-
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
Navigation: Improve trigger for fallback navigation #66478
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: -21 B (0%) Total Size: 1.81 MB
ℹ️ View Unchanged
|
Flaky tests detected in b19aae9. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11519476541
|
// If there is no navigation menu found | ||
// then trigger fallback algorithm to create one. | ||
if ( | ||
! firstNavigationMenu && | ||
! isResolvingNavigationMenus && | ||
hasResolvedNavigationMenus && | ||
! hasCreatedFallback | ||
// Ensure a fallback navigation is created only once | ||
! isCreatingNavigationFallback | ||
) { | ||
getNavigationFallbackId(); |
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.
Calling a selector during the render seems odd. I know that useSelect isn't the best place to "fire and forget" pattern, but I can't think of a better alternative.
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 admit that's weird, however, with the mechanics of selectors and resolvers, it does make sense to some degree. It's also documented why we're doing it, so it felt OK to leave as-is. This PR attempts to only fix the React Compiler error after all.
Juts for history: the flag removed in this PR was added in #51413 not in #50321 in this commit. |
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've tested this and it seems to be OK. I remember back in the day these navigation block integrations were added sometimes checking for isResolving
was insufficient 🤷🏻
All in all 🚀 let's bring this in. 🤞🏻
Co-authored-by: tyxla <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: draganescu <[email protected]>
What?
Come up with an alternative solution for solving the problem #50321 intends to solve.
Why?
#50321 uses an external flag for the component, which is against React's rules, and the React Compiler doesn't appreciate it (see #61788).
How?
The goal of #50321 was to create fallback navigation only if there were no navigations at all, and create it only once for the session.
This PR achieves it by checking if the request to create a fallback navigation is currently resolving. This simplifies the logic by avoiding an extra flag, and satisfies the React Compiler.
Testing Instructions
Same as in #50321.
Testing Instructions for Keyboard
Same
Screenshots or screencast
None