Skip to content

iAPI Docs: Add client-side navigation compatibility guide#76242

Merged
luisherranz merged 25 commits intotrunkfrom
docs/iapi-csn-compatibility-guide
Mar 27, 2026
Merged

iAPI Docs: Add client-side navigation compatibility guide#76242
luisherranz merged 25 commits intotrunkfrom
docs/iapi-csn-compatibility-guide

Conversation

@DAreRodz
Copy link
Copy Markdown
Contributor

@DAreRodz DAreRodz commented Mar 6, 2026

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.md and links it from the Core Concepts README. The guide covers:

  • Declaring compatibility in block.json via supports.interactivity.clientNavigation.
  • What makes a block compatible — non-interactive blocks, Interactivity API blocks, and blocks using other libraries.
  • CSS requirements — no dynamic CSS injection, no runtime stylesheet modifications, stable CSS selectors (with wp_unique_id_from_values() as the recommended alternative to wp_unique_id()), and selector consistency across navigations.
  • JavaScript requirements — use of script modules instead of regular scripts, and how to handle script modules outside blocks (e.g., classic PHP themes) via wp_register_script_module() with loadOnClientNavigation.
  • HTML requirements — consistent HTML structures, proper use of data-wp-key for dynamic lists, avoiding DOM mutations outside the Interactivity API (with data-wp-watch as the escape hatch), and using attachTo for HTML outside router regions.
  • Compatibility checklist — a pre-flight checklist for developers to verify before marking a block as CSN-compatible.
  • Quick reference table summarizing block types and their compatibility status.

The guide is written to be useful for both block developers and classic PHP theme/plugin authors.

@DAreRodz DAreRodz added [Type] Developer Documentation Documentation for developers [Feature] Interactivity API API to add frontend interactivity to blocks. labels Mar 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 9, 2026

Flaky tests detected in e390127.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23620565336
📝 Reported issues:

@DAreRodz DAreRodz marked this pull request as ready for review March 10, 2026 16:44
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 10, 2026

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
Co-authored-by: ryanwelcher <welcher@git.wordpress.org>

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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a definitive list of which packages are compatble?

@github-actions github-actions bot added the [Package] Interactivity Router /packages/interactivity-router label Mar 25, 2026
Copy link
Copy Markdown
Member

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clientNavigation in block.json is explained.
  • Router package README: Extended the existing callout to also mention the compatibility guide.
  • Block Supports reference: Simplified the clientNavigation sub-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.json and manifest.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.

@DAreRodz DAreRodz force-pushed the docs/iapi-csn-compatibility-guide branch from 12930f7 to 242afb9 Compare March 26, 2026 20:56
@DAreRodz DAreRodz requested a review from luisherranz March 26, 2026 22:35
Copy link
Copy Markdown
Member

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, David 🙂

LGTM now! Approving 👍

@luisherranz luisherranz merged commit 884c9e0 into trunk Mar 27, 2026
56 of 61 checks passed
@luisherranz luisherranz deleted the docs/iapi-csn-compatibility-guide branch March 27, 2026 06:22
@github-actions github-actions bot added this to the Gutenberg 22.9 milestone Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Interactivity API API to add frontend interactivity to blocks. [Package] Interactivity Router /packages/interactivity-router [Type] Developer Documentation Documentation for developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants