Repository navigation
Interactivity API: Show the new page's server content in kept data-wp-html elements - #86416
luisherranz merged 24 commits into
Conversation
…-html elements whose value is the server representation
…already show the new page's server content
…-html elements whose value is pending
…new page's server content
…dered content across navigation in the browser
…tml element tests
…ate that brings it
…ons keep their content after navigation
…ement until the navigation's data-wp-watch callbacks have run
…hose value a data-wp-watch callback syncs after navigation
…the page's HTML into its context element
…server content it shows is unchanged
…ct's dependencies, which the vnode already covers
…unchanged server content keeps its nodes after navigation
…alike that copying content calls no Trusted Types policy
…er its value resolves
…edits by the link of the page shown
…ation a browser must prove
…'s dependencies, which the hooks lint rule requires
…pt-nodes statement in the data-wp-html reference
… script changed before hydration is replaced on navigation
…s from the server representation into a token or null
…content that the same update replaces
🤖 PR meta 🤖🎉 PropsIf 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +67 B (0%) Total Size: 8.62 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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. Page List converts to Navigation Links with entity bindings in
|
SantosGuillamot
left a comment
There was a problem hiding this comment.
Looks good to me 🙂 I tested it and it works as expected.
One edge case to consider for a follow-up: when an element switches from a client token on one page to the server marker on the next, its nodes are replaced even if the HTML is identical. It's an edge case, so it shouldn't block this fix.
…-html elements (#86416) * Interactivity API: Show the new page's server content in kept data-wp-html elements whose value is the server representation * Interactivity API: Keep the nodes of kept data-wp-html elements that already show the new page's server content * Interactivity API: Show the new page's server content in kept data-wp-html elements whose value is pending * Interactivity API: Document that kept data-wp-html elements show the new page's server content * Interactivity API: Test kept data-wp-html elements showing server-rendered content across navigation in the browser * Interactivity Router: Explain the value letters of the kept data-wp-html element tests * Interactivity API: Stop owing server content after the navigation update that brings it * Interactivity API: Say that data-wp-html elements outside router regions keep their content after navigation * Interactivity API: Keep server content owed to a kept data-wp-html element until the navigation's data-wp-watch callbacks have run * Interactivity API: Add an end-to-end test for data-wp-html elements whose value a data-wp-watch callback syncs after navigation * Interactivity API: Explain why the router server HTML fixture writes the page's HTML into its context element * Interactivity API: Keep a kept data-wp-html element's nodes when the server content it shows is unchanged * Interactivity API: Drop the server content from the data-wp-html effect's dependencies, which the vnode already covers * Interactivity API: Document that a kept data-wp-html element showing unchanged server content keeps its nodes after navigation * Interactivity API: State in the data-wp-html reference and changelog alike that copying content calls no Trusted Types policy * Interactivity API: Assert what the pending router-html case shows after its value resolves * Interactivity API: Find the post the router-html-server refresh test edits by the link of the page shown * Interactivity API: Limit the data-wp-watch sync e2e test to the navigation a browser must prove * Interactivity API: Keep the server content in the data-wp-html effect's dependencies, which the hooks lint rule requires * Interactivity API: Leave content with noscript elements out of the kept-nodes statement in the data-wp-html reference * Interactivity API: State in the data-wp-html reference that content a script changed before hydration is replaced on navigation * Interactivity API: Test a kept data-wp-html element whose getter turns from the server representation into a token or null * Interactivity API: Explain why a stale server context value can copy content that the same update replaces * Interactivity API: Link the changelog entry to its pull request
|
I just cherry-picked this PR to the wp/7.2 branch to get it included in the next release: 479c84d |
This updates the pinned commit hash of the Gutenberg repository from `c035c1a649ef68f5c1646694cf440df1d7ae6e62` to `1b0dc90c700746b108e080263a4dc67707b750a1` (fixes cherry-picked to the `wp/7.2` branch). A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@c035c1a...1b0dc90 - [WP 7.2] Components, UI: Use focus-visible for disabled item focus rings (WordPress/gutenberg#86269) - Notes: Keep the canvas still when a new note is added (WordPress/gutenberg#86283) (#86293) - Post summary: Show placeholders for an empty excerpt and a missing author (WordPress/gutenberg#85842) (#86294) - Core fields: Restore the previous Publish and Status panel date behaviour (WordPress/gutenberg#86065) (#86295) - Interactivity API: Show the data-wp-html fallback on created elements under Trusted Types (WordPress/gutenberg#84924) (#86306) - [WP 7.2] UI: Add LoadingIndicator to item popups (WordPress/gutenberg#86303) - Interactivity Router: Fix nested router regions without data-wp-interactive disappearing on navigation (WordPress/gutenberg#86061) (#86308) - Interactivity API: Run watch() cleanups and attachTo render callbacks without a directive scope (WordPress/gutenberg#86058) (#86311) - DataForm: Fix clipped focus ring of field values in panel layout (WordPress/gutenberg#86361) (#86369) - Tests: Avoid passing an object when invoking static methods via reflection. (WordPress/gutenberg#86329) - [WP 7.2] DropdownMenu: Invert the selected item indicator while highlighted (WordPress/gutenberg#86379) - Fields: Lowercase the (no excerpt), (no author) and (no description) placeholders (WordPress/gutenberg#86391) (#86424) - Core fields: Decode non-Latin slugs in the slug field (WordPress/gutenberg#86359) - Interactivity API: Show the new page's server content in kept data-wp-html elements (WordPress/gutenberg#86416) - DataForm: Tighten value density in the panel layout (WordPress/gutenberg#86389) (#86426) - Post summary: Show "Immediately" and relative publish dates in the Date row (WordPress/gutenberg#86367) - [WP 7.2] Block Styles: Show the active style variation in forced colors mode (WordPress/gutenberg#86450) - Site Editor: Fix the frame snapping to the mobile width when resized with the mouse (WordPress/gutenberg#86423) - Image: measure the lightbox container, not the image's parent (WordPress/gutenberg#82312) (#85491) - URL: Decode percent-encoded characters in getFilename (WordPress/gutenberg#86422) (#86477) - Fix: Hide the author avatar when the site does not show avatars and frame a blank one. (WordPress/gutenberg#86395) - Date picker: Mark the posts of the month a typed or reset date moves to (WordPress/gutenberg#86298) (#86463) - Fix iOS 27 tap into a heading leaving the caret in a quote (WordPress/gutenberg#85809) - Hand focus back to the field on a press in every browser (WordPress/gutenberg#86549) - Prevent jobs from running within forks on `push`. (WordPress/gutenberg#85968) - i18n: Add translator context to the "Copy error" button label (WordPress/gutenberg#85967) - Bubble editor canvas events to the outer iframe (WordPress/gutenberg#85263) - UI: Use LoadingIndicator in remaining popup consumers (WordPress/gutenberg#86501) - Block Editor: Keep the revision canvas read-only in preview mode (WordPress/gutenberg#84578) - Core Data: Rank an exact title match first among tied link suggestions (WordPress/gutenberg#86327) - Tests: Render the router-html-server context case through state (WordPress/gutenberg#86511) - iOS tests: De-flake the selection handle test (WordPress/gutenberg#85461) Props mamaduka, wildworks. See #66340. git-svn-id: https://develop.svn.wordpress.org/trunk@65379 602fd350-edb4-49c9-b593-d223f7449a82
This updates the pinned commit hash of the Gutenberg repository from `c035c1a649ef68f5c1646694cf440df1d7ae6e62` to `1b0dc90c700746b108e080263a4dc67707b750a1` (fixes cherry-picked to the `wp/7.2` branch). A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@c035c1a...1b0dc90 - [WP 7.2] Components, UI: Use focus-visible for disabled item focus rings (WordPress/gutenberg#86269) - Notes: Keep the canvas still when a new note is added (WordPress/gutenberg#86283) (#86293) - Post summary: Show placeholders for an empty excerpt and a missing author (WordPress/gutenberg#85842) (#86294) - Core fields: Restore the previous Publish and Status panel date behaviour (WordPress/gutenberg#86065) (#86295) - Interactivity API: Show the data-wp-html fallback on created elements under Trusted Types (WordPress/gutenberg#84924) (#86306) - [WP 7.2] UI: Add LoadingIndicator to item popups (WordPress/gutenberg#86303) - Interactivity Router: Fix nested router regions without data-wp-interactive disappearing on navigation (WordPress/gutenberg#86061) (#86308) - Interactivity API: Run watch() cleanups and attachTo render callbacks without a directive scope (WordPress/gutenberg#86058) (#86311) - DataForm: Fix clipped focus ring of field values in panel layout (WordPress/gutenberg#86361) (#86369) - Tests: Avoid passing an object when invoking static methods via reflection. (WordPress/gutenberg#86329) - [WP 7.2] DropdownMenu: Invert the selected item indicator while highlighted (WordPress/gutenberg#86379) - Fields: Lowercase the (no excerpt), (no author) and (no description) placeholders (WordPress/gutenberg#86391) (#86424) - Core fields: Decode non-Latin slugs in the slug field (WordPress/gutenberg#86359) - Interactivity API: Show the new page's server content in kept data-wp-html elements (WordPress/gutenberg#86416) - DataForm: Tighten value density in the panel layout (WordPress/gutenberg#86389) (#86426) - Post summary: Show "Immediately" and relative publish dates in the Date row (WordPress/gutenberg#86367) - [WP 7.2] Block Styles: Show the active style variation in forced colors mode (WordPress/gutenberg#86450) - Site Editor: Fix the frame snapping to the mobile width when resized with the mouse (WordPress/gutenberg#86423) - Image: measure the lightbox container, not the image's parent (WordPress/gutenberg#82312) (#85491) - URL: Decode percent-encoded characters in getFilename (WordPress/gutenberg#86422) (#86477) - Fix: Hide the author avatar when the site does not show avatars and frame a blank one. (WordPress/gutenberg#86395) - Date picker: Mark the posts of the month a typed or reset date moves to (WordPress/gutenberg#86298) (#86463) - Fix iOS 27 tap into a heading leaving the caret in a quote (WordPress/gutenberg#85809) - Hand focus back to the field on a press in every browser (WordPress/gutenberg#86549) - Prevent jobs from running within forks on `push`. (WordPress/gutenberg#85968) - i18n: Add translator context to the "Copy error" button label (WordPress/gutenberg#85967) - Bubble editor canvas events to the outer iframe (WordPress/gutenberg#85263) - UI: Use LoadingIndicator in remaining popup consumers (WordPress/gutenberg#86501) - Block Editor: Keep the revision canvas read-only in preview mode (WordPress/gutenberg#84578) - Core Data: Rank an exact title match first among tied link suggestions (WordPress/gutenberg#86327) - Tests: Render the router-html-server context case through state (WordPress/gutenberg#86511) - iOS tests: De-flake the selection handle test (WordPress/gutenberg#85461) Props mamaduka, wildworks. See #66340. Built from https://develop.svn.wordpress.org/trunk@65379 git-svn-id: http://core.svn.wordpress.org/trunk@64518 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This updates the pinned commit hash of the Gutenberg repository from `c035c1a649ef68f5c1646694cf440df1d7ae6e62` to `1b0dc90c700746b108e080263a4dc67707b750a1` (fixes cherry-picked to the `wp/7.2` branch). A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@c035c1a...1b0dc90 - [WP 7.2] Components, UI: Use focus-visible for disabled item focus rings (WordPress/gutenberg#86269) - Notes: Keep the canvas still when a new note is added (WordPress/gutenberg#86283) (#86293) - Post summary: Show placeholders for an empty excerpt and a missing author (WordPress/gutenberg#85842) (#86294) - Core fields: Restore the previous Publish and Status panel date behaviour (WordPress/gutenberg#86065) (#86295) - Interactivity API: Show the data-wp-html fallback on created elements under Trusted Types (WordPress/gutenberg#84924) (#86306) - [WP 7.2] UI: Add LoadingIndicator to item popups (WordPress/gutenberg#86303) - Interactivity Router: Fix nested router regions without data-wp-interactive disappearing on navigation (WordPress/gutenberg#86061) (#86308) - Interactivity API: Run watch() cleanups and attachTo render callbacks without a directive scope (WordPress/gutenberg#86058) (#86311) - DataForm: Fix clipped focus ring of field values in panel layout (WordPress/gutenberg#86361) (#86369) - Tests: Avoid passing an object when invoking static methods via reflection. (WordPress/gutenberg#86329) - [WP 7.2] DropdownMenu: Invert the selected item indicator while highlighted (WordPress/gutenberg#86379) - Fields: Lowercase the (no excerpt), (no author) and (no description) placeholders (WordPress/gutenberg#86391) (#86424) - Core fields: Decode non-Latin slugs in the slug field (WordPress/gutenberg#86359) - Interactivity API: Show the new page's server content in kept data-wp-html elements (WordPress/gutenberg#86416) - DataForm: Tighten value density in the panel layout (WordPress/gutenberg#86389) (#86426) - Post summary: Show "Immediately" and relative publish dates in the Date row (WordPress/gutenberg#86367) - [WP 7.2] Block Styles: Show the active style variation in forced colors mode (WordPress/gutenberg#86450) - Site Editor: Fix the frame snapping to the mobile width when resized with the mouse (WordPress/gutenberg#86423) - Image: measure the lightbox container, not the image's parent (WordPress/gutenberg#82312) (#85491) - URL: Decode percent-encoded characters in getFilename (WordPress/gutenberg#86422) (#86477) - Fix: Hide the author avatar when the site does not show avatars and frame a blank one. (WordPress/gutenberg#86395) - Date picker: Mark the posts of the month a typed or reset date moves to (WordPress/gutenberg#86298) (#86463) - Fix iOS 27 tap into a heading leaving the caret in a quote (WordPress/gutenberg#85809) - Hand focus back to the field on a press in every browser (WordPress/gutenberg#86549) - Prevent jobs from running within forks on `push`. (WordPress/gutenberg#85968) - i18n: Add translator context to the "Copy error" button label (WordPress/gutenberg#85967) - Bubble editor canvas events to the outer iframe (WordPress/gutenberg#85263) - UI: Use LoadingIndicator in remaining popup consumers (WordPress/gutenberg#86501) - Block Editor: Keep the revision canvas read-only in preview mode (WordPress/gutenberg#84578) - Core Data: Rank an exact title match first among tied link suggestions (WordPress/gutenberg#86327) - Tests: Render the router-html-server context case through state (WordPress/gutenberg#86511) - iOS tests: De-flake the selection handle test (WordPress/gutenberg#85461) Props mamaduka, wildworks. See #66340. git-svn-id: https://develop.svn.wordpress.org/trunk@65379 602fd350-edb4-49c9-b593-d223f7449a82
What?
Follow-up to #84889 and #84924.
A
data-wp-htmlelement that client-side navigation keeps in a router region now shows the new page's server-rendered content when its value on the new page is{ "wpServerHtml": true }or pending, instead of the content it had on the previous page. This removes the known limitation that #84889 added to thewp-htmlreference.Why?
Navigation keeps the DOM element at the same place in a router region, and the directive left a kept element's content alone for these two values. So after navigating, the element went on showing the previous page's content while the new page's HTML held different content for it. A
data-wp-htmlelement the navigation creates, and a keptdata-wp-textelement with a pending value, already showed the new page's content.How?
toVdom()already keeps a script-free snapshot of eachdata-wp-htmlelement's server content (Interactivity API: Show the data-wp-html fallback on created elements under Trusted Types #84924). It now also records whether a snapshot comes from the document's markup or from<template>content, and a package-internalgetHtmlServerContent()returns only the first kind, so keptdata-wp-eachitems never show their template's content.data-wp-watchcallbacks that update notifies, which run one frame later. A callback that copies the server representation into the element's value, as the guides recommend, therefore works too.importNode(). Copying nodes isn't a Trusted Types sink, so showing the content writes no HTML string and calls no policy. The content comes only from the new page's server-rendered HTML, without its<script>elements.isEqualNode()plus the contents of<template>elements, whichisEqualNode()ignores. An element showing unchanged content keeps its nodes, along with changes scripts or the visitor made to them after the page hydrated, such as an opened<details>or an added class.nulland invalid values, hydration, elements the navigation creates, elements outside router regions anddata-wp-eachitems keep their behavior. The router is unchanged.wp-htmlreference and the@wordpress/interactivitychangelog describe the new outcome.Limitations and follow-ups
getServerContext(), a value that goes from the marker on the previous page to a token,null,undefinedor an invalid value on the new page still sees the previous page's value in the navigation's first render. The new page's server content is inserted for a moment and replaced within the same update, so the final DOM is right and nothing is painted in between, but images and media in that content may start loading. A getter that readsgetServerState()is not affected. This is accepted for this PR and left as a follow-up. A getter that returns a pending value on the previous page behaves the same way; no documented consumer was found that switches like this between pages.<noscript>elements, doesn't count as the same server content. It is replaced when navigating away from that page, and can be when navigating back. The reference now says so.Testing Instructions
<!-- wp:test/router-html-server {"page":"two"} /-->, and page one with<!-- wp:test/router-html-server {"page":"one","next":"<URL of page two>"} /-->.One.Two. On trunk they keep showingOne.npm run test:unit:vitest -- packages/interactivity packages/interactivity-routernpm run test:e2e -- test/e2e/specs/interactivity/router-html-server.spec.ts test/e2e/specs/interactivity/router-html.spec.ts test/e2e/specs/interactivity/directive-html.spec.tsTesting Instructions for Keyboard
No UI changes.
Use of AI Tools
100% of the code, tests, and comments in this PR were autonomously generated by AI and reviewed by @luisherranz before the PR was opened.