@wordpress/e2e-tests 9.21.0 → 9.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/mu-plugins/e2e-fast-sync-polling.php +4 -4
  3. package/package.json +4 -5
  4. package/plugins/block-bindings.php +5 -0
  5. package/plugins/interactive-blocks/directive-html/block.json +15 -0
  6. package/plugins/interactive-blocks/directive-html/render.php +42 -0
  7. package/plugins/interactive-blocks/directive-html/view.asset.php +1 -0
  8. package/plugins/interactive-blocks/directive-html/view.js +20 -0
  9. package/plugins/interactive-blocks/directive-init/render.php +1 -1
  10. package/plugins/interactive-blocks/directive-on/render.php +1 -1
  11. package/plugins/interactive-blocks/directive-on-document/render.php +1 -1
  12. package/plugins/interactive-blocks/directive-on-window/render.php +1 -1
  13. package/plugins/interactive-blocks/directive-run/render.php +1 -1
  14. package/plugins/interactive-blocks/directive-run/view.js +2 -2
  15. package/plugins/interactive-blocks/directive-watch/render.php +1 -1
  16. package/plugins/interactive-blocks/router-navigation-full-page/block.json +15 -0
  17. package/plugins/interactive-blocks/router-navigation-full-page/render.php +120 -0
  18. package/plugins/interactive-blocks/router-navigation-full-page/view.asset.php +9 -0
  19. package/plugins/interactive-blocks/router-navigation-full-page/view.js +95 -0
  20. package/plugins/interactive-blocks/router-navigation-lifecycle/block.json +15 -0
  21. package/plugins/interactive-blocks/router-navigation-lifecycle/render.php +303 -0
  22. package/plugins/interactive-blocks/router-navigation-lifecycle/view.asset.php +9 -0
  23. package/plugins/interactive-blocks/router-navigation-lifecycle/view.js +383 -0
  24. package/plugins/interactive-blocks/tovdom-islands/render.php +7 -10
  25. package/plugins/interactive-blocks/with-scope/render.php +1 -1
  26. package/plugins/lightbox-overlay-wrapper.php +25 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 9.22.0 (2026-10-07)
