@wordpress/e2e-tests 9.20.1-next.v.202609171837.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 (29) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/mu-plugins/e2e-fast-sync-polling.php +4 -4
  3. package/package.json +5 -7
  4. package/plugins/block-bindings.php +5 -0
  5. package/plugins/interactive-blocks/directive-context/render.php +1 -1
  6. package/plugins/interactive-blocks/directive-html/block.json +15 -0
  7. package/plugins/interactive-blocks/directive-html/render.php +42 -0
  8. package/plugins/interactive-blocks/directive-html/view.asset.php +1 -0
  9. package/plugins/interactive-blocks/directive-html/view.js +20 -0
  10. package/plugins/interactive-blocks/directive-init/render.php +1 -1
  11. package/plugins/interactive-blocks/directive-on/render.php +1 -1
  12. package/plugins/interactive-blocks/directive-on-document/render.php +1 -1
  13. package/plugins/interactive-blocks/directive-on-window/render.php +1 -1
  14. package/plugins/interactive-blocks/directive-run/render.php +1 -1
  15. package/plugins/interactive-blocks/directive-run/view.js +2 -2
  16. package/plugins/interactive-blocks/directive-watch/render.php +1 -1
  17. package/plugins/interactive-blocks/router-navigation-full-page/block.json +15 -0
  18. package/plugins/interactive-blocks/router-navigation-full-page/render.php +120 -0
  19. package/plugins/interactive-blocks/router-navigation-full-page/view.asset.php +9 -0
  20. package/plugins/interactive-blocks/router-navigation-full-page/view.js +95 -0
  21. package/plugins/interactive-blocks/router-navigation-lifecycle/block.json +15 -0
  22. package/plugins/interactive-blocks/router-navigation-lifecycle/render.php +303 -0
  23. package/plugins/interactive-blocks/router-navigation-lifecycle/view.asset.php +9 -0
  24. package/plugins/interactive-blocks/router-navigation-lifecycle/view.js +383 -0
  25. package/plugins/interactive-blocks/tovdom-islands/render.php +7 -10
  26. package/plugins/interactive-blocks/with-scope/render.php +1 -1
  27. package/plugins/lightbox-overlay-wrapper.php +25 -0
  28. package/plugins/media-upload-filter/index.js +30 -0
  29. package/plugins/media-upload-filter.php +23 -0
@@ -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
+ } );