mobxjs / mobxjs/mobx-react-devtools

Restore settings from localStorage on componentWillMount

Open
#48 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
1.2k
Forks
45
PR merge metrics
No merged PRs in 30d

Description

I'm running into a problem where the mobx DevTools miss some actions that run synchronously with the page load (its an authentication check that gets run by a react-router onEnter callback).

I dug a little deeper and found that it's caused by running the restoreLogFromLocalstorage in componentDidMount in LogControl here:

https://github.com/mobxjs/mobx-react-devtools/blob/092fb0e782f2b02ae13a47fd7f909127affc70d7/src/Controls/LogControl.jsx#L6

Would it break things to run it in componentWillMount, which (I think) would cause it to run before those actions? Don't know if that messes up other things.

For now, I've worked around it by running this in my own Root component's componentWillMount:

const logEnabled = window.localStorage.getItem('mobx-react-devtool__logEnabled') === 'YES';
configureDevtool({ logEnabled });

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/Controls/LogControl.jsx at restoreLogFromLocalstorage and compare componentDidMount with componentWillMount. Reproduce the reported synchronous react-router onEnter authentication case and verify that restored settings are available before those actions without breaking the existing LogControl behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
devtools, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.