@timber-js/app 0.2.0-alpha.211 → 0.2.0-alpha.212
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.
- package/agent-skill.md +10 -5
- package/dist/_chunks/{actions-Rjk4htmA.js → actions-CCdnVtWm.js} +8 -6
- package/dist/_chunks/actions-CCdnVtWm.js.map +1 -0
- package/dist/_chunks/{als-registry-DaxkVjt5.js → als-registry-BZqHCtq-.js} +2 -4
- package/dist/_chunks/als-registry-BZqHCtq-.js.map +1 -0
- package/dist/_chunks/{cache-api-DGdYfNJn.js → cache-api-LA3sBpUS.js} +5 -5
- package/dist/_chunks/{cache-api-DGdYfNJn.js.map → cache-api-LA3sBpUS.js.map} +1 -1
- package/dist/_chunks/{chains-DGX9zmg9.js → chains-BfoPFraI.js} +2 -2
- package/dist/_chunks/{chains-DGX9zmg9.js.map → chains-BfoPFraI.js.map} +1 -1
- package/dist/_chunks/{classify-QwG5rxKI.js → classify-BT66U83D.js} +2 -2
- package/dist/_chunks/{classify-QwG5rxKI.js.map → classify-BT66U83D.js.map} +1 -1
- package/dist/_chunks/{cli-check-ajNY3B2e.js → cli-check-BfQ54-UJ.js} +3 -3
- package/dist/_chunks/{cli-check-ajNY3B2e.js.map → cli-check-BfQ54-UJ.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-D2eI8jEg.js → cli-schema-sync-czh2dsLs.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-D2eI8jEg.js.map → cli-schema-sync-czh2dsLs.js.map} +1 -1
- package/dist/_chunks/{client-dep-entries-2HCF09no.js → client-dep-entries-CQwpb8dI.js} +2 -2
- package/dist/_chunks/{client-dep-entries-2HCF09no.js.map → client-dep-entries-CQwpb8dI.js.map} +1 -1
- package/dist/_chunks/{convention-lint-DLmhGsRS.js → convention-lint-BEVW4EID.js} +3 -3
- package/dist/_chunks/{convention-lint-DLmhGsRS.js.map → convention-lint-BEVW4EID.js.map} +1 -1
- package/dist/_chunks/{dev-server-TFpEwm3H.js → dev-server-FKxptbnI.js} +2 -2
- package/dist/_chunks/{dev-server-TFpEwm3H.js.map → dev-server-FKxptbnI.js.map} +1 -1
- package/dist/_chunks/{json-lossy-check-CVuRs2hG.js → json-lossy-check-C8zBY2uZ.js} +2 -2
- package/dist/_chunks/{json-lossy-check-CVuRs2hG.js.map → json-lossy-check-C8zBY2uZ.js.map} +1 -1
- package/dist/_chunks/{live-graph-cNuWMYQI.js → live-graph-C_4v-fHv.js} +4 -4
- package/dist/_chunks/{live-graph-cNuWMYQI.js.map → live-graph-C_4v-fHv.js.map} +1 -1
- package/dist/_chunks/{logger-BP0LN6vP.js → logger-CbLdcy-W.js} +2 -2
- package/dist/_chunks/{logger-BP0LN6vP.js.map → logger-CbLdcy-W.js.map} +1 -1
- package/dist/_chunks/{poison-scan-CfQ3unZR.js → poison-scan-C92liMAr.js} +2 -2
- package/dist/_chunks/{poison-scan-CfQ3unZR.js.map → poison-scan-C92liMAr.js.map} +1 -1
- package/dist/_chunks/{scanner-DmqdxzbW.js → scanner-CQt12vE2.js} +2 -2
- package/dist/_chunks/{scanner-DmqdxzbW.js.map → scanner-CQt12vE2.js.map} +1 -1
- package/dist/_chunks/{sizeof-BM1409x2.js → sizeof-QPE5nd3u.js} +2 -2
- package/dist/_chunks/{sizeof-BM1409x2.js.map → sizeof-QPE5nd3u.js.map} +1 -1
- package/dist/_chunks/{walkers-Czu2jXFq.js → walkers-DAT4avhZ.js} +3 -3
- package/dist/_chunks/{walkers-Czu2jXFq.js.map → walkers-DAT4avhZ.js.map} +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cache/index.js +2 -2
- package/dist/cache/stores/memory.js +1 -1
- package/dist/cdn/workers-cache-purge.js +1 -1
- package/dist/cli.js +3 -3
- package/dist/client/browser-entry/action-dispatch.d.ts.map +1 -1
- package/dist/client/browser-entry/hydrate.d.ts.map +1 -1
- package/dist/client/browser-entry/router-init.d.ts.map +1 -1
- package/dist/client/form.d.ts +17 -64
- package/dist/client/form.d.ts.map +1 -1
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +23 -51
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.js +25 -25
- package/dist/client/internal.js.map +1 -1
- package/dist/client/navigation-api.d.ts +25 -63
- package/dist/client/navigation-api.d.ts.map +1 -1
- package/dist/client/router-lifecycle.d.ts +17 -11
- package/dist/client/router-lifecycle.d.ts.map +1 -1
- package/dist/client/router-pipeline.d.ts +0 -1
- package/dist/client/router-pipeline.d.ts.map +1 -1
- package/dist/client/router-types.d.ts +14 -45
- package/dist/client/router-types.d.ts.map +1 -1
- package/dist/client/router.d.ts.map +1 -1
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/plugins/shims.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/rsc-runtime/rsc.d.ts +1 -1
- package/dist/rsc-runtime/rsc.d.ts.map +1 -1
- package/dist/server/action-client.d.ts +9 -5
- package/dist/server/action-client.d.ts.map +1 -1
- package/dist/server/action-handler.d.ts +27 -8
- package/dist/server/action-handler.d.ts.map +1 -1
- package/dist/server/als-registry.d.ts +22 -2
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/client-error-message.d.ts +12 -0
- package/dist/server/client-error-message.d.ts.map +1 -0
- package/dist/server/form-state-embed.d.ts +32 -0
- package/dist/server/form-state-embed.d.ts.map +1 -0
- package/dist/server/index.d.ts +0 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +7 -40
- package/dist/server/index.js.map +1 -1
- package/dist/server/internal.js +10 -6
- package/dist/server/internal.js.map +1 -1
- package/dist/server/logger.d.ts +1 -0
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts +20 -6
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/request-context.d.ts +27 -2
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/rsc-entry/action-dispatcher.d.ts +6 -5
- package/dist/server/rsc-entry/action-dispatcher.d.ts.map +1 -1
- package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
- package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
- package/dist/server/ssr-bridge-types.d.ts +8 -0
- package/dist/server/ssr-bridge-types.d.ts.map +1 -1
- package/dist/server/ssr-entry.d.ts.map +1 -1
- package/dist/server/ssr-render.d.ts +3 -0
- package/dist/server/ssr-render.d.ts.map +1 -1
- package/docs/api/31-api-client.mdx +9 -3
- package/docs/learn/08-forms-and-actions.mdx +21 -28
- package/package.json +1 -1
- package/src/client/browser-entry/action-dispatch.ts +74 -18
- package/src/client/browser-entry/hydrate.ts +18 -0
- package/src/client/browser-entry/router-init.ts +4 -18
- package/src/client/form.tsx +33 -98
- package/src/client/index.ts +2 -2
- package/src/client/navigation-api.ts +47 -173
- package/src/client/navigation-transition.ts +2 -2
- package/src/client/router-lifecycle.ts +40 -20
- package/src/client/router-pipeline.ts +3 -9
- package/src/client/router-types.ts +14 -49
- package/src/client/router.ts +38 -58
- package/src/plugins/shims.ts +0 -2
- package/src/rsc-runtime/rsc.ts +3 -0
- package/src/rsc-runtime/vendor-types.d.ts +14 -0
- package/src/server/action-client.ts +18 -20
- package/src/server/action-handler.ts +133 -95
- package/src/server/als-registry.ts +23 -9
- package/src/server/client-error-message.ts +18 -0
- package/src/server/form-state-embed.ts +63 -0
- package/src/server/index.ts +0 -4
- package/src/server/logger.ts +6 -1
- package/src/server/pipeline.ts +27 -8
- package/src/server/request-context.ts +39 -2
- package/src/server/route-element-builder.ts +12 -1
- package/src/server/rsc-entry/action-dispatcher.ts +37 -34
- package/src/server/rsc-entry/error-renderer.ts +2 -1
- package/src/server/rsc-entry/rsc-stream.ts +20 -11
- package/src/server/rsc-entry/ssr-renderer.ts +14 -1
- package/src/server/ssr-bridge-types.ts +9 -0
- package/src/server/ssr-entry.ts +1 -0
- package/src/server/ssr-render.ts +5 -0
- package/dist/_chunks/actions-Rjk4htmA.js.map +0 -1
- package/dist/_chunks/als-registry-DaxkVjt5.js.map +0 -1
- package/dist/server/form-flash.d.ts +0 -78
- package/dist/server/form-flash.d.ts.map +0 -1
- package/src/server/form-flash.ts +0 -89
|
@@ -35,23 +35,13 @@ export interface NavigationEpoch {
|
|
|
35
35
|
readonly idle: boolean;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/** The subset of `RouterDeps` the navigation lifecycle needs. */
|
|
39
|
-
export interface NavigationLifecycleDeps {
|
|
40
|
-
/**
|
|
41
|
-
* Signal that a router-initiated navigation has completed. Resolves the
|
|
42
|
-
* deferred promise that ties the browser's native loading state to the
|
|
43
|
-
* navigation lifecycle.
|
|
44
|
-
*/
|
|
45
|
-
completeRouterNavigation?: () => void;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
38
|
export interface NavigationLifecycle {
|
|
49
39
|
/** The owner that holds the router right now, or null when idle. */
|
|
50
40
|
currentOwner: () => RenderOwner | null;
|
|
51
41
|
/**
|
|
52
42
|
* Take ownership of the router, superseding whatever held it. Returns
|
|
53
43
|
* a fresh `RenderOwner` for the new navigation. See the implementation
|
|
54
|
-
* for the
|
|
44
|
+
* for the two parts of superseding.
|
|
55
45
|
*/
|
|
56
46
|
createNavOwner: (
|
|
57
47
|
kind: 'navigation' | 'revalidation',
|
|
@@ -99,6 +89,21 @@ export interface NavigationLifecycle {
|
|
|
99
89
|
* replaces an earlier one (TIM-1474).
|
|
100
90
|
*/
|
|
101
91
|
runWhenIdle: (task: () => void) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Subscribe to the router becoming idle (pending false AND commit done):
|
|
94
|
+
* `listener` runs on every such transition until unsubscribed. Unlike
|
|
95
|
+
* `runWhenIdle`, any number of listeners may wait.
|
|
96
|
+
*/
|
|
97
|
+
onIdle: (listener: () => void) => () => void;
|
|
98
|
+
/**
|
|
99
|
+
* Subscribe to React committing a navigation's tree — the tree on screen
|
|
100
|
+
* has changed, whether or not its stream has finished decoding (so the
|
|
101
|
+
* router may still be pending). Runs on every commit until unsubscribed,
|
|
102
|
+
* with the committing navigation's `epoch().seq`: a tree handed to React
|
|
103
|
+
* before a later navigation started can still commit after it, and the
|
|
104
|
+
* sequence says which one it was.
|
|
105
|
+
*/
|
|
106
|
+
onTreeCommit: (listener: (seq: number) => void) => () => void;
|
|
102
107
|
/**
|
|
103
108
|
* Settle any handed-off-but-uncommitted owners as superseded, then flush
|
|
104
109
|
* the idle task if the router is now idle. Called by `syncShallowSearch`
|
|
@@ -119,7 +124,7 @@ function isAbortError(error: unknown): boolean {
|
|
|
119
124
|
return false;
|
|
120
125
|
}
|
|
121
126
|
|
|
122
|
-
export function createNavigationLifecycle(
|
|
127
|
+
export function createNavigationLifecycle(): NavigationLifecycle {
|
|
123
128
|
// The single ownership slot. One navigation at a time.
|
|
124
129
|
let current: RenderOwner | null = null;
|
|
125
130
|
|
|
@@ -135,6 +140,10 @@ export function createNavigationLifecycle(deps: NavigationLifecycleDeps): Naviga
|
|
|
135
140
|
|
|
136
141
|
let navigationSeq = 0;
|
|
137
142
|
let idleTask: (() => void) | null = null;
|
|
143
|
+
const idleListeners = new Set<() => void>();
|
|
144
|
+
const treeCommitListeners = new Set<(seq: number) => void>();
|
|
145
|
+
// The navigationSeq each owner ran under, for tree-commit listeners.
|
|
146
|
+
const ownerSeq = new WeakMap<RenderOwner, number>();
|
|
138
147
|
|
|
139
148
|
/**
|
|
140
149
|
* Whether a handed-off tree has not yet committed. Derived from the slot:
|
|
@@ -167,17 +176,13 @@ export function createNavigationLifecycle(deps: NavigationLifecycleDeps): Naviga
|
|
|
167
176
|
* in-flight navigation. Optionally links to an external signal (e.g.,
|
|
168
177
|
* from the Navigation API's NavigateEvent.signal).
|
|
169
178
|
*
|
|
170
|
-
* Superseding is one operation with
|
|
179
|
+
* Superseding is one operation with two parts:
|
|
171
180
|
* 1. Abort the previous navigation's fetch — UNLESS its tree is the one on
|
|
172
181
|
* screen, in which case tearing the stream down would error the page the
|
|
173
182
|
* user is currently looking at. See `RenderOwner.handedOff`.
|
|
174
183
|
* 2. Settle the previous owner as 'superseded' so its transition detects
|
|
175
184
|
* it lost and never hands a stale tree to React. This replaces both
|
|
176
185
|
* `supersedeNavigationTransitions()` and the transition counter bump.
|
|
177
|
-
* 3. Resolve its Navigation API deferred — the superseded navigation's
|
|
178
|
-
* finally block is staleness-guarded (see TIM-1034) and no longer
|
|
179
|
-
* cleans up after itself, so the browser's native loading state for
|
|
180
|
-
* the dead navigation is cleared here.
|
|
181
186
|
*/
|
|
182
187
|
function createNavOwner(
|
|
183
188
|
kind: 'navigation' | 'revalidation',
|
|
@@ -186,7 +191,6 @@ export function createNavigationLifecycle(deps: NavigationLifecycleDeps): Naviga
|
|
|
186
191
|
if (current) {
|
|
187
192
|
abortUnlessHandedOff(current);
|
|
188
193
|
current.settle('superseded');
|
|
189
|
-
deps.completeRouterNavigation?.();
|
|
190
194
|
}
|
|
191
195
|
// A handed-off owner whose runNavigation has already finished but whose
|
|
192
196
|
// tree hasn't committed yet. Settle it so its onCommit fires.
|
|
@@ -196,6 +200,7 @@ export function createNavigationLifecycle(deps: NavigationLifecycleDeps): Naviga
|
|
|
196
200
|
}
|
|
197
201
|
navigationSeq += 1;
|
|
198
202
|
const owner = createRenderOwner(kind);
|
|
203
|
+
ownerSeq.set(owner, navigationSeq);
|
|
199
204
|
current = owner;
|
|
200
205
|
|
|
201
206
|
// If an external signal is provided (e.g., Navigation API),
|
|
@@ -264,14 +269,16 @@ export function createNavigationLifecycle(deps: NavigationLifecycleDeps): Naviga
|
|
|
264
269
|
if (current === owner) {
|
|
265
270
|
current = null;
|
|
266
271
|
setPending(false);
|
|
267
|
-
deps.completeRouterNavigation?.();
|
|
268
272
|
flushIdleTask();
|
|
269
273
|
}
|
|
270
274
|
}
|
|
271
275
|
}
|
|
272
276
|
|
|
277
|
+
// Every place the router may have just become idle calls this.
|
|
273
278
|
function flushIdleTask(): void {
|
|
274
|
-
if (routerPhase.phase !== 'idle' || hasUncommittedNav()
|
|
279
|
+
if (routerPhase.phase !== 'idle' || hasUncommittedNav()) return;
|
|
280
|
+
for (const listener of [...idleListeners]) listener();
|
|
281
|
+
if (!idleTask) return;
|
|
275
282
|
const task = idleTask;
|
|
276
283
|
idleTask = null;
|
|
277
284
|
task();
|
|
@@ -307,10 +314,13 @@ export function createNavigationLifecycle(deps: NavigationLifecycleDeps): Naviga
|
|
|
307
314
|
if (pendingCommit === owner) {
|
|
308
315
|
pendingCommit = null;
|
|
309
316
|
}
|
|
317
|
+
const seq = ownerSeq.get(owner) ?? navigationSeq;
|
|
318
|
+
for (const listener of [...treeCommitListeners]) listener(seq);
|
|
310
319
|
flushIdleTask();
|
|
311
320
|
},
|
|
312
321
|
|
|
313
322
|
placeRevalidationOwner(owner: RenderOwner): void {
|
|
323
|
+
ownerSeq.set(owner, navigationSeq);
|
|
314
324
|
current = owner;
|
|
315
325
|
},
|
|
316
326
|
|
|
@@ -340,6 +350,16 @@ export function createNavigationLifecycle(deps: NavigationLifecycleDeps): Naviga
|
|
|
340
350
|
idleTask = task;
|
|
341
351
|
},
|
|
342
352
|
|
|
353
|
+
onIdle(listener) {
|
|
354
|
+
idleListeners.add(listener);
|
|
355
|
+
return () => idleListeners.delete(listener);
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
onTreeCommit(listener) {
|
|
359
|
+
treeCommitListeners.add(listener);
|
|
360
|
+
return () => treeCommitListeners.delete(listener);
|
|
361
|
+
},
|
|
362
|
+
|
|
343
363
|
settleHandoffs(): void {
|
|
344
364
|
if (pendingCommit) {
|
|
345
365
|
pendingCommit.settle('superseded');
|
|
@@ -55,7 +55,6 @@ export interface NavigationFetchOptions {
|
|
|
55
55
|
replace: boolean;
|
|
56
56
|
commitUrl?: string;
|
|
57
57
|
signal?: AbortSignal;
|
|
58
|
-
skipHistory?: boolean;
|
|
59
58
|
departingUrl?: string;
|
|
60
59
|
}
|
|
61
60
|
|
|
@@ -388,9 +387,9 @@ export function createNavigationPipeline({
|
|
|
388
387
|
result = await fetchRscPayload(url, deps, freshStateTree, currentUrl, options.signal);
|
|
389
388
|
}
|
|
390
389
|
|
|
391
|
-
// Update the browser history
|
|
392
|
-
//
|
|
393
|
-
// The committed URL keeps the #fragment (commitUrl) even though the
|
|
390
|
+
// Update the browser history. This is the only place a push/replace
|
|
391
|
+
// navigation moves the address bar, with or without the Navigation API
|
|
392
|
+
// (its listener leaves same-document pushState alone). The committed URL keeps the #fragment (commitUrl) even though the
|
|
394
393
|
// fetch/history-stack URL is hash-less (TIM-1035).
|
|
395
394
|
//
|
|
396
395
|
// Deferred with the rest of the commit: the address bar is navigation
|
|
@@ -400,17 +399,12 @@ export function createNavigationPipeline({
|
|
|
400
399
|
// response that won the race anyway re-pushed the abandoned URL
|
|
401
400
|
// (TIM-1022's failure mode, made unconditional by TIM-1301).
|
|
402
401
|
const commitHistoryUrl = (): void => {
|
|
403
|
-
if (options.skipHistory) return;
|
|
404
402
|
const commitUrl = options.commitUrl ?? url;
|
|
405
|
-
// Set the router-navigating flag so the Navigation API's navigate
|
|
406
|
-
// listener doesn't double-intercept this pushState/replaceState.
|
|
407
|
-
deps.setRouterNavigating?.(true);
|
|
408
403
|
if (options.replace) {
|
|
409
404
|
deps.replaceState({ timber: true, scrollY: 0 }, '', commitUrl);
|
|
410
405
|
} else {
|
|
411
406
|
deps.pushState({ timber: true, scrollY: 0 }, '', commitUrl);
|
|
412
407
|
}
|
|
413
|
-
deps.setRouterNavigating?.(false);
|
|
414
408
|
};
|
|
415
409
|
|
|
416
410
|
const params = await result.params;
|
|
@@ -89,25 +89,6 @@ export interface NavigationOptions {
|
|
|
89
89
|
* which of the three it was.
|
|
90
90
|
*/
|
|
91
91
|
onCommit?: (outcome: CommitOutcome) => void;
|
|
92
|
-
/**
|
|
93
|
-
* @internal AbortSignal from the Navigation API's NavigateEvent.
|
|
94
|
-
* When provided, the signal is linked to the router's per-navigation
|
|
95
|
-
* AbortController so in-flight RSC fetches are cancelled when a new
|
|
96
|
-
* navigation starts.
|
|
97
|
-
*/
|
|
98
|
-
_signal?: AbortSignal;
|
|
99
|
-
/**
|
|
100
|
-
* @internal Skip pushState/replaceState — the Navigation API has already
|
|
101
|
-
* updated the URL via event.intercept(). Used for external navigations
|
|
102
|
-
* intercepted by the navigate event handler.
|
|
103
|
-
*/
|
|
104
|
-
_skipHistory?: boolean;
|
|
105
|
-
/**
|
|
106
|
-
* @internal The URL the user is navigating FROM, captured before the
|
|
107
|
-
* Navigation API commits the destination. Sent as X-Timber-URL for
|
|
108
|
-
* slot skip comparison on the server (TIM-1232).
|
|
109
|
-
*/
|
|
110
|
-
_departingUrl?: string;
|
|
111
92
|
}
|
|
112
93
|
|
|
113
94
|
/**
|
|
@@ -177,34 +158,12 @@ export interface RouterDeps {
|
|
|
177
158
|
onCommit?: (outcome: CommitOutcome) => void
|
|
178
159
|
) => Promise<void>;
|
|
179
160
|
|
|
180
|
-
/**
|
|
181
|
-
* Whether the Navigation API is active and handling traversals.
|
|
182
|
-
* When true, the popstate handler is a no-op — the Navigation API's
|
|
183
|
-
* navigate event covers back/forward button presses.
|
|
184
|
-
*/
|
|
185
|
-
navigationApiActive?: boolean;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Called around pushState/replaceState to set a flag that prevents
|
|
189
|
-
* the Navigation API's navigate listener from double-handling
|
|
190
|
-
* router-initiated navigations.
|
|
191
|
-
*/
|
|
192
|
-
setRouterNavigating?: (value: boolean) => void;
|
|
193
|
-
|
|
194
161
|
/**
|
|
195
162
|
* Save scroll position via the Navigation API's per-entry state.
|
|
196
163
|
* When provided, used instead of history.replaceState for scroll storage.
|
|
197
164
|
*/
|
|
198
165
|
saveNavigationEntryScroll?: (scrollY: number) => void;
|
|
199
166
|
|
|
200
|
-
/**
|
|
201
|
-
* Signal that a router-initiated navigation has completed. Resolves the
|
|
202
|
-
* deferred promise that ties the browser's native loading state to the
|
|
203
|
-
* navigation lifecycle. Called in the finally block of navigate/refresh,
|
|
204
|
-
* the same place `setPending(false)` clears the TopLoader.
|
|
205
|
-
*/
|
|
206
|
-
completeRouterNavigation?: () => void;
|
|
207
|
-
|
|
208
167
|
/**
|
|
209
168
|
* Get the current unwrapped RSC payload element. Used for partial
|
|
210
169
|
* navigation: the router re-wraps the same element with new
|
|
@@ -212,14 +171,6 @@ export interface RouterDeps {
|
|
|
212
171
|
*/
|
|
213
172
|
_getCurrentPayload?: () => unknown;
|
|
214
173
|
|
|
215
|
-
/**
|
|
216
|
-
* Initiate a navigation via the Navigation API (`navigation.navigate()`).
|
|
217
|
-
* Fires the navigate event BEFORE committing the URL, allowing Chrome
|
|
218
|
-
* to show its native loading indicator. Falls back to pushState when
|
|
219
|
-
* unavailable.
|
|
220
|
-
*/
|
|
221
|
-
navigationNavigate?: (url: string, replace: boolean) => void;
|
|
222
|
-
|
|
223
174
|
/**
|
|
224
175
|
* Scroll the element matching a URL #fragment into view. Returns true
|
|
225
176
|
* when a matching element was found and scrolled. When absent or false,
|
|
@@ -301,6 +252,20 @@ export interface RouterInstance {
|
|
|
301
252
|
* router-idle are true (TIM-1474).
|
|
302
253
|
*/
|
|
303
254
|
runWhenIdle(task: () => void): void;
|
|
255
|
+
/**
|
|
256
|
+
* Subscribe to the router becoming idle — no navigation pending and no
|
|
257
|
+
* handed-off tree waiting to commit. Runs on every such transition until
|
|
258
|
+
* the returned function unsubscribes; any number of listeners may wait.
|
|
259
|
+
*/
|
|
260
|
+
onIdle(listener: () => void): () => void;
|
|
261
|
+
/**
|
|
262
|
+
* Subscribe to React committing a navigation's tree: the page on screen
|
|
263
|
+
* has changed, even if its stream is still decoding and the router is
|
|
264
|
+
* still pending. Runs on every commit until unsubscribed, with the
|
|
265
|
+
* committing navigation's `epoch().seq` — a tree handed to React before a
|
|
266
|
+
* later navigation started can still commit after it.
|
|
267
|
+
*/
|
|
268
|
+
onTreeCommit(listener: (seq: number) => void): () => void;
|
|
304
269
|
/**
|
|
305
270
|
* Settle any handed-off-but-uncommitted owners as superseded, then flush
|
|
306
271
|
* idle tasks. Called by `syncShallowSearch` when a shallow URL update
|
package/src/client/router.ts
CHANGED
|
@@ -59,7 +59,7 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
59
59
|
|
|
60
60
|
// Ownership of the router: who is navigating, whose fetch may be cut, and
|
|
61
61
|
// the pending store TopLoader subscribes to. See router-lifecycle.ts.
|
|
62
|
-
const lifecycle = createNavigationLifecycle(
|
|
62
|
+
const lifecycle = createNavigationLifecycle();
|
|
63
63
|
const {
|
|
64
64
|
currentOwner,
|
|
65
65
|
createNavOwner,
|
|
@@ -108,8 +108,6 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
108
108
|
async function navigate(url: string, options: NavigationOptions = {}): Promise<void> {
|
|
109
109
|
const scroll = options.scroll !== false;
|
|
110
110
|
const replace = options.replace === true;
|
|
111
|
-
const externalSignal = options._signal as AbortSignal | undefined;
|
|
112
|
-
const skipHistory = options._skipHistory === true;
|
|
113
111
|
// A push, a replace, and a server action redirect all move the user
|
|
114
112
|
// forward; the caller's own types ride beside it. A redirect this router
|
|
115
113
|
// follows keeps the types of the render it interrupted instead.
|
|
@@ -127,11 +125,9 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
127
125
|
const hash = hashIndex === -1 ? '' : url.slice(hashIndex);
|
|
128
126
|
const fetchUrl = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
129
127
|
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
// for non-Navigation-API navigations (TIM-1232).
|
|
134
|
-
const departingUrl = options._departingUrl ?? deps.getCurrentUrl();
|
|
128
|
+
// The address bar moves only when the destination commits, so it still
|
|
129
|
+
// names the page being left (TIM-1232).
|
|
130
|
+
const departingUrl = deps.getCurrentUrl();
|
|
135
131
|
|
|
136
132
|
// Capture the departing page's scroll position for scroll={false} preservation.
|
|
137
133
|
const currentScrollY = deps.getScrollY();
|
|
@@ -155,57 +151,39 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
155
151
|
await leaveSpaSuperseding(url, departingUrl);
|
|
156
152
|
}
|
|
157
153
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
performNavigationFetch(fetchUrl, {
|
|
181
|
-
replace,
|
|
182
|
-
commitUrl: url,
|
|
183
|
-
signal: owner.fetchAbort.signal,
|
|
184
|
-
skipHistory: effectiveSkipHistory,
|
|
185
|
-
departingUrl,
|
|
186
|
-
}),
|
|
187
|
-
options.onCommit
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
// Scroll-to-top on forward navigation, scroll to the #fragment target
|
|
191
|
-
// when the URL has one, or restore captured position for scroll={false}.
|
|
192
|
-
if (scroll && hash) {
|
|
193
|
-
scrollToHashAfterPaint(hash);
|
|
194
|
-
} else {
|
|
195
|
-
restoreScrollAfterPaint(scroll ? 0 : currentScrollY);
|
|
196
|
-
}
|
|
197
|
-
} catch (error) {
|
|
198
|
-
// `url` is where the user asked to go and `departingUrl` is where
|
|
199
|
-
// they were: a failure here finishes the click as a full document
|
|
200
|
-
// load of the destination, fragment included (TIM-1234). Reloading
|
|
201
|
-
// instead would rebuild the page they were *leaving* and discard
|
|
202
|
-
// the click (TIM-1275).
|
|
203
|
-
if (await recoverFromNavigationError(error, owner, url, departingUrl, types)) return;
|
|
204
|
-
throw error;
|
|
154
|
+
await runNavigation(url, async (owner) => {
|
|
155
|
+
try {
|
|
156
|
+
await renderViaTransition(
|
|
157
|
+
fetchUrl,
|
|
158
|
+
owner,
|
|
159
|
+
types,
|
|
160
|
+
() =>
|
|
161
|
+
performNavigationFetch(fetchUrl, {
|
|
162
|
+
replace,
|
|
163
|
+
commitUrl: url,
|
|
164
|
+
signal: owner.fetchAbort.signal,
|
|
165
|
+
departingUrl,
|
|
166
|
+
}),
|
|
167
|
+
options.onCommit
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
// Scroll-to-top on forward navigation, scroll to the #fragment target
|
|
171
|
+
// when the URL has one, or restore captured position for scroll={false}.
|
|
172
|
+
if (scroll && hash) {
|
|
173
|
+
scrollToHashAfterPaint(hash);
|
|
174
|
+
} else {
|
|
175
|
+
restoreScrollAfterPaint(scroll ? 0 : currentScrollY);
|
|
205
176
|
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
177
|
+
} catch (error) {
|
|
178
|
+
// `url` is where the user asked to go and `departingUrl` is where
|
|
179
|
+
// they were: a failure here finishes the click as a full document
|
|
180
|
+
// load of the destination, fragment included (TIM-1234). Reloading
|
|
181
|
+
// instead would rebuild the page they were *leaving* and discard
|
|
182
|
+
// the click (TIM-1275).
|
|
183
|
+
if (await recoverFromNavigationError(error, owner, url, departingUrl, types)) return;
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
209
187
|
}
|
|
210
188
|
|
|
211
189
|
/**
|
|
@@ -523,6 +501,8 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
523
501
|
return outcome === 'committed';
|
|
524
502
|
},
|
|
525
503
|
runWhenIdle: (task: () => void) => lifecycle.runWhenIdle(task),
|
|
504
|
+
onIdle: (listener) => lifecycle.onIdle(listener),
|
|
505
|
+
onTreeCommit: (listener) => lifecycle.onTreeCommit(listener),
|
|
526
506
|
settleHandoffs: () => lifecycle.settleHandoffs(),
|
|
527
507
|
suppressSegmentReuse(): void {
|
|
528
508
|
// TIM-1466: uses invalidateReuse() instead of clear() to preserve
|
package/src/plugins/shims.ts
CHANGED
package/src/rsc-runtime/rsc.ts
CHANGED
|
@@ -16,6 +16,9 @@ export {
|
|
|
16
16
|
loadServerAction,
|
|
17
17
|
decodeReply,
|
|
18
18
|
decodeAction,
|
|
19
|
+
// No-JS action result → the `useActionState` hook that submitted it
|
|
20
|
+
// (server/action-handler.ts), as Next.js does in its action handler.
|
|
21
|
+
decodeFormState,
|
|
19
22
|
encryptActionBoundArgs,
|
|
20
23
|
decryptActionBoundArgs,
|
|
21
24
|
// Flight client running INSIDE the RSC environment — decodes a cached
|
|
@@ -25,3 +25,17 @@ declare module '@vitejs/plugin-rsc/vendor/react-server-dom/server.edge' {
|
|
|
25
25
|
options?: { temporaryReferences?: unknown; arraySizeLimit?: number }
|
|
26
26
|
): Promise<unknown[]>;
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
// src decodes through plugin-rsc's wrappers; tests decode a Flight response
|
|
30
|
+
// with the vendored client directly, as the browser's createFromFetch does.
|
|
31
|
+
declare module '@vitejs/plugin-rsc/vendor/react-server-dom/client.edge' {
|
|
32
|
+
export function createFromReadableStream(
|
|
33
|
+
stream: ReadableStream<Uint8Array>,
|
|
34
|
+
options: {
|
|
35
|
+
serverConsumerManifest: unknown;
|
|
36
|
+
nonce?: string;
|
|
37
|
+
temporaryReferences?: unknown;
|
|
38
|
+
encodeFormAction?: unknown;
|
|
39
|
+
}
|
|
40
|
+
): PromiseLike<unknown>;
|
|
41
|
+
}
|
|
@@ -161,7 +161,8 @@ export interface ActionBuilderWithSchema<TCtx, TInput> {
|
|
|
161
161
|
/**
|
|
162
162
|
* The final action function. Callable three ways:
|
|
163
163
|
* - Direct: action(input) → Promise<ActionResult<TData>>
|
|
164
|
-
* - React useActionState: action(prevState,
|
|
164
|
+
* - React useActionState: action(prevState, payload) → Promise<ActionResult<TData>>,
|
|
165
|
+
* where payload is the submitted FormData or the value dispatch was called with
|
|
165
166
|
* - React <form action={fn}>: action(formData) → void (return value ignored by React)
|
|
166
167
|
*
|
|
167
168
|
* The third overload exists purely for type compatibility with React's
|
|
@@ -193,8 +194,11 @@ export type ActionFn<TData = unknown, TInput = unknown> = {
|
|
|
193
194
|
(
|
|
194
195
|
...args: undefined extends TInput ? [input?: TInput] : [input: TInput]
|
|
195
196
|
): Promise<ActionResult<TData>>;
|
|
196
|
-
/**
|
|
197
|
-
|
|
197
|
+
/**
|
|
198
|
+
* React useActionState: action(prevState, payload). The payload is the
|
|
199
|
+
* submitted FormData, or whatever the hook's dispatch was called with.
|
|
200
|
+
*/
|
|
201
|
+
(prevState: ActionResult<TData> | null, payload: TInput | FormData): Promise<ActionResult<TData>>;
|
|
198
202
|
};
|
|
199
203
|
|
|
200
204
|
// ─── Implementation ──────────────────────────────────────────────────────
|
|
@@ -281,8 +285,8 @@ function extractStandardSchemaErrors(issues: ReadonlyArray<StandardSchemaIssue>)
|
|
|
281
285
|
* Wrap unexpected errors into a safe server error result.
|
|
282
286
|
* ActionError → typed result. Other errors → INTERNAL_ERROR (no leak).
|
|
283
287
|
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
288
|
+
* `createActionClient` actions only. A raw `'use server'` function that
|
|
289
|
+
* throws is rejected on the client instead (action-handler.ts).
|
|
286
290
|
*/
|
|
287
291
|
export function handleActionError(error: unknown): ActionResult<never> {
|
|
288
292
|
if (error instanceof ActionError) {
|
|
@@ -339,21 +343,15 @@ export function createActionClient<TCtx = Record<string, never>>(
|
|
|
339
343
|
// Run middleware
|
|
340
344
|
const ctx = await runActionMiddleware(config.middleware);
|
|
341
345
|
|
|
342
|
-
//
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
// no additional args — so the bound FormData arrives as args[0].
|
|
352
|
-
rawInput = schema ? parseFormData(args[0]) : args[0];
|
|
353
|
-
} else {
|
|
354
|
-
// Direct call: action(input)
|
|
355
|
-
rawInput = args[0];
|
|
356
|
-
}
|
|
346
|
+
// The input is the last argument in every call shape: `(input)`,
|
|
347
|
+
// `(formData)`, `(prevState, payload)` from useActionState's
|
|
348
|
+
// dispatch, `(initialState, formData)` on the no-JS path (Fizz binds
|
|
349
|
+
// the initial state into the form, and decodeAction binds the
|
|
350
|
+
// FormData after it), and `(...bound, prevState, payload)` for an
|
|
351
|
+
// action with bound arguments. Nothing before it is input:
|
|
352
|
+
// `prevState` comes from the client, so it is never read.
|
|
353
|
+
const last = args.at(-1);
|
|
354
|
+
const rawInput: unknown = schema && last instanceof FormData ? parseFormData(last) : last;
|
|
357
355
|
|
|
358
356
|
// Resolve the sensitive-field stripping predicate once per invocation.
|
|
359
357
|
// Precedence: per-action (config.stripSensitiveFields) > global
|