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

Fix pre-initialization UI error state capture #20529

Merged
merged 1 commit into from
Aug 18, 2023

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Aug 18, 2023

Explanation

In the case where an error is thrown in the UI before initialization has finished, we aren't capturing the application state correctly for Sentry errors. We had a test case for this, but the test case was broken due to a mistake in how the network-store was setup (it was not matching the behavior of the real local-tstore module).

The pre-initialization state capture logic was updated to rely solely upon the localStore instance used by Sentry to determine whether the user had opted-in to metrics or not. This simplifies the logic a great deal, removing the need for the getMostRecentPersistedState state hook. It also ensures that state is captured corretly pre- initialization in both the background and UI.

Manual Testing Steps

Update ui/index.js to throw an error during initialization (but after the getMostRecentPersistedState hook was setup, if testing on develop). On develop, you'll see that the resulting error doesn't include Sentry state, even though it was meant to. On this PR it will include the state in the error report.

Alternatively you could do what the e2e test does and wait until after initialization, but "emulate" a pre-initialization state by deleting the getSentryAppState state hook. Then you can more easily trigger an error by calling window.stateHooks.throwTestError(). Again, you should see the same result (on develop the state will be missing, but on this PR it will be present).

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@@ -31,7 +31,6 @@ export default class ReadOnlyNetworkStore {
const response = await fetchWithTimeout(FIXTURE_SERVER_URL);
if (response.ok) {
this._state = await response.json();
this.mostRecentRetrievedState = this._state;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is why the test had passed earlier when it should have failed: this property was set too early, before the first read. In production it's only set upon read.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

@Gudahtt Gudahtt force-pushed the fix-ui-pre-initialization-errors branch from 90e2751 to 37c93da Compare August 18, 2023 16:48
@@ -100,6 +94,9 @@ const openMetamaskTabsIDs = {};
const requestAccountTabIds = {};
let controller;

// state persistence
Copy link
Member Author

Choose a reason for hiding this comment

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

Effectively I'm reverting some of the changes made in #20491. I wouldn't normally write a comment like this, but I'm trying to reduce the diff for the v10.34.5 release (this was pre-existing before #20491)

In the case where an error is thrown in the UI before initialization
has finished, we aren't capturing the application state correctly for
Sentry errors. We had a test case for this, but the test case was
broken due to a mistake in how the `network-store` was setup (it was
not matching the behavior of the real `local-tstore` module).

The pre-initialization state capture logic was updated to rely solely
upon the `localStore` instance used by Sentry to determine whether the
user had opted-in to metrics or not. This simplifies the logic a great
deal, removing the need for the `getMostRecentPersistedState` state
hook. It also ensures that state is captured corretly pre-
initialization in both the background and UI.
@Gudahtt Gudahtt force-pushed the fix-ui-pre-initialization-errors branch from 37c93da to 185ab6d Compare August 18, 2023 16:50
@Gudahtt Gudahtt added release-blocker This bug is blocking the next release team-extension-platform labels Aug 18, 2023
@Gudahtt Gudahtt marked this pull request as ready for review August 18, 2023 16:54
@Gudahtt Gudahtt requested a review from a team as a code owner August 18, 2023 16:54
Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

Code looks good. I will do a manual test

@codecov
Copy link

codecov bot commented Aug 18, 2023

Codecov Report

Merging #20529 (185ab6d) into develop (8df77ed) will increase coverage by 0.00%.
Report is 2 commits behind head on develop.
The diff coverage is 0.00%.

@@           Coverage Diff            @@
##           develop   #20529   +/-   ##
========================================
  Coverage    68.66%   68.66%           
========================================
  Files          991      991           
  Lines        38467    38465    -2     
  Branches     10333    10333           
========================================
  Hits         26411    26411           
+ Misses       12056    12054    -2     
Files Changed Coverage Δ
app/scripts/lib/network-store.js 0.00% <0.00%> (ø)
app/scripts/lib/setup-initial-state-hooks.js 0.00% <0.00%> (ø)

@metamaskbot
Copy link
Collaborator

Builds ready [185ab6d]
Page Load Metrics (2122 ± 124 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1464432037335
domContentLoaded169126132119256123
load169226342122258124
domInteractive169126132119256123
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -73 Bytes (-0.00%)
  • ui: -308 Bytes (-0.00%)
  • common: -89 Bytes (-0.00%)

Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

Manual QA was good

@Gudahtt Gudahtt merged commit 9cfa9ba into develop Aug 18, 2023
@Gudahtt Gudahtt deleted the fix-ui-pre-initialization-errors branch August 18, 2023 19:02
@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2023
@metamaskbot metamaskbot added the release-10.36.0 Issue or pull request that will be included in release 10.36.0 label Aug 18, 2023
@Gudahtt Gudahtt added release-10.34.5 Issue or pull request that will be included in release 10.34.5 and removed release-10.36.0 Issue or pull request that will be included in release 10.36.0 labels Sep 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-10.34.5 Issue or pull request that will be included in release 10.34.5 release-blocker This bug is blocking the next release team-extension-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants