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 Modal’s dismiss effect in StrictMode #64075

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/components/src/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ function UnforwardedModal(
// onRequestClose for any prior and/or nested modals as applicable.
useEffect( () => {
dismissers.push( refOnRequestClose );
const [ first, second ] = dismissers;
if ( second ) {
first?.current?.();
const [ prior ] = dismissers;
if ( prior && prior !== refOnRequestClose ) {
prior.current?.();
}

const nested = nestedDismissers.current;
Expand Down
6 changes: 2 additions & 4 deletions packages/editor/src/components/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ function useEditorCommandLoader() {
name: 'core/open-shortcut-help',
label: __( 'Keyboard shortcuts' ),
icon: keyboard,
callback: ( { close } ) => {
close();
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to keep the Command Palette modal open alongside the shortcuts and preferences modal? Most of the commands I checked call the close callback.

Copy link
Contributor Author

@stokesman stokesman Jul 30, 2024

Choose a reason for hiding this comment

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

(Non-nested) Modal’s already can’t be open alongside each other. It doesn’t hurt anything to keep calling the close callback but I figured why not remove it now that the malfunction it works around is fixed.

Copy link
Member

Choose a reason for hiding this comment

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

Calling close() here is actually a good idea, because the command palette modal closes itself explicitly.

Otherwise it's auto-closed by the newly opened modal: they are at the same context level, they are not nested, so only one can be open.

callback: () => {
openModal( 'editor/keyboard-shortcut-help' );
},
} );
Expand All @@ -109,8 +108,7 @@ function useEditorCommandLoader() {
commands.push( {
name: 'core/open-preferences',
label: __( 'Editor preferences' ),
callback: ( { close } ) => {
close();
callback: () => {
openModal( 'editor/preferences' );
},
} );
Expand Down
Loading