iAPI Docs: Add client-side navigation compatibility guide#76242
iAPI Docs: Add client-side navigation compatibility guide#76242luisherranz merged 25 commits intotrunkfrom
Conversation
|
Flaky tests detected in e390127. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23620565336
|
|
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. |
|
|
||
| Accessing WordPress packages through global variables like `window.wp.element` or `window.wp.data` is not compatible with CSN. These globals are set by regular scripts, which are not re-executed during client-side navigation. | ||
|
|
||
| **Instead:** Use ES module imports from the corresponding `@wordpress/*` script module, if one is available. For example, `@wordpress/a11y` is available both as a regular script (`window.wp.a11y`) and as a script module: |
There was a problem hiding this comment.
Is there a definitive list of which packages are compatble?
luisherranz
left a comment
There was a problem hiding this comment.
I added a bunch of corrections and refinements in a6bbb97. Can you review them to make sure they are all correct?
I added cross-references to the CSN Compatibility guide across the documentation for better discoverability:
- Client-Side Navigation guide: Added a callout near the top of the page, and a link in the "Ensuring script modules load during navigation" section where
clientNavigationinblock.jsonis explained. - Router package README: Extended the existing callout to also mention the compatibility guide.
- Block Supports reference: Simplified the
clientNavigationsub-property description to defer to the compatibility guide instead of inlining partial guidelines. - Interactivity API FAQ: Linked the "client-side navigation" mention to the CSN guide.
toc.jsonandmanifest.json: Added entries for both the Client-Side Navigation guide and the Client-Side Navigation Compatibility guide, which were missing from the handbook's table of contents and manifest.
And other things that I think should be clarified below.
docs/reference-guides/interactivity-api/core-concepts/client-side-navigation-compatibility.md
Outdated
Show resolved
Hide resolved
docs/reference-guides/interactivity-api/core-concepts/client-side-navigation-compatibility.md
Outdated
Show resolved
Hide resolved
docs/reference-guides/interactivity-api/core-concepts/client-side-navigation-compatibility.md
Outdated
Show resolved
Hide resolved
docs/reference-guides/interactivity-api/core-concepts/client-side-navigation-compatibility.md
Outdated
Show resolved
Hide resolved
…avigation documentation
12930f7 to
242afb9
Compare
luisherranz
left a comment
There was a problem hiding this comment.
Thanks for the changes, David 🙂
LGTM now! Approving 👍
What?
Adds a new documentation page: Client-Side Navigation Compatibility Guide for the Interactivity API.
Why?
Block developers and theme authors need clear guidance on what makes their code compatible with client-side navigation. Without this, developers may unknowingly introduce patterns that break client-side navigation — causing fallbacks to full page reloads or potentially breaking the site, degrading the user experience.
There was no centralized reference for CSN compatibility, nor a checklist that developers could use to verify compatibility before declaring their blocks compatible.
How?
Adds a new document at
docs/reference-guides/interactivity-api/core-concepts/client-side-navigation-compatibility.mdand links it from the Core Concepts README. The guide covers:block.jsonviasupports.interactivity.clientNavigation.wp_unique_id_from_values()as the recommended alternative towp_unique_id()), and selector consistency across navigations.wp_register_script_module()withloadOnClientNavigation.data-wp-keyfor dynamic lists, avoiding DOM mutations outside the Interactivity API (withdata-wp-watchas the escape hatch), and usingattachTofor HTML outside router regions.The guide is written to be useful for both block developers and classic PHP theme/plugin authors.