-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
LocalAutosaveNotice: use stable notice id to prevent double notices #47776
Conversation
Size Change: -10 B (0%) Total Size: 1.31 MB
ℹ️ View Unchanged
|
Flaky tests detected in c2086ea. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4103472326
|
window.sessionStorage.removeItem( '__wpEditorTestSessionStorage' ); | ||
hasStorageSupport = true; | ||
} catch { | ||
hasStorageSupport = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we return the value in this try/catch
block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say we should return it after the try / catch
block. Seems like in this branch we no longer return it at all in this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a fix 👍 The return
statement must have got lost during a git add -p
when I wanted to commit the changes as two commits.
1a399ce
to
c2086ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works great for me and the code looks good 👍
if ( hasStorageSupport !== undefined ) { | ||
return hasStorageSupport; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of a rational reason to need to run it multiple times 👍
…47776) * LocalAutosaveNotice: use stable notice id to prevent double notices * Some code cleanups (bailout, catch, useSelect)
Cherry-picked this PR to the wp/6.2 branch. |
Fixes issue in React strict mode where local autosave notice appears twice, reported by @ntsekouras here: #47703 (comment)
The notice is created in
useEffect
, and on mount, React strict mode runs effects twice.I fixed this by giving a stable ID to the notice, instead of making it unique on each call. If the notice is created for the second time, the previous one gets removed. The unique ID was never really needed -- this is the kind of notice that should appear only once.