-
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
Interactivity API: Fix navigate()
issues related to initial state merges
#57134
Conversation
Size Change: +2.75 kB (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Flaky tests detected in 80f28ad. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8012361745
|
We need to avoid overriding the getters, because the state in the server is just their initial state: wp_initial_state( "myPlugin", array(
"counter": 1,
"double": 2
)); const { state } = store("myPlugin", {
state: {
get double() {
return state.counter * 2;
},
},
}); |
7ca0847
to
ffa8db8
Compare
navigate()
callsnavigate()
calls
navigate()
callsnavigate()
issues related to initial state merges
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. |
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 didn't look at the tests, but the code looks good to me 🙂
I just manually cherry-picked this PR to the cherry-pick-wp-6-5-beta-3 branch to get it included in the next release. |
…erges (#57134) * Use deepMerge and stores to update state * Add test case * Do not render state when `data` is not present * Move batch call inside braces * Move initial data related code together * Fix initial data tag ID * Prevent passing the state proxy as receiver * Add comment * Move links to a nav element to prevent hydration issues * Add failing test for getters merge * Simplify assignments * Add a try-catch to ignore getter assignments * Fix disabled navigation test * Test navigations to pages with csn disabled * Update changelogs Co-authored-by: DAreRodz <[email protected]> Co-authored-by: luisherranz <[email protected]> # Conflicts: # packages/interactivity-router/CHANGELOG.md # packages/interactivity/CHANGELOG.md
…erges (#57134) * Use deepMerge and stores to update state * Add test case * Do not render state when `data` is not present * Move batch call inside braces * Move initial data related code together * Fix initial data tag ID * Prevent passing the state proxy as receiver * Add comment * Move links to a nav element to prevent hydration issues * Add failing test for getters merge * Simplify assignments * Add a try-catch to ignore getter assignments * Fix disabled navigation test * Test navigations to pages with csn disabled * Update changelogs Co-authored-by: DAreRodz <[email protected]> Co-authored-by: luisherranz <[email protected]> # Conflicts: # packages/interactivity-router/CHANGELOG.md # packages/interactivity/CHANGELOG.md
What?
Epic: #56803
Related discussion: #53056
Fixes the initial state not being merged with the current state during
navigate()
calls and the page not being reloaded whenclientNavigationDisabled
is true for the target page.Also, fixes a hidden bug related to state proxies being passed as the
receiver
to deepSignal proxy handlers.How?
The
@wordpress/interactivity
module now exposes three more private functions:parseInitialData
: deserializes and returns the content of the initial data tag.populateInitialData
: merges the passed data onto the current state/config. Property values are overwritten, except for getters.batch
: the Preact signals'batch
function.Those functions are used by the
@wordpress/interactivity-router
module to preserve a cached copy of the initial state and update the global state during navigation. That update occurs inside abatch
call to prevent directives from updating before the new page rendering has finished.