-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Router: Fix addition and removal of empty classnames #67378
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. |
packages/router/src/router.tsx
Outdated
@@ -129,13 +129,17 @@ export function useHistory() { | |||
|
|||
await new Promise< void >( ( resolve ) => { | |||
const classname = options.transition ?? ''; | |||
document.documentElement.classList.add( classname ); | |||
if ( classname ) { |
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.
There's something I'm missing here. When can this happen?
There's a ! options.transition
check above that is meant to prevent using a transition entirely no?
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.
There's a
! options.transition
check above
But that check doesn't prevent the transition from running! It's:
if ( ! options.transition ) {
performPush();
}
await new Promise( ... );
There is missing return
after performPush()
. That's probably the actual bug!
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.
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 swear in my mind, there was an early return haha :)
Flaky tests detected in bb9b71f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12066792436
|
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.
Yes, this is a perfect fix
@@ -125,6 +125,7 @@ export function useHistory() { | |||
! options.transition | |||
) { | |||
performPush(); | |||
return; | |||
} | |||
|
|||
await new Promise< void >( ( resolve ) => { |
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 think we can probably remove the ?? ''
fallback here
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 think you added it mostly to satisfy types there. Without it, TS will not be happy because classname
could be undefined
and classList.add()
can't work with undefined
. Happy to keep it.
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 thought the early return will tell typescript that the classname is not empty there anymore.
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.
It would have been the case if the calls were synchronous, but this is called in an async 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.
Currently TypeScript cannot narrow down the type from string | undefined
to undefined
because the options.transition
usage is inside a nested function (the promise constructor). In such a case it's harder to guarantee in what order code is executed.
But you could solve this by extracting most of the code out of the new Promise
callback. The only part that needs to be async is the final transition.finished.finally
call. Everything before it is sync.
* Router: Fix addition and removal of empty classnames * Actually prevent transition Co-authored-by: tyxla <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: jsnajdr <[email protected]>
* Router: Fix addition and removal of empty classnames * Actually prevent transition Co-authored-by: tyxla <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: jsnajdr <[email protected]>
What?
Fixes an error that occurs when navigating between different blocks in global styles in the site editor.
Why?
Just fixing an error, seems like it was introduced in #67199.
Found while late testing #67199.
How?
We're making sure that before adding or removing a classname during router navigation, there's actually one to be added or removed.
Testing Instructions
/wp-admin/site-editor.php?p=%2Fstyles§ion=%2Fblocks
Testing Instructions for Keyboard
Same
Screenshots or screencast