Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly detect changes to background state #8435

Merged
merged 1 commit into from
Apr 28, 2020

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Apr 28, 2020

Changes to the background state were being detected in the update event handler in ui/index.js that receives state updates from the background. However this doesn't catch every update; some state changes are received by the UI in-between these update events.

The background getState function is callable directly from the UI, and many action creators call it via forceUpdateMetamaskState to update the metamask state immediately without waiting for the next update event. These state updates skip this change detection in ui/index.js.

For example, if a 3Box state restoration resulted in a currentLocale change, and then a forceUpdateMetamaskState call completed before the next update event was received, then updateCurrentLocale wouldn't be called, and the locale store would not be updated correctly with the localized messages for the new locale.

We now check for background state changes in the updateMetamaskState action creator. All metamask state updates go through this function, so we aren't missing any changes anymore.

@Gudahtt Gudahtt marked this pull request as ready for review April 28, 2020 03:47
@Gudahtt Gudahtt requested a review from a team as a code owner April 28, 2020 03:47
@metamaskbot
Copy link
Collaborator

Builds ready [dab86df]

rekmarks
rekmarks previously approved these changes Apr 28, 2020
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

whymarrh
whymarrh previously approved these changes Apr 28, 2020
Copy link
Contributor

@whymarrh whymarrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Changes to the background state were being detected in the `update`
event handler in `ui/index.js` that receives state updates from the
background. However this doesn't catch every update; some state
changes are received by the UI in-between these `update` events.

The background `getState` function is callable directly from the UI,
and many action creators call it via `forceUpdateMetamaskState` to
update the `metamask` state immediately without waiting for the next
`update` event. These state updates skip this change detection in
`ui/index.js`.

For example, if a 3Box state restoration resulted in a `currentLocale`
change, and then a `forceUpdateMetamaskState` call completed before the
next `update `event was received, then `updateCurrentLocale` wouldn't
be called, and the `locale` store would not be updated correctly with
the localized messages for the new locale.

We now check for background state changes in the `updateMetamaskState`
action creator. All `metamask` state updates go through this function,
so we aren't missing any changes anymore.
@Gudahtt Gudahtt dismissed stale reviews from whymarrh and rekmarks via 35bec8d April 28, 2020 12:53
@Gudahtt Gudahtt force-pushed the fix-background-state-change-detection branch from dab86df to 35bec8d Compare April 28, 2020 12:53
@metamaskbot
Copy link
Collaborator

Builds ready [35bec8d]
Page Load Metrics (599 ± 14 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint298236115
domContentLoaded5646795972914
load5656815992914
domInteractive5636795972914

Copy link
Contributor

@whymarrh whymarrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Gudahtt Gudahtt merged commit 46d72d1 into develop Apr 28, 2020
@Gudahtt Gudahtt deleted the fix-background-state-change-detection branch April 28, 2020 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants