-
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
Fix 'Preferences' and 'Shortcuts' commands in StrictMode #64019
Fix 'Preferences' and 'Shortcuts' commands in StrictMode #64019
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: 0 B Total Size: 1.76 MB ℹ️ View Unchanged
|
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.
LGTM! This change makes sense to me.
If I comment on the logic for "dismissers," the modal opens correctly.
I found an article that said React 18 intentionally remounts components when Strict Mode is on.
Maybe this is related.
Adding
<StrictMode>
to a React application adds special behavior (only in DEV mode) to all of components it wraps around. For example, when running in “strict mode“ React will intentionally double-render components for in order to flush out unsafe side effects.
From: Adding Reusable State to StrictMode · reactwg/react-18 · Discussion #19
Yes, it does, to help developers discover potential bugs. The documentation page explains the reasoning behind it pretty well - https://react.dev/reference/react/StrictMode. |
I’d wanted to try debugging the effect that George highlighted but I've not been able to reproduce the issue. It seems like React is running in production mode for me and I can’t figure out why. Logging |
@stokesman, check if these constants are set to true WP_DEBUG and SCRIPT_DEBUG. Basically, React needs to load in development mode for StrictMode to be active. |
Thank you George. That makes sense and now I finally read the instructions where you already mentioned it 🤦. I made a #64075 with what should be a proper fix. |
What?
Closes #64004.
PR fixes a bug where the "Editor Preferences" or "Keyboard shortcuts" modal will close immediately when opening from the command palette. There's no modal flash, so it looks like the commands never run.
Note: While this fix is correct, it still fixes a symptom, not the actual cause. I've included more details below.
Why?
I noticed that
onRequestClose
callbacks are called for both models as soon as they open. This led me to "dismissers" logic in the Modal component, introduced in #51602. If I comment on the logic for "dismissers," the modal opens correctly. It seems that this side effect isn't resilient for the StrictMode.gutenberg/packages/components/src/modal/index.tsx
Lines 152 to 166 in 159d01a
How?
Explicitly close the command palette dialog before opening other models. This matches other
callback
calls in the file.Testing Instructions
WP_DEBUG = true
andSCRIPT_DEBUG = true
.Testing Instructions for Keyboard
Same