6
+
7
+ ### Enhancements
8
+
9
+ - Remove the unused Jest peer dependency from the fixture package ([#83502](https://github.com/WordPress/gutenberg/pull/83502)).
10
+
5
11
  ## 9.21.0 (2026-09-23)
6
12
 
7
13
  ## 9.20.0 (2026-09-10)
@@ -2,15 +2,15 @@
2
2
  /**
3
3
  * MU-plugin: Speed up collaboration sync polling in e2e tests.
4
4
  *
5
- * The sync module reads its polling intervals via applyFilters at load time,
6
- * so the filters must be registered before the wp-sync script executes.
7
- * Hooked to admin_init so the wp-sync handle is already registered.
5
+ * The sync module reads its polling intervals via applyFilters at load time.
6
+ * The sync module is bundled into the wp-core-data script, so the filters
7
+ * must be registered before that script executes.
8
8
  */
9
9
  add_action(
10
10
  'enqueue_block_editor_assets',
11
11
  function () {
12
12
  wp_add_inline_script(
13
- 'wp-sync',
13
+ 'wp-core-data',
14
14
  <<<'JS'
15
15
  wp.hooks.addFilter(
16
16
  'sync.pollingManager.pollingInterval',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/e2e-tests",
3
- "version": "9.21.0",
3
+ "version": "9.22.0",
4
4
  "description": "Test plugins and mu-plugins for E2E tests in WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -23,19 +23,18 @@
23
23
  "node": ">=18.12.0"
24
24
  },
25
25
  "dependencies": {
26
- "@wordpress/interactivity": "^6.56.0",
27
- "@wordpress/interactivity-router": "^2.56.0"
26
+ "@wordpress/interactivity": "^7.0.0",
27
+ "@wordpress/interactivity-router": "^2.57.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "y-websocket": "^3.0.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "jest": ">=29",
34
33
  "react": "^18 || ^19",
35
34
  "react-dom": "^18 || ^19"
36
35
  },
37
36
  "publishConfig": {
38
37
  "access": "public"
39
38
  },
40
- "gitHead": "56d8058eda6e30c4cc8bfc37818fa6ed972f7dc2"
39
+ "gitHead": "12441e2520c78b2254a792a8cba40c34110be060"
41
40
  }
@@ -28,6 +28,11 @@ function gutenberg_test_block_bindings_registration() {
28
28
  'value' => $testing_url,
29
29
  'type' => 'string',
30
30
  ),
31
+ 'icon_field' => array(
32
+ 'label' => 'Icon Field Label',
33
+ 'value' => 'core/arrow-right',
34
+ 'type' => 'string',
35
+ ),
31
36
  'empty_field' => array(
32
37
  'label' => 'Empty Field Label',
33
38
  'value' => '',
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
4
+ "name": "test/directive-html",
5
+ "title": "E2E Interactivity tests - directive html",
6
+ "category": "text",
7
+ "icon": "heart",
8
+ "description": "",
9
+ "supports": {
10
+ "interactivity": true
11
+ },
12
+ "textdomain": "e2e-interactivity",
13
+ "viewScriptModule": "file:./view.js",
14
+ "render": "file:./render.php"
15
+ }
@@ -0,0 +1,42 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the directive `data-wp-html`.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+ ?>
8
+
9
+ <div data-wp-interactive="directive-html">
10
+ <div data-wp-html="state.html" data-testid="show state html">
11
+ <p data-testid="fallback">Fallback content</p>
12
+ </div>
13
+
14
+ <button data-wp-on--click="actions.setHtml" data-testid="set html">
15
+ Set HTML
16
+ </button>
17
+
18
+ <button
19
+ data-wp-on--click="actions.setLoading"
20
+ data-testid="set loading"
21
+ >
22
+ Set Loading
23
+ </button>
24
+
25
+ <button
26
+ data-wp-on--click="actions.setPlainString"
27
+ data-testid="set plain string"
28
+ >
29
+ Set Plain String
30
+ </button>
31
+
32
+ <div data-wp-html--suffix="state.html" data-testid="ignores suffixes">
33
+ <span data-testid="suffix-fallback">Suffix fallback</span>
34
+ </div>
35
+
36
+ <div
37
+ data-wp-html---unique-id="state.html"
38
+ data-testid="ignores unique-ids"
39
+ >
40
+ <span data-testid="unique-id-fallback">Unique ID fallback</span>
41
+ </div>
42
+ </div>
@@ -0,0 +1 @@
1
+ <?php return array( 'dependencies' => array( '@wordpress/interactivity' ) );
@@ -0,0 +1,20 @@
1
+ import { store, asDangerousHTML } from '@wordpress/interactivity';
2
+
3
+ const { state } = store( 'directive-html', {
4
+ state: {
5
+ html: null,
6
+ },
7
+ actions: {
8
+ setHtml() {
9
+ state.html = asDangerousHTML(
10
+ '<strong data-testid="rendered-strong">Rendered HTML</strong>'
11
+ );
12
+ },
13
+ setLoading() {
14
+ state.html = null;
15
+ },
16
+ setPlainString() {
17
+ state.html = '<strong>Not rendered</strong>';
18
+ },
19
+ },
20
+ } );
@@ -19,7 +19,7 @@
19
19
  <div
20
20
  data-testid="multiple inits"
21
21
  data-wp-context='{"isReady":[false,false],"calls":[0,0]}'
22
- data-wp-init--one="actions.initOne"
22
+ data-wp-init---one="actions.initOne"
23
23
  data-wp-init---two="actions.initTwo"
24
24
  >
25
25
  <p data-wp-text="state.isReady" data-testid="isReady">false,false</p>
@@ -66,7 +66,7 @@
66
66
  <button
67
67
  data-testid="multiple handlers button"
68
68
  data-wp-on--click="actions.setClicked"
69
- data-wp-on--click--counter="actions.countClick"
69
+ data-wp-on--click---counter="actions.countClick"
70
70
  data-wp-on--click---toggle="actions.toggle"
71
71
  >Click me!</button>
72
72
  </div>
@@ -26,7 +26,7 @@
26
26
  </div>
27
27
  <div
28
28
  data-wp-on-document--keydown="actions.keydownHandler"
29
- data-wp-on-document--keydown--second="actions.keydownSecondHandler"
29
+ data-wp-on-document--keydown---second="actions.keydownSecondHandler"
30
30
  data-wp-on-document--keydown---third="actions.keydownThirdHandler"
31
31
  >
32
32
  <p data-wp-text="state.keydownHandler" data-testid="keydownHandler">no</p>
@@ -23,7 +23,7 @@
23
23
  </div>
24
24
  <div
25
25
  data-wp-on-window--resize="actions.resizeHandler"
26
- data-wp-on-window--resize--second="actions.resizeSecondHandler"
26
+ data-wp-on-window--resize---second="actions.resizeSecondHandler"
27
27
  data-wp-on-window--resize---third="actions.resizeThirdHandler"
28
28
  >
29
29
  <p data-wp-text="state.resizeHandler" data-testid="resizeHandler">no</p>
@@ -43,7 +43,7 @@
43
43
  data-watch=""
44
44
  >
45
45
  <div
46
- data-wp-run--mounted="callbacks.updateIsMounted"
46
+ data-wp-run---mounted="callbacks.updateIsMounted"
47
47
  data-wp-run---hooks="callbacks.useHooks"
48
48
  >
49
49
  Element with wp-run using hooks
@@ -39,8 +39,8 @@ const html = `
39
39
  <div data-testid="navigated">yes</div>
40
40
 
41
41
  <div
42
- data-wp-run--hydrated="callbacks.updateIsHydrated"
43
- data-wp-run--renderCount="callbacks.updateRenderCount"
42
+ data-wp-run---hydrated="callbacks.updateIsHydrated"
43
+ data-wp-run---renderCount="callbacks.updateRenderCount"
44
44
  data-wp-text="state.clickCount"
45
45
  ></div>
46
46
  </div>
@@ -31,7 +31,7 @@
31
31
 
32
32
  <div
33
33
  data-testid="multiple watches"
34
- data-wp-watch--one="callbacks.watch1"
34
+ data-wp-watch---one="callbacks.watch1"
35
35
  data-wp-watch---two="callbacks.watch2"
36
36
  data-wp-bind--data-watch-one="state.watch1"
37
37
  data-wp-bind--data-watch-two="state.watch2"
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
4
+ "name": "test/router-navigation-full-page",
5
+ "title": "E2E Interactivity tests - router navigation full-page mode",
6
+ "category": "text",
7
+ "icon": "heart",
8
+ "description": "",
9
+ "supports": {
10
+ "interactivity": true
11
+ },
12
+ "textdomain": "e2e-interactivity",
13
+ "viewScriptModule": "file:./view.js",
14
+ "render": "file:./render.php"
15
+ }
@@ -0,0 +1,120 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the router navigation lifecycle state (`state.navigating`
4
+ * and `state.initiator`, published by `@wordpress/interactivity-router`) in
5
+ * **full-page** client-side navigation mode (the
6
+ * `gutenberg-full-page-client-side-navigation` experiment).
7
+ *
8
+ * Full-page mode makes the whole BODY the router region --
9
+ * `Gutenberg_Interactivity_API_Full_Page_Navigation::add_directives_to_body()`
10
+ * sets `data-wp-interactive` and `data-wp-router-region="core/body"` on the
11
+ * BODY tag itself, and there is no per-post switch. So, unlike
12
+ * `router-navigation-lifecycle`, this fixture's own wrapper declares *no*
13
+ * `data-wp-router-region` of its own: its own named region (`regionId`) is
14
+ * nested *inside* the implicit BODY region, which is what lets the "outside
15
+ * every block region" control below -- rendered inside this wrapper but
16
+ * outside that nested region -- derive `core/body` by walking up to BODY,
17
+ * rather than stopping at this wrapper or at some region of its own.
18
+ *
19
+ * @package gutenberg-test-interactive-blocks
20
+ *
21
+ * @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
22
+ */
23
+
24
+ $page = $attributes['page'] ?? '';
25
+ $next_href = $attributes['next'] ?? null;
26
+ $region_id = $attributes['regionId'] ?? '';
27
+ ?>
28
+ <div data-wp-interactive="router-navigation-full-page">
29
+ <?php if ( isset( $next_href ) ) : ?>
30
+ <!--
31
+ A plain <a>, outside every block region. No directive
32
+ handles this click, so the full-page document click listener
33
+ (`packages/interactivity-router/src/full-page.ts`) does -- and
34
+ that listener's own `actions.navigate()` call carries no ambient
35
+ directive scope, so it must read absent regardless of where this
36
+ link sits in the DOM.
37
+ -->
38
+ <a
39
+ data-testid="plain-link-outside-region"
40
+ href="<?php echo esc_url( $next_href ); ?>"
41
+ >plain link (outside region)</a>
42
+
43
+ <!--
44
+ A directive-scoped click control, also outside every
45
+ block region. Its own `data-wp-on--click` action *does* carry an
46
+ ambient scope, and this control's nearest enclosing
47
+ `data-wp-router-region` is the BODY the full-page PHP class marks
48
+ `core/body` -- not this wrapper, which declares none of its own.
49
+ -->
50
+ <a
51
+ data-testid="navigate-outside-region"
52
+ data-wp-on--click="actions.navigate"
53
+ href="<?php echo esc_url( $next_href ); ?>"
54
+ >navigate (outside region)</a>
55
+ <?php endif; ?>
56
+
57
+ <?php
58
+ /*
59
+ * Note (see `router-navigation-lifecycle/render.php` for the
60
+ * full account): `data-wp-interactive` is repeated here even though the
61
+ * outer wrapper above already carries it. `interactivity-router`'s own
62
+ * region-detection selector requires the region-bearing element itself
63
+ * to carry `data-wp-interactive`, not merely an ancestor -- omitting it
64
+ * here would hydrate fine on first load and then silently drop this
65
+ * region's content after the first client-side navigation.
66
+ */
67
+ ?>
68
+ <div
69
+ data-testid="region-<?php echo esc_attr( $region_id ); ?>"
70
+ data-wp-interactive="router-navigation-full-page"
71
+ data-wp-router-region="<?php echo esc_attr( $region_id ); ?>"
72
+ >
73
+ <?php if ( isset( $next_href ) ) : ?>
74
+ <!--
75
+ A plain <a>, this time *inside* the fixture's own
76
+ region. Still handled by the document listener, not by any
77
+ directive scope -- DOM containment must not change the
78
+ reading, which is exactly what makes this link and the one
79
+ above a matched pair.
80
+ -->
81
+ <a
82
+ data-testid="plain-link-inside-region"
83
+ href="<?php echo esc_url( $next_href ); ?>"
84
+ >plain link (inside region)</a>
85
+
86
+ <!--
87
+ A click handled by this block's own scoped action,
88
+ inside its own region -- the identical shape to
89
+ `router-navigation-lifecycle`'s region-mode `navigate` link,
90
+ so the reading it produces here must match the region-mode
91
+ reading exactly.
92
+ -->
93
+ <a
94
+ data-testid="navigate-inside-region"
95
+ data-wp-on--click="actions.navigate"
96
+ href="<?php echo esc_url( $next_href ); ?>"
97
+ >navigate (inside region)</a>
98
+ <?php endif; ?>
99
+
100
+ <p data-testid="page-marker">page marker: <?php echo esc_html( $page ); ?></p>
101
+ </div>
102
+
103
+ <!--
104
+ The observer readout -- the same shape as
105
+ `router-navigation-lifecycle`'s counted lifecycle observer, reading
106
+ `core/router` state from this block's own store namespace. Its run
107
+ *count* is not asserted anywhere in this fixture's tests: the
108
+ BODY-wide region tears this whole wrapper down and rebuilds it on
109
+ every navigation, so a count here is a function of reconciliation,
110
+ not of the lifecycle. Its *content* still is evidence, because
111
+ `state.log` is module state and survives the region swap.
112
+ -->
113
+ <p
114
+ data-testid="lifecycle log"
115
+ data-wp-watch="callbacks.watchLifecycle"
116
+ data-wp-text="state.log"
117
+ >not hydrated</p>
118
+ <p data-testid="lifecycle navigating" data-wp-text="state.navigatingReading">not hydrated</p>
119
+ <p data-testid="lifecycle initiator" data-wp-text="state.initiatorReading">not hydrated</p>
120
+ </div>
@@ -0,0 +1,9 @@
1
+ <?php return array(
2
+ 'dependencies' => array(
3
+ '@wordpress/interactivity',
4
+ array(
5
+ 'id' => '@wordpress/interactivity-router',
6
+ 'import' => 'dynamic',
7
+ ),
8
+ ),
9
+ );
@@ -0,0 +1,95 @@
1
+ import { store, withSyncEvent } from '@wordpress/interactivity';
2
+
3
+ /*
4
+ * `core/router` is *read*, never imported -- same rationale as
5
+ * `router-navigation-lifecycle/view.js`: this namespace is auto-created by
6
+ * the store proxy and later merges into the router's own store once (and
7
+ * if) that module loads.
8
+ */
9
+ const { state: routerState } = store( 'core/router' );
10
+
11
+ /**
12
+ * Renders a `navigating` value the same way as
13
+ * `router-navigation-lifecycle/view.js`'s `describeNavigating`.
14
+ *
15
+ * @param {boolean|undefined} navigating
16
+ * @return {string} The human-readable reading.
17
+ */
18
+ function describeNavigating( navigating ) {
19
+ return navigating ? 'navigating' : 'not navigating';
20
+ }
21
+
22
+ /**
23
+ * Renders an `initiator` value the same way as
24
+ * `router-navigation-lifecycle/view.js`'s `describeInitiator`. `undefined`
25
+ * (never set) and `null` (no enclosing region, or explicitly suppressed) are
26
+ * deliberately not distinguished here -- both are the documented "absence of
27
+ * identity" reading (Requirement 11).
28
+ *
29
+ * @param {string|null|undefined} initiator
30
+ * @return {string} The human-readable reading.
31
+ */
32
+ function describeInitiator( initiator ) {
33
+ return initiator === undefined || initiator === null ? 'absent' : initiator;
34
+ }
35
+
36
+ const { state } = store( 'router-navigation-full-page', {
37
+ state: {
38
+ /*
39
+ * The backing array lives inside `state`, not at module scope, for
40
+ * the same reason as `router-navigation-lifecycle/view.js`: a
41
+ * module-scope mutation is invisible to the signals system, so
42
+ * nothing would ever mark `state.log`'s `data-wp-text` readout dirty.
43
+ */
44
+ _log: [],
45
+
46
+ get navigatingReading() {
47
+ return describeNavigating( routerState.navigating );
48
+ },
49
+ get initiatorReading() {
50
+ return describeInitiator( routerState.initiator );
51
+ },
52
+
53
+ /*
54
+ * A serialized array, so a spec can `JSON.parse` the readout and
55
+ * assert on its *content*. This is the only instrument the full-page
56
+ * tests use for "a transition fired at all": the whole BODY is one
57
+ * router region in full-page mode, so this element -- and its
58
+ * `data-wp-watch` -- is torn down and re-created on every
59
+ * navigation, and its run *count* is therefore not a transition
60
+ * record. `state.log` itself is module state and survives the swap.
61
+ */
62
+ get log() {
63
+ return JSON.stringify( state._log );
64
+ },
65
+ },
66
+ actions: {
67
+ navigate: withSyncEvent( function* ( e ) {
68
+ /*
69
+ * `e.preventDefault()` is not optional here either: without it,
70
+ * every click also performs a full page load, and the full-page
71
+ * document listener (`full-page.ts`) would also see the event,
72
+ * since it gates on `! event.defaultPrevented` -- which is what
73
+ * the block-action test relies on.
74
+ */
75
+ e.preventDefault();
76
+ const { actions: router } =
77
+ yield import( '@wordpress/interactivity-router' );
78
+ yield router.navigate( e.target.href );
79
+ } ),
80
+ },
81
+ callbacks: {
82
+ /*
83
+ * The counted lifecycle observer, same shape as
84
+ * `router-navigation-lifecycle/view.js`'s `watchLifecycle`: reads
85
+ * *only* `routerState.navigating` and `routerState.initiator`, one
86
+ * entry per run.
87
+ */
88
+ watchLifecycle() {
89
+ state._log.push( {
90
+ navigating: describeNavigating( routerState.navigating ),
91
+ initiator: describeInitiator( routerState.initiator ),
92
+ } );
93
+ },
94
+ },
95
+ } );
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
4
+ "name": "test/router-navigation-lifecycle",
5
+ "title": "E2E Interactivity tests - router navigation lifecycle",
6
+ "category": "text",
7
+ "icon": "heart",
8
+ "description": "",
9
+ "supports": {
10
+ "interactivity": true
11
+ },
12
+ "textdomain": "e2e-interactivity",
13
+ "viewScriptModule": "file:./view.js",
14
+ "render": "file:./render.php"
15
+ }
@@ -0,0 +1,303 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the router navigation lifecycle state (`state.navigating`
4
+ * and `state.initiator`, published by `@wordpress/interactivity-router`) in
5
+ * region-based client-side navigation.
6
+ *
7
+ * This single fixture block is shared by every test of the
8
+ * `router-navigation-lifecycle` e2e spec, so it supports more attributes
9
+ * than any one test exercises. The spec's `beforeAll` lists the published
10
+ * pages and which attribute combination each one uses.
11
+ *
12
+ * @package gutenberg-test-interactive-blocks
13
+ *
14
+ * @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
15
+ */
16
+
17
+ if ( isset( $attributes['disableNavigation'] ) && $attributes['disableNavigation'] ) {
18
+ wp_interactivity_config(
19
+ 'core/router',
20
+ array( 'clientNavigationDisabled' => true )
21
+ );
22
+ }
23
+
24
+ $page = $attributes['page'] ?? '';
25
+
26
+ // Seeded into this block's own server context so `server-context-readout`
27
+ // below is driven by the real `parseServerData` -> `populateServerData`
28
+ // path rather than by static markup -- see the end-transition test and the "cascaded-commit
29
+ // absorption on the real server-context path" verifier it discharges.
30
+ wp_interactivity_state(
31
+ 'router-navigation-lifecycle',
32
+ array( 'readout' => "server context for page {$page}" )
33
+ );
34
+
35
+ $next_href = $attributes['next'] ?? null;
36
+ $other_href = $attributes['other'] ?? null;
37
+
38
+ // Each entry describes one router region this block instance renders: its
39
+ // id, the href its own (unlabelled) "navigate" link targets, and whether it
40
+ // is the primary region -- the one that also carries the destination marker
41
+ // and the server-context readout.
42
+ $regions = array();
43
+ if ( isset( $attributes['regionId'] ) ) {
44
+ $regions[] = array(
45
+ 'id' => $attributes['regionId'],
46
+ 'navigate_href' => $next_href,
47
+ 'is_primary' => true,
48
+ );
49
+ }
50
+ if ( isset( $attributes['secondRegionId'] ) ) {
51
+ $regions[] = array(
52
+ 'id' => $attributes['secondRegionId'],
53
+ // The second region's own "navigate" link targets `other`, not
54
+ // `next` -- deliberately, so a cross-region flow has two distinct
55
+ // hrefs for the router's `navigatingTo` bail to separate. "Same
56
+ // structure as the first" stops here: every other link below keeps
57
+ // its usual meaning for both regions.
58
+ 'navigate_href' => $other_href,
59
+ 'is_primary' => false,
60
+ );
61
+ }
62
+ ?>
63
+ <div data-wp-interactive="router-navigation-lifecycle">
64
+ <?php if ( empty( $attributes['observerOnly'] ) ) : ?>
65
+ <?php
66
+ foreach ( $regions as $region ) :
67
+ $region_id = $region['id'];
68
+ $navigate_href = $region['navigate_href'];
69
+ $context = wp_interactivity_data_wp_context( array( 'regionId' => $region_id ) );
70
+ ?>
71
+ <?php
72
+ /*
73
+ * Note: `data-wp-interactive` is repeated here even
74
+ * though the outer wrapper above already carries it. Do not
75
+ * "simplify" this away. The directive runtime's own hydration
76
+ * resolves the namespace from any ancestor, so omitting it here
77
+ * looks like it still works on first load -- links click,
78
+ * `data-wp-text` renders, everything hydrates fine. What breaks
79
+ * is silent: `interactivity-router`'s own region-detection
80
+ * selector (`regionsSelector` in
81
+ * `packages/interactivity-router/src/index.ts`) is
82
+ * `[data-wp-interactive][data-wp-router-region], [data-wp-interactive] [data-wp-interactive][data-wp-router-region]`
83
+ * -- it requires the *region-bearing element itself* to carry
84
+ * `data-wp-interactive`, not merely an ancestor. Without it,
85
+ * `preparePage()` never registers this element under
86
+ * `page.regions` for *any* page, including the very first one,
87
+ * so every navigation resets this region's signal to `null` and
88
+ * never repopulates it -- the region's entire content silently
89
+ * disappears after the first client-side navigation.
90
+ */
91
+ ?>
92
+ <div
93
+ data-testid="region-<?php echo esc_attr( $region_id ); ?>"
94
+ data-wp-interactive="router-navigation-lifecycle"
95
+ data-wp-router-region="<?php echo esc_attr( $region_id ); ?>"
96
+ data-wp-class--is-origin="state.isOrigin"
97
+ <?php echo $context; ?>
98
+ >
99
+ <?php if ( isset( $navigate_href ) ) : ?>
100
+ <a
101
+ data-testid="navigate"
102
+ data-wp-on--click="actions.navigate"
103
+ href="<?php echo esc_url( $navigate_href ); ?>"
104
+ >navigate</a>
105
+ <?php endif; ?>
106
+
107
+ <?php
108
+ /*
109
+ * `refresh` takes its href from `window.location.href` at
110
+ * click time, not from an attribute, so it renders on every
111
+ * page regardless of `next`/`other` -- which is what lets
112
+ * the superseded-navigation part of the uncached-traversal
113
+ * test start a navigation from page 2.
114
+ */
115
+ ?>
116
+ <a
117
+ data-testid="refresh"
118
+ data-wp-on--click="actions.refresh"
119
+ href="#"
120
+ >refresh</a>
121
+
122
+ <?php if ( isset( $next_href ) ) : ?>
123
+ <a
124
+ data-testid="navigate (silent)"
125
+ data-wp-on--click="actions.navigateSilent"
126
+ href="<?php echo esc_url( $next_href ); ?>"
127
+ >navigate (silent)</a>
128
+ <a
129
+ data-testid="navigate (declared)"
130
+ data-wp-on--click="actions.navigateDeclared"
131
+ href="<?php echo esc_url( $next_href ); ?>"
132
+ >navigate (declared)</a>
133
+ <a
134
+ data-testid="navigate (suppressed)"
135
+ data-wp-on--click="actions.navigateSuppressed"
136
+ href="<?php echo esc_url( $next_href ); ?>"
137
+ >navigate (suppressed)</a>
138
+ <a
139
+ data-testid="navigate (timeout)"
140
+ data-wp-on--click="actions.navigateTimeout"
141
+ href="<?php echo esc_url( $next_href ); ?>"
142
+ >navigate (timeout)</a>
143
+ <a
144
+ data-testid="prefetch"
145
+ data-wp-on--click="actions.prefetch"
146
+ href="<?php echo esc_url( $next_href ); ?>"
147
+ >prefetch</a>
148
+ <?php endif; ?>
149
+
150
+ <?php if ( isset( $other_href ) ) : ?>
151
+ <a
152
+ data-testid="navigate (other)"
153
+ data-wp-on--click="actions.navigate"
154
+ href="<?php echo esc_url( $other_href ); ?>"
155
+ >navigate (other)</a>
156
+ <?php endif; ?>
157
+
158
+ <?php if ( $region['is_primary'] ) : ?>
159
+ <p data-testid="page-marker">page marker: <?php echo esc_html( $page ); ?></p>
160
+ <p
161
+ data-testid="server-context-readout"
162
+ data-wp-text="state.readout"
163
+ >not hydrated</p>
164
+ <?php endif; ?>
165
+
166
+ <?php
167
+ /*
168
+ * Per-block spinner demonstration: a per-block spinner
169
+ * that shows only while *this* region's own navigation is
170
+ * in flight. `state.isLoading` reads `getContext().regionId`
171
+ * the same way `state.isOrigin` above does, so one getter
172
+ * serves every region on the page.
173
+ */
174
+ ?>
175
+ <span
176
+ data-testid="spinner-<?php echo esc_attr( $region_id ); ?>"
177
+ data-wp-class--is-loading="state.isLoading"
178
+ ></span>
179
+
180
+ <?php
181
+ /*
182
+ * Region-scoped focus demonstration: a third `data-wp-watch`
183
+ * (never run-counted), one per region, edge-triggered on the
184
+ * `navigating` reading and scoped so it can read its own
185
+ * `regionId` from context. See `watchFocus()` in `view.js`
186
+ * for why its previous-`navigating` bookkeeping is kept
187
+ * outside `context` rather than in it.
188
+ */
189
+ ?>
190
+ <span
191
+ data-testid="focus-watcher-<?php echo esc_attr( $region_id ); ?>"
192
+ data-wp-watch="callbacks.watchFocus"
193
+ ></span>
194
+ </div>
195
+ <?php endforeach; ?>
196
+
197
+ <?php if ( ! empty( $attributes['nested'] ) ) : ?>
198
+ <?php
199
+ /*
200
+ * Nested-regions fixture: an `inner-region` nested inside an
201
+ * `outer-region`, with the `navigate` link inside the inner
202
+ * one, so a derivation that walks to the *outermost* region
203
+ * (the reading a writer might reach for "because the router
204
+ * treats the outer region as the update unit") reads
205
+ * `outer-region` instead of the correct nearest-enclosing
206
+ * `inner-region`. Both posts using `nested` render the same
207
+ * two ids, so the router updates both regions on navigation.
208
+ *
209
+ * Note (see above): both the outer and the inner
210
+ * region element carry `data-wp-interactive` on *themselves*,
211
+ * not only on an ancestor -- `regionsSelector` requires it on
212
+ * the region-bearing element itself.
213
+ */
214
+ ?>
215
+ <div
216
+ data-testid="region-outer-region"
217
+ data-wp-interactive="router-navigation-lifecycle"
218
+ data-wp-router-region="outer-region"
219
+ >
220
+ <div
221
+ data-testid="region-inner-region"
222
+ data-wp-interactive="router-navigation-lifecycle"
223
+ data-wp-router-region="inner-region"
224
+ >
225
+ <?php if ( isset( $next_href ) ) : ?>
226
+ <a
227
+ data-testid="navigate"
228
+ data-wp-on--click="actions.navigate"
229
+ href="<?php echo esc_url( $next_href ); ?>"
230
+ >navigate</a>
231
+ <?php endif; ?>
232
+ </div>
233
+ </div>
234
+ <?php endif; ?>
235
+ <?php endif; ?>
236
+
237
+ <!--
238
+ The observer readout: rendered on every page, including
239
+ `observerOnly`. The two watchers live on their own elements, each --
240
+ not sharing one, since directives at one priority level on one
241
+ element share a scope object.
242
+ -->
243
+ <p
244
+ data-testid="lifecycle log"
245
+ data-wp-watch="callbacks.watchLifecycle"
246
+ data-wp-text="state.log"
247
+ >not hydrated</p>
248
+ <p
249
+ data-testid="settlement log"
250
+ data-wp-watch="callbacks.watchSettlement"
251
+ data-wp-text="state.settlementLog"
252
+ >not hydrated</p>
253
+ <p data-testid="lifecycle navigating" data-wp-text="state.navigatingReading">not hydrated</p>
254
+ <p data-testid="lifecycle initiator" data-wp-text="state.initiatorReading">not hydrated</p>
255
+
256
+ <span data-testid="bind-aria-busy" data-wp-bind--aria-busy="state.navigating"></span>
257
+ <span data-testid="bind-class-busy" data-wp-class--busy="state.navigating"></span>
258
+
259
+ <?php
260
+ /*
261
+ * The two `hidden` bindings, deliberately opposite
262
+ * polarities on the same page. `bind-hidden-negated` is
263
+ * `!state.navigating` -- the spinner shape, visible only while
264
+ * navigating -- and `bind-hidden-plain` is the un-negated inverse. Do
265
+ * not "fix" either expression to make a failing assertion pass: a
266
+ * test written against an inverted expectation goes red against
267
+ * *correct* code here, and dropping the negation would plant the bug
268
+ * in the fixture instead of the test. Check polarity against
269
+ * `getEvaluate`/`bind.ts`'s handling of the `!` prefix and of `hidden`
270
+ * specifically (`packages/interactivity/src/hooks.tsx:249,283-284` and
271
+ * `packages/interactivity/src/directives/bind.ts:67-72`), not
272
+ * intuition.
273
+ */
274
+ ?>
275
+ <span data-testid="bind-hidden-negated" data-wp-bind--hidden="!state.navigating"></span>
276
+ <span data-testid="bind-hidden-plain" data-wp-bind--hidden="state.navigating"></span>
277
+
278
+ <?php
279
+ /*
280
+ * A replica of Core's WP 6.9 loading-bar markup, bound to the
281
+ * *public* `core/router` store's deprecated `state.navigation` getter --
282
+ * not the private store WP 7.0 binds instead. `data-wp-interactive` is
283
+ * repeated here (unlike the plain elements above) because this element
284
+ * switches namespace away from `router-navigation-lifecycle`, not
285
+ * because of the region-detection trap noted earlier in this file.
286
+ */
287
+ ?>
288
+ <div
289
+ data-testid="loading-bar"
290
+ data-wp-interactive="core/router"
291
+ data-wp-class--start-animation="state.navigation.hasStarted"
292
+ data-wp-class--finish-animation="state.navigation.hasFinished"
293
+ ></div>
294
+
295
+ <?php
296
+ /*
297
+ * A Core-loading-bar equivalent, rebuilt purely from the new
298
+ * public keys plus a consumer-side 400 ms debounce -- see the bare
299
+ * `watch()` call in `view.js` that writes `state.showBar`.
300
+ */
301
+ ?>
302
+ <span data-testid="debounced-bar" data-wp-class--show-bar="state.showBar"></span>
303
+ </div>
@@ -0,0 +1,9 @@
1
+ <?php return array(
2
+ 'dependencies' => array(
3
+ '@wordpress/interactivity',
4
+ array(
5
+ 'id' => '@wordpress/interactivity-router',
6
+ 'import' => 'dynamic',
7
+ ),
8
+ ),
9
+ );
@@ -0,0 +1,383 @@
1
+ import {
2
+ store,
3
+ withSyncEvent,
4
+ getContext,
5
+ getServerState,
6
+ watch,
7
+ } from '@wordpress/interactivity';
8
+
9
+ /*
10
+ * A short timeout for the `navigate (timeout)` link's action. It only needs
11
+ * to be short enough that a route held open indefinitely by a test triggers
12
+ * the router's own timeout fallback well within a test's default timeout.
13
+ */
14
+ const NAVIGATE_TIMEOUT = 100;
15
+
16
+ /*
17
+ * `core/router` is *read*, never imported: this namespace is auto-created by
18
+ * the store proxy and later merges into the very same proxy the router
19
+ * module registers, once (and if) that module loads. That is what makes
20
+ * the router-absent page meaningful -- these
21
+ * getters must be safe to read before the router exists.
22
+ */
23
+ const { state: routerState } = store( 'core/router' );
24
+
25
+ /*
26
+ * Both logs below live *inside* the store's reactive `state`, as plain
27
+ * arrays under `state._log` / `state._settlementLog`, rather than as
28
+ * module-scope variables: mutating a module-scope array is invisible to the
29
+ * signals system, so nothing would ever mark `state.log` / `state.settlementLog`
30
+ * dirty and their `data-wp-text` readouts would render once, at hydration,
31
+ * and never again. Pushing into an array that is itself part of the
32
+ * reactive state (the same shape `state.items.push( … )` uses in
33
+ * `router-regions/view.js`) does notify.
34
+ */
35
+ let previousNavigating = false;
36
+
37
+ /*
38
+ * Per-region previous-`navigating` bookkeeping for the region-scoped
39
+ * focus demo, keyed by region id. A plain module-scope object, not `context`: `watchFocus()` below
40
+ * both reads and writes it in the same run, and reading it through the
41
+ * reactive `context` proxy would subscribe that same effect to its own
42
+ * write, re-triggering it. It also has to live outside any one region's
43
+ * DOM, since the region element it would otherwise sit on can be torn
44
+ * down and recreated by a client-side navigation while this module stays
45
+ * loaded -- the same reason `previousNavigating` above is module scope
46
+ * rather than an element-local variable.
47
+ */
48
+ const focusWasNavigating = {};
49
+
50
+ /*
51
+ * Debounce timer for the loading-bar-equivalent demo, for the bare
52
+ * `watch()` registered near the bottom of this file.
53
+ */
54
+ let debounceTimer;
55
+
56
+ /*
57
+ * Raw lifecycle-write log. Unlike the counted `data-wp-watch` observer, a
58
+ * bare `watch()` runs synchronously for each notification, so it can observe
59
+ * the discharge immediately before this document is replaced.
60
+ */
61
+ const rawWriteLog = [];
62
+
63
+ /**
64
+ * Renders a `navigating` value the same way for the counted log and for the
65
+ * `lifecycle navigating` readout. `undefined` (never navigated) and `false`
66
+ * both read "not navigating", matching the tests' own wording -- the
67
+ * distinction between them is only ever observable through the four
68
+ * directive-bound elements (`state.navigating`, the raw value), not through
69
+ * this human-readable form.
70
+ *
71
+ * @param {boolean|undefined} navigating
72
+ * @return {string} The human-readable reading.
73
+ */
74
+ function describeNavigating( navigating ) {
75
+ return navigating ? 'navigating' : 'not navigating';
76
+ }
77
+
78
+ /**
79
+ * Renders an `initiator` value the same way for the counted log and for the
80
+ * `lifecycle initiator` readout. `undefined` (never set) and `null` (an
81
+ * explicit "no initiator", see `{ initiator: null }`) are deliberately not
82
+ * distinguished here: both are the documented "absence of identity"
83
+ * reading.
84
+ *
85
+ * @param {string|null|undefined} initiator
86
+ * @return {string} The human-readable reading.
87
+ */
88
+ function describeInitiator( initiator ) {
89
+ return initiator === undefined || initiator === null ? 'absent' : initiator;
90
+ }
91
+
92
+ const { state } = store( 'router-navigation-lifecycle', {
93
+ state: {
94
+ // Backing arrays for the two serialized logs -- see the comment
95
+ // above on why these must live inside `state`, not at module scope.
96
+ _log: [],
97
+ _settlementLog: [],
98
+
99
+ // Debounced-bar flag for the loading-bar-equivalent demo. Declared with an idle default and
100
+ // written directly (never derived), unlike `navigating`/`initiator`
101
+ // below -- this is *this* store's own state, not a passthrough of
102
+ // `core/router`'s, so none of the "don't declare" reasoning applies.
103
+ showBar: false,
104
+
105
+ /*
106
+ * Raw passthroughs of the router's own state, for the four
107
+ * directive-bound elements asserted before the first navigation. These need the real
108
+ * `boolean | undefined` value, not the human-readable text below,
109
+ * because their whole point is to exercise `data-wp-bind`'s and
110
+ * `data-wp-class`'s real boolean/undefined handling.
111
+ */
112
+ get navigating() {
113
+ return routerState.navigating;
114
+ },
115
+ get initiator() {
116
+ return routerState.initiator;
117
+ },
118
+
119
+ // Human-readable readouts for `data-testid="lifecycle navigating"`
120
+ // and `data-testid="lifecycle initiator"`.
121
+ get navigatingReading() {
122
+ return describeNavigating( routerState.navigating );
123
+ },
124
+ get initiatorReading() {
125
+ return describeInitiator( routerState.initiator );
126
+ },
127
+
128
+ /*
129
+ * `true` only while a navigation *this* element's own region
130
+ * initiated is in flight. Context-dependent so the same getter
131
+ * serves every region: each region co-renders its own id into
132
+ * `data-wp-context`, and this getter reads it back.
133
+ */
134
+ get isOrigin() {
135
+ const { regionId } = getContext();
136
+ return (
137
+ !! routerState.navigating && routerState.initiator === regionId
138
+ );
139
+ },
140
+
141
+ /*
142
+ * Per-block spinner demonstration: `true` only while a
143
+ * navigation *this* region's own element initiated is in flight.
144
+ * Computationally identical to `isOrigin` above -- both are the
145
+ * documented composition `state.navigating && state.initiator ===
146
+ * myRegionId` -- but kept as its own getter because it stands in
147
+ * for a real consumer's own per-block spinner, built from only the
148
+ * two public keys and `getContext()`, independent of the
149
+ * `isOrigin`/`is-origin` scaffolding used by the earlier identity tests.
150
+ */
151
+ get isLoading() {
152
+ const { regionId } = getContext();
153
+ return (
154
+ !! routerState.navigating && routerState.initiator === regionId
155
+ );
156
+ },
157
+
158
+ /*
159
+ * Serialized logs. A serialized array, rather than a hand-rolled
160
+ * delimited string, so a spec can `JSON.parse` the readout and
161
+ * assert on entry count and contents structurally.
162
+ */
163
+ get log() {
164
+ return JSON.stringify( state._log );
165
+ },
166
+ get settlementLog() {
167
+ return JSON.stringify( state._settlementLog );
168
+ },
169
+ },
170
+ actions: {
171
+ navigate: withSyncEvent( function* ( e ) {
172
+ e.preventDefault();
173
+ const { actions: router } =
174
+ yield import( '@wordpress/interactivity-router' );
175
+ yield router.navigate( e.target.href );
176
+ } ),
177
+ navigateSilent: withSyncEvent( function* ( e ) {
178
+ e.preventDefault();
179
+ const { actions: router } =
180
+ yield import( '@wordpress/interactivity-router' );
181
+ yield router.navigate( e.target.href, {
182
+ loadingAnimation: false,
183
+ screenReaderAnnouncement: false,
184
+ } );
185
+ } ),
186
+ refresh: withSyncEvent( function* ( e ) {
187
+ e.preventDefault();
188
+ const { actions: router } =
189
+ yield import( '@wordpress/interactivity-router' );
190
+ yield router.navigate( window.location.href, { force: true } );
191
+ } ),
192
+ navigateDeclared: withSyncEvent( function* ( e ) {
193
+ e.preventDefault();
194
+ const { actions: router } =
195
+ yield import( '@wordpress/interactivity-router' );
196
+ yield router.navigate( e.target.href, {
197
+ initiator: 'my-plugin/declared',
198
+ } );
199
+ } ),
200
+ navigateSuppressed: withSyncEvent( function* ( e ) {
201
+ e.preventDefault();
202
+ const { actions: router } =
203
+ yield import( '@wordpress/interactivity-router' );
204
+ yield router.navigate( e.target.href, { initiator: null } );
205
+ } ),
206
+ navigateTimeout: withSyncEvent( function* ( e ) {
207
+ e.preventDefault();
208
+ const { actions: router } =
209
+ yield import( '@wordpress/interactivity-router' );
210
+ yield router.navigate( e.target.href, {
211
+ timeout: NAVIGATE_TIMEOUT,
212
+ } );
213
+ } ),
214
+ prefetch: withSyncEvent( function* ( e ) {
215
+ e.preventDefault();
216
+ const { actions: router } =
217
+ yield import( '@wordpress/interactivity-router' );
218
+ yield router.prefetch( e.target.href );
219
+ } ),
220
+ },
221
+ callbacks: {
222
+ /*
223
+ * The counted lifecycle observer. Reads *only*
224
+ * `routerState.navigating` and `routerState.initiator`, so it never
225
+ * re-runs at the commit batch, which writes `state.url` while
226
+ * `navigating` is still truthy.
227
+ */
228
+ watchLifecycle() {
229
+ state._log.push( {
230
+ navigating: describeNavigating( routerState.navigating ),
231
+ initiator: describeInitiator( routerState.initiator ),
232
+ } );
233
+ },
234
+ /*
235
+ * The settlement probe. Edge-triggered: appends an entry only the
236
+ * moment `navigating` turns falsy, recording `routerState.url`, the
237
+ * destination marker's text and the server-context readout's text
238
+ * at that moment -- both read directly from the DOM, since this
239
+ * watcher's whole point is to observe the *committed* page rather
240
+ * than any reactive value of its own.
241
+ *
242
+ * Note: `populateServerData()` merges each navigation's
243
+ * server state with `override: false`
244
+ * (`packages/interactivity/src/proxies/state.ts:378-389`), so an
245
+ * *existing* key such as `state.readout` is never overwritten
246
+ * automatically on a later navigation -- only genuinely new keys
247
+ * are. Binding `data-wp-text="state.readout"` and expecting it to
248
+ * track each destination's own server-seeded value, with no further
249
+ * code, looked correct through hydration and the first page but
250
+ * silently kept showing the *first* page's value forever after.
251
+ * A consumer that wants a key to track the destination's
252
+ * own server-seeded value must re-sync it itself from
253
+ * `getServerState()`, the documented pattern
254
+ * (`router-regions/view.js`'s `updateCounterFromServer` does the
255
+ * same for context). Doing that sync here, as this callback's first
256
+ * statement, keeps the write and the DOM read that discharges the
257
+ * falling edge in one synchronous callback -- `@preact/signals`'
258
+ * text bindings update the DOM synchronously on write, so there is
259
+ * no cross-watcher race to get this wrong.
260
+ */
261
+ watchSettlement() {
262
+ const serverReadout = getServerState().readout;
263
+ if ( serverReadout !== undefined ) {
264
+ state.readout = serverReadout;
265
+ }
266
+ const navigating = !! routerState.navigating;
267
+ if ( previousNavigating && ! navigating ) {
268
+ const marker = document.querySelector(
269
+ '[data-testid="page-marker"]'
270
+ );
271
+ const readout = document.querySelector(
272
+ '[data-testid="server-context-readout"]'
273
+ );
274
+ state._settlementLog.push( {
275
+ url: routerState.url,
276
+ marker: marker ? marker.textContent : null,
277
+ serverContextReadout: readout ? readout.textContent : null,
278
+ } );
279
+ }
280
+ previousNavigating = navigating;
281
+ },
282
+ /*
283
+ * Region-scoped focus demonstration. Edge-
284
+ * triggered like `watchSettlement` above, but per-instance -- it
285
+ * lives on its own element inside *each* region (a third
286
+ * `data-wp-watch`, never run-counted), so it is scoped and can read
287
+ * its own `regionId` from context. Only fires on the falling edge
288
+ * when `initiator` still reads as *this* region's own id, which is
289
+ * what makes it refrain on a traversal (`initiator` reads absent
290
+ * there). No DOM reference is captured across the navigation: the
291
+ * target link is looked up fresh, by region id, only once the
292
+ * falling edge actually fires -- never stored ahead of time.
293
+ */
294
+ watchFocus() {
295
+ const { regionId } = getContext();
296
+ const navigating = !! routerState.navigating;
297
+ if (
298
+ focusWasNavigating[ regionId ] &&
299
+ ! navigating &&
300
+ routerState.initiator === regionId
301
+ ) {
302
+ document
303
+ .querySelector(
304
+ `[data-wp-router-region="${ regionId }"] a`
305
+ )
306
+ ?.focus();
307
+ }
308
+ focusWasNavigating[ regionId ] = navigating;
309
+ },
310
+ },
311
+ } );
312
+
313
+ /*
314
+ * Loading-bar-equivalent demonstration: a Core-loading-bar equivalent,
315
+ * rebuilt purely from the two public keys plus a consumer-side 400 ms
316
+ * debounce -- the debounced loading bar recipe from the Client-Side
317
+ * Navigation guide. A bare `watch()`, not a
318
+ * `data-wp-watch`: the timer callback writes this store's own `state`
319
+ * (`showBar`), not `context`, so it needs no scope at all.
320
+ */
321
+ watch( () => {
322
+ if ( routerState.navigating ) {
323
+ debounceTimer = setTimeout( () => {
324
+ state.showBar = true;
325
+ }, 400 );
326
+ } else {
327
+ clearTimeout( debounceTimer );
328
+ state.showBar = false;
329
+ }
330
+ } );
331
+
332
+ watch( () => {
333
+ rawWriteLog.push( {
334
+ navigating: routerState.navigating,
335
+ initiator: routerState.initiator,
336
+ } );
337
+ } );
338
+
339
+ /*
340
+ * Persists the counted log to `localStorage` right before this document is
341
+ * torn down, so a test can recover the *outgoing* document's last known
342
+ * state after a forced full page load -- even one triggered by a
343
+ * `window.location.assign()` / `.reload()` call whose own network request
344
+ * was intercepted (held or aborted) via Playwright's `page.route()`.
345
+ *
346
+ * This exists because holding a main-frame document request open, or
347
+ * aborting it, are both equally unable to keep the outgoing document's
348
+ * execution context alive and assertable in this environment. `pagehide`
349
+ * and `beforeunload`, by contrast, were confirmed (by a standalone probe
350
+ * against this same environment) to fire reliably even when the
351
+ * *outgoing* navigation's own request is aborted, and `localStorage`
352
+ * persists across the reload because the destination is same-origin. Both
353
+ * events are listened for, writing the same key, because a future
354
+ * navigation's exact treatment of an aborted vs. held request is not a
355
+ * guarantee this fixture should depend on.
356
+ */
357
+ window.addEventListener( 'pagehide', persistLogBeforeUnload );
358
+ window.addEventListener( 'beforeunload', persistLogBeforeUnload );
359
+ function persistLogBeforeUnload() {
360
+ try {
361
+ localStorage.setItem(
362
+ 'router-navigation-lifecycle:log-before-unload',
363
+ state.log
364
+ );
365
+ localStorage.setItem(
366
+ 'router-navigation-lifecycle:raw-write-log-before-unload',
367
+ JSON.stringify( rawWriteLog )
368
+ );
369
+ } catch {}
370
+ }
371
+
372
+ /*
373
+ * Module-scope, no directive scope at all: dynamically imports the router
374
+ * and navigates from an awaited continuation, for the scope-less
375
+ * programmatic navigation test. The destination is read off the already-rendered `navigate`
376
+ * link rather than hardcoded, so this works on any page carrying a region.
377
+ */
378
+ window.addEventListener( '_test_navigate_scopeless_', async () => {
379
+ const link = document.querySelector( '[data-testid="navigate"]' );
380
+ const { actions: router } =
381
+ await import( '@wordpress/interactivity-router' );
382
+ await router.navigate( link.href );
383
+ } );
@@ -32,11 +32,9 @@
32
32
  <div data-wp-interactive="tovdom-islands">
33
33
  <div data-wp-ignore>
34
34
  <div data-wp-show-mock="state.falseValue">
35
- <span
36
- data-testid="inside an inner block of an isolated island"
37
- >
38
- This should be shown because it is inside an inner
39
- block of an isolated island.
35
+ <span data-testid="inside an element with data-wp-ignore">
36
+ This should not be shown because data-wp-ignore no
37
+ longer prevents hydration.
40
38
  </span>
41
39
  </div>
42
40
  </div>
@@ -60,15 +58,14 @@
60
58
  <div>
61
59
  <div
62
60
  data-wp-interactive="tovdom-islands"
63
- data-wp-ignore
64
61
  >
65
62
  <div data-wp-show-mock="state.falseValue">
66
63
  <span
67
- data-testid="island inside inner block of isolated island"
64
+ data-testid="island inside an inner element of another island"
68
65
  >
69
- This should not be shown because even though it
70
- is inside an inner block of an isolated island,
71
- it's inside an new island.
66
+ This should not be shown because it is inside a
67
+ new island nested in an inner element of another
68
+ island.
72
69
  </span>
73
70
  </div>
74
71
  </div>
@@ -6,7 +6,7 @@
6
6
  */
7
7
  ?>
8
8
 
9
- <div data-wp-interactive="with-scope" data-wp-context='{"asyncCounter": 0, "syncCounter": 0}' data-wp-init--a='callbacks.asyncInit' data-wp-init--b='callbacks.syncInit'>
9
+ <div data-wp-interactive="with-scope" data-wp-context='{"asyncCounter": 0, "syncCounter": 0}' data-wp-init---a='callbacks.asyncInit' data-wp-init---b='callbacks.syncInit'>
10
10
  <p data-wp-text="context.asyncCounter" data-testid="asyncCounter">0</p>
11
11
  <p data-wp-text="context.syncCounter" data-testid="syncCounter">0</p>
12
12
  </div>
@@ -0,0 +1,25 @@
1
+ <?php
2
+ /**
3
+ * Plugin Name: Gutenberg Test Lightbox Overlay Wrapper
4
+ * Plugin URI: https://github.com/WordPress/gutenberg
5
+ * Author: Gutenberg Team
6
+ *
7
+ * @package gutenberg-test-lightbox-overlay-wrapper
8
+ */
9
+
10
+ /**
11
+ * Opens a wrapper around the page, so the lightbox overlay printed on
12
+ * `wp_footer` is not a direct child of `<body>`.
13
+ */
14
+ function gutenberg_test_lightbox_overlay_wrapper_open() {
15
+ echo '<div id="site-wrap">';
16
+ }
17
+ add_action( 'wp_body_open', 'gutenberg_test_lightbox_overlay_wrapper_open' );
18
+
19
+ /**
20
+ * Closes the wrapper after the lightbox overlay has been printed.
21
+ */
22
+ function gutenberg_test_lightbox_overlay_wrapper_close() {
23
+ echo '</div>';
24
+ }
25
+ add_action( 'wp_footer', 'gutenberg_test_lightbox_overlay_wrapper_close', 100 );