Site Editor: Have useNavigateToPreviousEntityRecord rely on location state#69103
Site Editor: Have useNavigateToPreviousEntityRecord rely on location state#69103stokesman wants to merge 2 commits into
useNavigateToPreviousEntityRecord rely on location state#69103Conversation
|
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.
- Moved 'react' import up from below
- Added
Locationtype import—Locationwas 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
useNavigateToPreviousEntityRecordhook relies on theusePrevioushook 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 theusePrevioushook:How?
useNavigateToEntityRecordto store the state that was kept byusePreviousin the the router’slocation.statelocation.statethrough theuseLocationhooknavigateToPreviousEntityRecordto use the new state from the routerTesting Instructions