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
|
There was a problem hiding this comment.
Shouldn't we return the value in this try/catch block?
There was a problem hiding this comment.
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.
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
tyxla
left a comment
There was a problem hiding this comment.
This works great for me and the code looks good 👍
| if ( hasStorageSupport !== undefined ) { | ||
| return hasStorageSupport; |
There was a problem hiding this comment.
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.