-
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
Site Editor: Have useNavigateToPreviousEntityRecord
rely on location state
#69103
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: +48 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
Flaky tests detected in f98383c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13299207343
|
import type { ReactNode } from 'react'; | ||
import type { Location } from 'history'; |
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.
- Moved 'react' import up from below
- Added
Location
type import—Location
was referenced before but since it wasn’t imported it was resolving to Typescript’s lib-dom which is different.
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. |
b4f408c
to
564608d
Compare
564608d
to
f98383c
Compare
Thanks for the PR! I believe there have been multiple PRs submitted regarding the context provider and router in the site editor:
And I found this comment in #68907:
Considering that, would it be best to close #68907 and move forward with #69103 and #69172? @youknowriad @jsnajdr Also, I'd love to hear any feedback if you have on moving state into the router and removing the context providers from the site editor sidebar. |
Can we move this PR forward? If all related PRs are resolved, including this one, I think the redundant nesting of elements will be resolved, especially in mobile layouts. I think that will make it easier to resolve #69156. |
What?
Makes the code concerned with whether to show a back button more robust.
Originally made to fix #69016.
Why?
Code quality. Currently the
useNavigateToPreviousEntityRecord
hook relies on theusePrevious
hook to keep some state locally. This, as seen in #69016, can fail if the consuming component remounts. While remounts are best avoided and unlikely to return in this case, the changes here make it impervious to remounts. Besides that, there are more reasons to avoid using theusePrevious
hook:How?
useNavigateToEntityRecord
to store the state that was kept byusePrevious
in the the router’slocation.state
location.state
through theuseLocation
hooknavigateToPreviousEntityRecord
to use the new state from the routerTesting Instructions