-
Notifications
You must be signed in to change notification settings - Fork 4.6k
iAPI: Fix using getServerContext in derived state getters
#73518
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
iAPI: Fix using getServerContext in derived state getters
#73518
Conversation
|
Size Change: +19 B (0%) Total Size: 2.54 MB
ℹ️ View Unchanged
|
|
@t-hamano I'm also working on this fix for 6.9 RC3, related to I have it working, although I still want to give the solution another thought in case there is a better way to fix it. I'll have it ready before tomorrow. |
|
Flaky tests detected in bfd0742. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19639118509
|
|
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. |
DAreRodz
left a comment
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 it, and the fix works as expected. I've also ensured the test passes only with the fix in place.
Codewise, using useLayoutEffect makes sense to me: the signal invalidation occurs right after the render finishes and before any visual changes are made. It is true that it could cause re-renders and multiple getters re-evaluation, but at least this shouldn't visually affect the layout.
Thanks for the fix, @luisherranz! ❤️
…within a microtask
…updates within a microtask" This reverts commit c2bf701.
|
Thanks David!
I have been testing it, and I think Preact batches that phase internally because, even though the signal is invalidated multiple times, the computations only run once. However, there is indeed a difference between the invalidation done for the state during Merging now 👍 |
|
There was a conflict while trying to cherry-pick the commit to the wp/6.9 branch. Please resolve the conflict manually and create a PR to the wp/6.9 branch. PRs to wp/6.9 are similar to PRs to trunk, but you should base your PR on the wp/6.9 branch instead of trunk. |
* Add failing test for context * Fix test * Add changelog * Don't trigger invalidations twice in the navigation phase * Debounce navigation signal invalidation to prevent redundant updates within a microtask * Revert "Debounce navigation signal invalidation to prevent redundant updates within a microtask" This reverts commit c2bf701. * Use a different navigation signal for context Co-authored-by: luisherranz <luisherranz@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
…73531) * Add failing test for context * Fix test * Add changelog * Don't trigger invalidations twice in the navigation phase * Debounce navigation signal invalidation to prevent redundant updates within a microtask * Revert "Debounce navigation signal invalidation to prevent redundant updates within a microtask" This reverts commit c2bf701. * Use a different navigation signal for context Co-authored-by: luisherranz <luisherranz@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
|
This PR was manually backported into the |
What?
Fixes an issue where derived state using
getServerContextwas not updating correctly during client-side navigation in the Interactivity API.Why?
When navigating between pages using the Interactivity API router, the server context changes. However, derived state properties that relied on
getServerContext()were not being re-evaluated or invalidated correctly in some scenarios, causing them to return stale data from the previous page.How?
We added a
useLayoutEffectin the router region directive to trigger anavigationSignalupdate when the VDOM changes. This ensures that any reactive dependencies, including those relying ongetServerContext, are properly notified and updated when the router region content is replaced during navigation.Testing Instructions
npm run test:e2e packages/e2e-tests/specs/interactivity/get-sever-context.spec.ts