-
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: Add getServerState()
and getServerContext()
#65151
Conversation
Size Change: +724 B (+0.04%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
ce56700
to
2392742
Compare
9cc32c7
to
60198c8
Compare
60198c8
to
98e959b
Compare
88a8e6b
to
580aba6
Compare
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.
Looks good to me, David!
…65151) * Expose client and server context from provider * Create `getServerContext` * Add simple test for server context * Implement `getServerState` * Add tests for read-only state proxies * Add e2e tests for `getServerState()` * Avoid PHPCS UndefinedVariable error * Add e2e tests for `getServerContext` WIP * Finish e2e tests for `getServerContext()` * Update `getServerState()` tests * Revert "Add simple test for server context" This reverts commit 7e6f530. * Update TSDocs Co-authored-by: DAreRodz <[email protected]> Co-authored-by: luisherranz <[email protected]> Co-authored-by: sethrubenstein <[email protected]> Co-authored-by: michalczaplinski <[email protected]>
I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: fa1a0d6 |
Great job finishing this task. @DAreRodz, it's going to be included in WordPress 6.7 and will need an accompanying dev note (added label) and documentation in the Interactivity API reference. |
…65151) * Expose client and server context from provider * Create `getServerContext` * Add simple test for server context * Implement `getServerState` * Add tests for read-only state proxies * Add e2e tests for `getServerState()` * Avoid PHPCS UndefinedVariable error * Add e2e tests for `getServerContext` WIP * Finish e2e tests for `getServerContext()` * Update `getServerState()` tests * Revert "Add simple test for server context" This reverts commit 7e6f530. * Update TSDocs Co-authored-by: DAreRodz <[email protected]> Co-authored-by: luisherranz <[email protected]> Co-authored-by: sethrubenstein <[email protected]> Co-authored-by: michalczaplinski <[email protected]>
I just cherry-picked this PR to the release/19.3 branch to get it included in the next release: 4c9fdd1 |
What?
Fixes: #65243
Exposes
getServerState()
andgetServerContext()
from the@wordpress/interactivity
package.These functions return an object that is analogous to the state/context returned by
store()
/getContext()
, with a couple of differences:navigate()
calls, using the values defined in the HTML.Example:
Why?
These functions are required for subscribing to changes in state/context when the HTML is updated using
navigate()
.How?
Both the state and the context use
proxifyState()
internally, a function that wraps objects with proxies and handles all the reactivity and property subscriptions. This function has been extended to accept a{ readOnly }
option that, whentrue
, prevents any modification to the given object and nested ones.The objects returned by
getServerState()
andgetServerContext()
usereadOnly: true
, and it's the functiondeepMerge()
, refactored in #64879, the one that updates the server state and the server context.The function
populateServerData()
has been changed to update the server state. As that function is already used innavigate()
, no changes in@wordpress/interactivity-router
were required.Lastly, the implementation of the
data-wp-context
directive has been adapted to handle the server context updates and inheritance.Testing Instructions
I've added unit tests and e2e tests.