@rsc-kit/core 0.20.7 → 0.20.8
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/dist/cache.d.ts +11 -0
- package/dist/cache.js +13 -0
- package/dist/cache.js.map +1 -1
- package/dist/clientEntries.js +4 -1
- package/dist/clientEntries.js.map +1 -1
- package/dist/files.d.ts +38 -0
- package/dist/files.js +109 -0
- package/dist/files.js.map +1 -1
- package/dist/host.d.ts +11 -2
- package/dist/host.js +37 -6
- package/dist/host.js.map +1 -1
- package/dist/js/ActivityRouter.d.ts +11 -0
- package/dist/js/ActivityRouter.js +19 -4
- package/dist/js/ActivityRouter.js.map +1 -1
- package/dist/js/Form.js +24 -2
- package/dist/js/Form.js.map +1 -1
- package/dist/js/PathnameProvider.d.ts +15 -2
- package/dist/js/PathnameProvider.js +17 -2
- package/dist/js/PathnameProvider.js.map +1 -1
- package/dist/js/SegmentBoundary.js +19 -3
- package/dist/js/SegmentBoundary.js.map +1 -1
- package/dist/js/activityMarkers.d.ts +7 -0
- package/dist/js/activityMarkers.js +18 -0
- package/dist/js/activityMarkers.js.map +1 -0
- package/dist/js/createViteRscApp.js +122 -76
- package/dist/js/createViteRscApp.js.map +1 -1
- package/dist/js/earlyClicks.d.ts +3 -1
- package/dist/js/earlyClicks.js +28 -5
- package/dist/js/earlyClicks.js.map +1 -1
- package/dist/js/errors.d.ts +2 -0
- package/dist/js/errors.js +11 -0
- package/dist/js/errors.js.map +1 -1
- package/dist/js/imagePreload.d.ts +37 -0
- package/dist/js/imagePreload.js +116 -0
- package/dist/js/imagePreload.js.map +1 -0
- package/dist/js/navigate.d.ts +33 -0
- package/dist/js/navigate.js +200 -12
- package/dist/js/navigate.js.map +1 -1
- package/dist/js/segmentStore.d.ts +52 -0
- package/dist/js/segmentStore.js +123 -2
- package/dist/js/segmentStore.js.map +1 -1
- package/dist/js/staleAssets.d.ts +10 -0
- package/dist/js/staleAssets.js +23 -2
- package/dist/js/staleAssets.js.map +1 -1
- package/dist/js/viewportPrefetch.js +27 -2
- package/dist/js/viewportPrefetch.js.map +1 -1
- package/dist/shellHead.d.ts +22 -0
- package/dist/shellHead.js +43 -0
- package/dist/shellHead.js.map +1 -0
- package/dist/vite.js +237 -55
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many <Activity> boundaries the server put in this document.
|
|
3
|
+
*
|
|
4
|
+
* React marks each with a comment, <!--&--> to <!--/&-->; the opening ones
|
|
5
|
+
* are counted.
|
|
6
|
+
*/
|
|
7
|
+
export function activityMarkersIn(container) {
|
|
8
|
+
if (typeof document === "undefined" || typeof document.createTreeWalker !== "function")
|
|
9
|
+
return 1;
|
|
10
|
+
const walker = document.createTreeWalker(container, 128 /* NodeFilter.SHOW_COMMENT */);
|
|
11
|
+
let count = 0;
|
|
12
|
+
while (walker.nextNode()) {
|
|
13
|
+
if (walker.currentNode.data === "&")
|
|
14
|
+
count++;
|
|
15
|
+
}
|
|
16
|
+
return count;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=activityMarkers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activityMarkers.js","sourceRoot":"","sources":["../../src/js/activityMarkers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAA6B;IAC7D,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,QAAQ,CAAC,gBAAgB,KAAK,UAAU;QAAE,OAAO,CAAC,CAAC;IAEjG,MAAM,MAAM,GAAG,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,GAAG,CAAC,6BAA6B,CAAC,CAAC;IACvF,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,OAAO,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;QACzB,IAAK,MAAM,CAAC,WAAuB,CAAC,IAAI,KAAK,GAAG;YAAE,KAAK,EAAE,CAAC;IAC5D,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * How many <Activity> boundaries the server put in this document.\n *\n * React marks each with a comment, <!--&--> to <!--/&-->; the opening ones\n * are counted.\n */\nexport function activityMarkersIn(container: Element | Document): number {\n if (typeof document === \"undefined\" || typeof document.createTreeWalker !== \"function\") return 1;\n\n const walker = document.createTreeWalker(container, 128 /* NodeFilter.SHOW_COMMENT */);\n let count = 0;\n\n while (walker.nextNode()) {\n if ((walker.currentNode as Comment).data === \"&\") count++;\n }\n\n return count;\n}\n"]}
|
|
@@ -12,14 +12,15 @@ import { caughtByLoading } from "./fallbackReport";
|
|
|
12
12
|
import { noteNavigation } from "./segmentStore";
|
|
13
13
|
import { isSafeRedirect } from "../safeUrl.js";
|
|
14
14
|
import { createFromReadableStream, encodeReply, setServerCallback, } from "@vitejs/plugin-rsc/browser";
|
|
15
|
-
import { createElement } from "react";
|
|
16
|
-
import { hydrateRoot } from "react-dom/client";
|
|
15
|
+
import { createElement, startTransition } from "react";
|
|
16
|
+
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
17
|
+
import { activityMarkersIn } from "./activityMarkers";
|
|
17
18
|
import { ActivityRoot } from "./ActivityRouter";
|
|
18
19
|
import { ServerRedirectError, noteRedirected, throwForFailedAction } from "./errors";
|
|
19
20
|
import { fetchPagePayload } from "./pagePayload";
|
|
20
21
|
import { claimRead, setQueryCodec } from "./queryClient";
|
|
21
|
-
import { clearSegments, restoreSegments, setSegment } from "./segmentStore";
|
|
22
|
-
import { cancelPrefetch, isPrefetched, navigate, setApiRoutes, refresh,
|
|
22
|
+
import { clearSegments, dropHidden, isHeld, prerenderSegment, restoreSegments, setSegment } from "./segmentStore";
|
|
23
|
+
import { cancelPrefetch, isPrefetched, navigate, setApiRoutes, refresh, applyRevalidations, prefetch, retentionKey, setCallServer, setHeldLayouts, setStaticPayloads, setStaticRoutes, seedStaticChain, payloadUrl, setDeserializer, setInterceptManifest, getHeldLayouts, setNavigateHandler, setHeldHandlers, setPrerenderHandler, setReplaceRootHandler, setRestoreHandler, setVersion, } from "./navigate";
|
|
23
24
|
/**
|
|
24
25
|
* A redirect that travelled as an error: the digest of the error itself, or
|
|
25
26
|
* of the cause React wraps it in when it reports client-rendering a boundary
|
|
@@ -72,15 +73,17 @@ export async function createViteRscApp(container = document, interceptEntries =
|
|
|
72
73
|
body = encoded;
|
|
73
74
|
realContentType = "text/plain;charset=UTF-8";
|
|
74
75
|
}
|
|
76
|
+
// Where the action was invoked from. The host resolves it to the
|
|
77
|
+
// components that render the page, so anything the action says it
|
|
78
|
+
// invalidated can come back with the answer instead of being fetched
|
|
79
|
+
// afterwards - and what comes back is for this page, not whichever is
|
|
80
|
+
// showing when it lands.
|
|
81
|
+
const from = window.location.pathname + window.location.search;
|
|
75
82
|
const res = await fetch("/_rsc/action", {
|
|
76
83
|
method: "POST",
|
|
77
84
|
headers: {
|
|
78
85
|
"X-RSC-Action": id,
|
|
79
|
-
|
|
80
|
-
// components that render the page, so anything the action says it
|
|
81
|
-
// invalidated can come back with the answer instead of being fetched
|
|
82
|
-
// afterwards.
|
|
83
|
-
"X-RSC-Referer": window.location.pathname + window.location.search,
|
|
86
|
+
"X-RSC-Referer": from,
|
|
84
87
|
"X-RSC-Content-Type": realContentType,
|
|
85
88
|
"Content-Type": "application/octet-stream",
|
|
86
89
|
"X-XSRF-TOKEN": decodeURIComponent(document.cookie.match(/XSRF-TOKEN=([^;]+)/)?.[1] ?? ""),
|
|
@@ -120,7 +123,7 @@ export async function createViteRscApp(container = document, interceptEntries =
|
|
|
120
123
|
throw err;
|
|
121
124
|
}
|
|
122
125
|
const answer = await createFromReadableStream(res.body, { callServer });
|
|
123
|
-
return unwrapRevalidated(answer);
|
|
126
|
+
return unwrapRevalidated(answer, from);
|
|
124
127
|
}
|
|
125
128
|
/**
|
|
126
129
|
* Put anything the action re-rendered on screen, and hand back its result.
|
|
@@ -129,16 +132,14 @@ export async function createViteRscApp(container = document, interceptEntries =
|
|
|
129
132
|
* the caller sees only what its action returned and never knows the page
|
|
130
133
|
* was updated around it.
|
|
131
134
|
*/
|
|
132
|
-
function unwrapRevalidated(answer) {
|
|
135
|
+
function unwrapRevalidated(answer, from) {
|
|
133
136
|
if (answer === null ||
|
|
134
137
|
typeof answer !== "object" ||
|
|
135
138
|
!("__rscRevalidated" in answer)) {
|
|
136
139
|
return answer;
|
|
137
140
|
}
|
|
138
141
|
const envelope = answer;
|
|
139
|
-
|
|
140
|
-
applyRevalidated(target, tree);
|
|
141
|
-
}
|
|
142
|
+
applyRevalidations(from, envelope.__rscRevalidated);
|
|
142
143
|
return envelope.result;
|
|
143
144
|
}
|
|
144
145
|
setDeserializer(createFromReadableStream);
|
|
@@ -215,68 +216,90 @@ export async function createViteRscApp(container = document, interceptEntries =
|
|
|
215
216
|
initialTree: tree,
|
|
216
217
|
})
|
|
217
218
|
: tree;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
219
|
+
// A document that cannot be hydrated by this tree is client-rendered
|
|
220
|
+
// instead - a repaint, not a freeze. React 19.2 does not recover from a
|
|
221
|
+
// hydration mismatch at an <Activity>: it retries hydrating the boundary,
|
|
222
|
+
// mismatches again, and never returns to the main thread. Every segment
|
|
223
|
+
// boundary is an Activity, one per layout, so a document with none where
|
|
224
|
+
// the page has layouts is that mismatch, guaranteed, before React starts.
|
|
225
|
+
// What produced one: a parameterised route's PPR shell, rendered without
|
|
226
|
+
// a page key and, by a build before this one, without the Activities too.
|
|
227
|
+
// None rather than fewer: a boundary inside a Suspense hole the shell left
|
|
228
|
+
// unfinished has no marker and is client-rendered by React on its own,
|
|
229
|
+
// which is not a mismatch. The stale-asset reload does not apply - the
|
|
230
|
+
// document would come back the same.
|
|
231
|
+
const missing = retains && getHeldLayouts().length > 0 && activityMarkersIn(container) === 0;
|
|
232
|
+
if (missing) {
|
|
233
|
+
console.warn("[rsc-kit] The document has no <Activity> boundaries where the page has layouts, so it cannot be hydrated; rendering the page instead. A PPR shell built by an earlier release lacks them - rebuild.");
|
|
234
|
+
}
|
|
235
|
+
// The payload answered with an error status - the not-found page for a
|
|
236
|
+
// url the shell was served for anyway. It is not the document on screen,
|
|
237
|
+
// so it is rendered, not hydrated: a mismatch at an Activity is the loop
|
|
238
|
+
// above, and this one is certain.
|
|
239
|
+
const disagrees = !res.ok;
|
|
240
|
+
const onRecoverableError = (error, errorInfo) => {
|
|
241
|
+
// A client component whose chunk the server no longer has fails while
|
|
242
|
+
// hydrating, and React reports that as recoverable: the page is loaded
|
|
243
|
+
// again, with the current names.
|
|
244
|
+
if (recoverFromStaleAssets(error))
|
|
245
|
+
return;
|
|
246
|
+
// A redirect decided inside a boundary: the server's row carried it as
|
|
247
|
+
// the digest, React client-renders the boundary and reports that it
|
|
248
|
+
// did, and the RedirectBoundary is already performing it. Nothing to
|
|
249
|
+
// read in the console about a page doing what it was told.
|
|
250
|
+
if (isRedirect(error))
|
|
251
|
+
return;
|
|
252
|
+
// A PPR shell is served with its Suspense boundaries deliberately
|
|
253
|
+
// unfinished — the build aborts the render once the static part is out.
|
|
254
|
+
// React reports that as #419 and client-renders the boundary from the
|
|
255
|
+
// Flight payload, which is the intended path, not a fault to report.
|
|
256
|
+
const message = String(error?.message ?? error);
|
|
257
|
+
if (message.includes("419") ||
|
|
258
|
+
message.includes("did not finish this Suspense boundary")) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
// A view transition the browser cancelled because the tab was not
|
|
262
|
+
// visible. React reports it here; the update still landed, and a tab
|
|
263
|
+
// in the background is not a fault in the page.
|
|
264
|
+
if (message.includes("Transition was aborted"))
|
|
265
|
+
return;
|
|
266
|
+
// A navigation another one overtook: its request was aborted, and a
|
|
267
|
+
// row of its payload that a component was still reading rejects with
|
|
268
|
+
// the abort. React recovers by rendering the root again synchronously
|
|
269
|
+
// and reports the recovery here as #520, with the abort as the cause.
|
|
270
|
+
// The page it recovered to is the one the second navigation asked for;
|
|
271
|
+
// the abort was the design, not a fault.
|
|
272
|
+
const cause = error?.cause;
|
|
273
|
+
if (cause?.name === "AbortError" ||
|
|
274
|
+
/\baborted\b/i.test(cause?.message ?? "") ||
|
|
275
|
+
/\baborted\b/i.test(message)) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
// A page whose query string was read under a boundary carries the
|
|
279
|
+
// fallback there; React reports the recovery on hydration. Under a
|
|
280
|
+
// boundary the developer wrote, that is the designed path and nothing
|
|
281
|
+
// is said. With nothing closer than a loading.tsx, the whole segment
|
|
282
|
+
// showed the fallback until the query arrived - said here, in the
|
|
283
|
+
// page and the console, for whoever is looking at either. Production
|
|
284
|
+
// has no stack to tell the two apart; the build's note on the route is
|
|
285
|
+
// the record there.
|
|
286
|
+
if (error?.digest === SEARCH_PARAMS_FALLBACK ||
|
|
287
|
+
message.includes("useSearchParams()")) {
|
|
288
|
+
const stack = errorInfo
|
|
289
|
+
?.componentStack;
|
|
290
|
+
if (!caughtByLoading(stack))
|
|
276
291
|
return;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
292
|
+
const hint = "useSearchParams() was read on the server with nothing closer than a loading.tsx, so the " +
|
|
293
|
+
"whole segment showed that fallback until the query arrived. A <Suspense> around the " +
|
|
294
|
+
"component that reads keeps the rest of the page painted.";
|
|
295
|
+
showDevNotice(hint, stack);
|
|
296
|
+
console.error(new Error(hint), errorInfo);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
console.error(error, errorInfo);
|
|
300
|
+
};
|
|
301
|
+
const rootOptions = {
|
|
302
|
+
onRecoverableError,
|
|
280
303
|
// A chunk the deploy no longer serves is not a fault in the page; the
|
|
281
304
|
// document is loaded again, and the new names come with it. Anything
|
|
282
305
|
// else is reported the way React would have.
|
|
@@ -293,7 +316,14 @@ export async function createViteRscApp(container = document, interceptEntries =
|
|
|
293
316
|
return;
|
|
294
317
|
console.error(error, errorInfo);
|
|
295
318
|
},
|
|
296
|
-
}
|
|
319
|
+
};
|
|
320
|
+
const root = missing || disagrees
|
|
321
|
+
? (() => {
|
|
322
|
+
const created = createRoot(container, rootOptions);
|
|
323
|
+
created.render(shell);
|
|
324
|
+
return created;
|
|
325
|
+
})()
|
|
326
|
+
: hydrateRoot(container, shell, rootOptions);
|
|
297
327
|
// Depth 0 is a whole document and replaces the root. Anything deeper is one
|
|
298
328
|
// segment: handing it to the boundary at that depth leaves the layouts above
|
|
299
329
|
// it mounted, which is the point of asking for a partial render at all.
|
|
@@ -308,9 +338,25 @@ export async function createViteRscApp(container = document, interceptEntries =
|
|
|
308
338
|
clearSegments();
|
|
309
339
|
root.render(newTree);
|
|
310
340
|
});
|
|
341
|
+
// The whole document again, in place - revalidate("all"). Not through the
|
|
342
|
+
// handler above: that clears the boundaries and renders the tree as a new
|
|
343
|
+
// page, and a boundary emptied re-keys its Activity to the current url and
|
|
344
|
+
// remounts everything under it. A port's "added to cart" went with the
|
|
345
|
+
// form's state that way, on every product reached by a link. Here the root
|
|
346
|
+
// takes the tree in a transition and each boundary hands its page the new
|
|
347
|
+
// children under the key it has - see replaceActive.
|
|
348
|
+
setReplaceRootHandler((tree) => {
|
|
349
|
+
startTransition(() => root.render(tree));
|
|
350
|
+
});
|
|
311
351
|
// Back and forward reveal a page the boundaries are still holding, with the
|
|
312
352
|
// form you were filling in still filled in, and without asking the server.
|
|
313
353
|
setRestoreHandler((key, maxAge) => restoreSegments(key, maxAge));
|
|
354
|
+
setHeldHandlers(isHeld, dropHidden);
|
|
355
|
+
// A touch or a settled hover: the page is rendered hidden now, and the
|
|
356
|
+
// click reveals it. See warm() in navigate.ts and prerenderSegment.
|
|
357
|
+
setPrerenderHandler((tree, key, segmentDepth) => {
|
|
358
|
+
prerenderSegment(segmentDepth, key, tree);
|
|
359
|
+
});
|
|
314
360
|
window.addEventListener("popstate", () => {
|
|
315
361
|
// restore: back and forward reveal the page you were on, with its state.
|
|
316
362
|
// Wherever the browser just went; not a literal this app wrote.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createViteRscApp.js","sourceRoot":"","sources":["../../src/js/createViteRscApp.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,qFAAqF;AACrF,8EAA8E;AAC9E,4EAA4E;AAC5E,qCAAqC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;A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E,YAAoB,EAAE,EAAE;QACtE,MAAM,OAAO,GAAG,IAAiB,CAAC;QAElC,2EAA2E;QAC3E,cAAc,EAAE,CAAC;QAEjB,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YACrB,UAAU,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;YAEvC,OAAO;QACT,CAAC;QAED,aAAa,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,4EAA4E;IAC5E,2EAA2E;IAC3E,iBAAiB,CAAC,CAAC,GAAW,EAAE,MAAe,EAAE,EAAE,CACjD,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAC7B,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,GAAG,EAAE;QACvC,yEAAyE;QACzE,gEAAgE;QAChE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,YAAY,CAClB,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAChC,EAAE,EACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CACrB,CAAC;IAEF,sEAAsE;IACtE,sEAAsE;IACtE,sEAAsE;IACtE,mEAAmE;IACnE,cAAc,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAY,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["// Vite-engine client bootstrap. Uses @vitejs/plugin-rsc's browser runtime as\n// the Flight deserializer + action encoder, and drives the package's engine-agnostic\n// navigate.ts SPA engine (Link, prefetch, popstate) through it. This replaces\n// the bun engine's createRscApp + the hand-rolled webpack shim — the plugin\n// resolves client references itself.\nimport { SEARCH_PARAMS_FALLBACK } from \"./useSearchParams\";\nimport { recoverFromStaleAssets } from \"./staleAssets\";\nimport { afterHydration, replayEarlyClicks } from \"./earlyClicks\";\nimport { parseRedirectDigest } from \"../redirectDigest.js\";\nimport { showDevNotice } from \"./devNotice\";\nimport { caughtByLoading } from \"./fallbackReport\";\nimport { noteNavigation } from \"./segmentStore\";\nimport type { Route } from \"../routes.js\";\nimport { isSafeRedirect } from \"../safeUrl.js\";\nimport {\n createFromReadableStream,\n encodeReply,\n setServerCallback,\n} from \"@vitejs/plugin-rsc/browser\";\nimport { createElement } from \"react\";\nimport { hydrateRoot } from \"react-dom/client\";\nimport { ActivityRoot } from \"./ActivityRouter\";\nimport { ServerRedirectError, noteRedirected, throwForFailedAction } from \"./errors\";\nimport { fetchPagePayload } from \"./pagePayload\";\nimport { claimRead, setQueryCodec } from \"./queryClient\";\nimport { clearSegments, restoreSegments, setSegment } from \"./segmentStore\";\nimport type { ReactNode } from \"react\";\nimport {\n cancelPrefetch,\n isPrefetched,\n navigate,\n setApiRoutes,\n refresh,\n applyRevalidated,\n prefetch,\n retentionKey,\n setCallServer,\n setHeldLayouts,\n setStaticPayloads,\n setStaticRoutes,\n seedStaticChain,\n payloadUrl,\n setDeserializer,\n setInterceptManifest,\n setNavigateHandler,\n setRestoreHandler,\n setVersion,\n} from \"./navigate\";\n\n\n/**\n * A redirect that travelled as an error: the digest of the error itself, or\n * of the cause React wraps it in when it reports client-rendering a boundary\n * the server had already failed.\n */\nfunction isRedirect(error: unknown): boolean {\n const digest = (error as { digest?: unknown } | null)?.digest;\n const cause = (error as { cause?: { digest?: unknown } } | null)?.cause;\n\n return parseRedirectDigest(digest) !== null || parseRedirectDigest(cause?.digest) !== null;\n}\n\nexport async function createViteRscApp(\n container: Document | Element = document,\n interceptEntries: { urlPattern: string; slot: string }[] = [],\n options: { staticPayloads?: string | null; routes?: unknown[] | null; apiRoutes?: string[] } = {},\n): Promise<void> {\n // The urls a route.ts answers: a link to one is an anchor, never a\n // prefetch, never a payload fetch.\n if (options.apiRoutes) setApiRoutes(options.apiRoutes);\n // An exported build has no server to negotiate with, so payloads live at\n // their own urls rather than behind a header on the page's url.\n setStaticPayloads(options.staticPayloads ?? null);\n // Only an exported build ships this: with no server to negotiate with, the\n // client works out for itself how much of a page it still holds.\n if (options.routes) setStaticRoutes(options.routes as never);\n // The router has to recognise an intercepted link before it asks the server,\n // so the patterns are baked into the generated browser entry. Without them\n // every intercepted route falls through to a full-page navigation.\n setInterceptManifest(interceptEntries);\n\n async function callServer(id: string, args: unknown[]): Promise<unknown> {\n // A read opened a slot before calling the reference, and this is the first\n // point at which the id exists on the client — React keeps it private and\n // hands it over only here. Claiming the slot enqueues the read for the\n // batched GET instead of posting it.\n const read = claimRead(id, args);\n\n if (read) return await read;\n\n const encoded = await encodeReply(args);\n\n // encodeReply returns FormData as soon as an argument contains a File.\n // Sending that as multipart would make PHP consume php://input while\n // parsing it, leaving the action with an empty body — so serialize it to\n // raw bytes under an opaque content-type and send the real one in\n // X-RSC-Content-Type for the worker to rebuild FormData from.\n let body: BodyInit;\n let realContentType: string;\n\n if (encoded instanceof FormData) {\n const serialized = new Response(encoded);\n body = await serialized.arrayBuffer();\n realContentType =\n serialized.headers.get(\"content-type\") ?? \"multipart/form-data\";\n } else {\n body = encoded as BodyInit;\n realContentType = \"text/plain;charset=UTF-8\";\n }\n\n const res = await fetch(\"/_rsc/action\", {\n method: \"POST\",\n headers: {\n \"X-RSC-Action\": id,\n // Where the action was invoked from. The host resolves it to the\n // components that render the page, so anything the action says it\n // invalidated can come back with the answer instead of being fetched\n // afterwards.\n \"X-RSC-Referer\": window.location.pathname + window.location.search,\n \"X-RSC-Content-Type\": realContentType,\n \"Content-Type\": \"application/octet-stream\",\n \"X-XSRF-TOKEN\": decodeURIComponent(\n document.cookie.match(/XSRF-TOKEN=([^;]+)/)?.[1] ?? \"\",\n ),\n },\n body,\n });\n\n // A failed action does not answer with a Flight stream, and the decoder\n // cannot tell — it reports its own parse failure instead of what the\n // server said.\n try {\n await throwForFailedAction(res);\n } catch (err) {\n // A redirect is an instruction, not something for a form to display:\n // an expired session answers this way, and the destination is the login\n // page rather than a message about one.\n if (err instanceof ServerRedirectError) {\n // The destination came off a response header, so it is checked here\n // too — the engine refuses these at the source, but a proxy or a host\n // in front of it can write whatever it likes. A navigation, not a\n // document load: the layouts stay mounted and the history entry the\n // form was on is replaced, the way a redirect after a POST should\n // be - Back does not return to the submitted form.\n if (isSafeRedirect(err.location)) {\n void navigate(err.location as Route, { replace: true });\n }\n\n // Performed, so resolved - not thrown. The call's answer is \"you are\n // being taken somewhere\": an object saying so, the shape an action's\n // result already has, so a caller reading result.validationErrors\n // reads undefined rather than throwing. A caller that awaited the\n // action in a plain startTransition had no catch for a throw, the\n // rejection reached React, and the root unmounted to a white page\n // on every logout.\n noteRedirected(err.location);\n\n return { redirected: err.location };\n }\n\n throw err;\n }\n\n const answer = await createFromReadableStream(res.body!, { callServer });\n\n return unwrapRevalidated(answer);\n }\n\n /**\n * Put anything the action re-rendered on screen, and hand back its result.\n *\n * The trees travel with the answer rather than being fetched afterwards, so\n * the caller sees only what its action returned and never knows the page\n * was updated around it.\n */\n function unwrapRevalidated(answer: unknown): unknown {\n if (\n answer === null ||\n typeof answer !== \"object\" ||\n !(\"__rscRevalidated\" in answer)\n ) {\n return answer;\n }\n\n const envelope = answer as {\n __rscRevalidated: Record<string, unknown>;\n result: unknown;\n };\n\n for (const [target, tree] of Object.entries(envelope.__rscRevalidated)) {\n applyRevalidated(target, tree);\n }\n\n return envelope.result;\n }\n\n setDeserializer(createFromReadableStream as never);\n // The query transport speaks Flight too, and reaches the runtime through here\n // rather than importing it: a second import of the browser runtime from the\n // client-component graph is a second client-reference registry, and the\n // symptom is components that render as undefined with nothing logged.\n setQueryCodec({\n deserialize: (stream) =>\n createFromReadableStream(stream, { callServer }) as Promise<unknown>,\n encode: (args) => encodeReply(args) as Promise<string | FormData>,\n // The way back when a read cannot ride in a url. Re-entering callServer is\n // safe: the slot was cleared the moment the reference returned, so this\n // takes the ordinary POST path rather than claiming a read again.\n asAction: (id, args) => callServer(id, args),\n });\n setCallServer(callServer);\n // The plugin's own \"use server\" client stubs route through its registered\n // server callback — register the same transport there too.\n setServerCallback(callServer as never);\n\n // Link / Form / router live in a separate build graph and reach the SPA\n // engine through these globals.\n (window as unknown as { __rsc_navigate: typeof navigate }).__rsc_navigate =\n navigate;\n (window as unknown as { __rsc_prefetch: typeof prefetch }).__rsc_prefetch =\n prefetch;\n (\n window as unknown as { __rsc_cancel_prefetch: typeof cancelPrefetch }\n ).__rsc_cancel_prefetch = cancelPrefetch;\n (\n window as unknown as { __rsc_is_prefetched: typeof isPrefetched }\n ).__rsc_is_prefetched = isPrefetched;\n (window as unknown as { __rsc_refresh: typeof refresh }).__rsc_refresh =\n refresh;\n\n // Hydrate from the RSC endpoint (same url + X-RSC, no version header).\n //\n // Everything from here to the decode is failure handling, because this is\n // the one request with nothing watching it. A page whose shell is already\n // rendered looks fine while this fails, and its fallbacks stay on screen\n // indefinitely with nothing reported anywhere.\n const res = await fetchPagePayload(payloadUrl(window.location.href));\n\n // Seed the router with the build this DOCUMENT is, so a redeploy is caught\n // on the next navigation: the host answers 409 to a client of another\n // build, and the document is loaded again. From the document's own meta\n // first - a document a service worker served from its cache is the last\n // build's, while the payload just fetched is this one's, and seeding from\n // the payload would have the old client claim to be new. The header is\n // the fallback for a document with no meta.\n const documentBuild = document.querySelector('meta[name=\"rsc-kit:build\"]')?.getAttribute(\"content\");\n const servedVersion = documentBuild || res.headers.get(\"X-RSC-Version\");\n\n if (servedVersion) {\n setVersion(servedVersion);\n }\n\n // The chain this page is built from, so the next navigation can say what is\n // already mounted and be sent only what changed.\n // A server says what this page is built from; a file server says nothing,\n // so an exported build works it out from the table it was given.\n const servedLayouts = res.headers.get(\"X-RSC-Layouts\");\n\n if (servedLayouts !== null) {\n setHeldLayouts(servedLayouts.split(\",\"));\n } else if (!seedStaticChain(window.location.href)) {\n setHeldLayouts([]);\n }\n const tree = await createFromReadableStream(res.body!, { callServer });\n\n // Retaining the previous page behind <Activity> needs a wrapper above the\n // page, and React will not hydrate a *document* container through one: the\n // root child of a document has to be <html>, and wrapping it hangs the\n // renderer outright (React 19.2.7). An app whose root layout owns <html>\n // therefore hydrates the tree directly and navigations replace it, as before.\n //\n // Apps that hydrate into an element get retention. Giving it to document-\n // rooted apps means SPA navigation returning only the changed segment rather\n // than a whole document, which is an engine change, not a client one.\n const retains = container !== document;\n\n const shell = retains\n ? createElement(ActivityRoot, {\n initialKey: retentionKey(window.location.href, null),\n initialTree: tree as ReactNode,\n })\n : (tree as ReactNode);\n\n const root = hydrateRoot(container, shell, {\n onRecoverableError(error: unknown, errorInfo: unknown) {\n // A client component whose chunk the server no longer has fails while\n // hydrating, and React reports that as recoverable: the page is loaded\n // again, with the current names.\n if (recoverFromStaleAssets(error)) return;\n\n // A redirect decided inside a boundary: the server's row carried it as\n // the digest, React client-renders the boundary and reports that it\n // did, and the RedirectBoundary is already performing it. Nothing to\n // read in the console about a page doing what it was told.\n if (isRedirect(error)) return;\n\n // A PPR shell is served with its Suspense boundaries deliberately\n // unfinished — the build aborts the render once the static part is out.\n // React reports that as #419 and client-renders the boundary from the\n // Flight payload, which is the intended path, not a fault to report.\n const message = String((error as { message?: string })?.message ?? error);\n\n if (\n message.includes(\"419\") ||\n message.includes(\"did not finish this Suspense boundary\")\n ) {\n return;\n }\n\n // A view transition the browser cancelled because the tab was not\n // visible. React reports it here; the update still landed, and a tab\n // in the background is not a fault in the page.\n if (message.includes(\"Transition was aborted\")) return;\n\n // A navigation another one overtook: its request was aborted, and a\n // row of its payload that a component was still reading rejects with\n // the abort. React recovers by rendering the root again synchronously\n // and reports the recovery here as #520, with the abort as the cause.\n // The page it recovered to is the one the second navigation asked for;\n // the abort was the design, not a fault.\n const cause = (error as { cause?: { name?: string; message?: string } } | null)?.cause;\n\n if (\n cause?.name === \"AbortError\" ||\n /\\baborted\\b/i.test(cause?.message ?? \"\") ||\n /\\baborted\\b/i.test(message)\n ) {\n return;\n }\n // A page whose query string was read under a boundary carries the\n // fallback there; React reports the recovery on hydration. Under a\n // boundary the developer wrote, that is the designed path and nothing\n // is said. With nothing closer than a loading.tsx, the whole segment\n // showed the fallback until the query arrived - said here, in the\n // page and the console, for whoever is looking at either. Production\n // has no stack to tell the two apart; the build's note on the route is\n // the record there.\n if (\n (error as { digest?: string })?.digest === SEARCH_PARAMS_FALLBACK ||\n message.includes(\"useSearchParams()\")\n ) {\n const stack = (errorInfo as { componentStack?: string } | null)\n ?.componentStack;\n\n if (!caughtByLoading(stack)) return;\n\n const hint =\n \"useSearchParams() was read on the server with nothing closer than a loading.tsx, so the \" +\n \"whole segment showed that fallback until the query arrived. A <Suspense> around the \" +\n \"component that reads keeps the rest of the page painted.\";\n\n showDevNotice(hint, stack);\n console.error(new Error(hint), errorInfo);\n\n return;\n }\n\n console.error(error, errorInfo);\n },\n // A chunk the deploy no longer serves is not a fault in the page; the\n // document is loaded again, and the new names come with it. Anything\n // else is reported the way React would have.\n onUncaughtError(error: unknown, errorInfo: unknown) {\n if (recoverFromStaleAssets(error)) return;\n\n console.error(error, errorInfo);\n },\n onCaughtError(error: unknown, errorInfo: unknown) {\n if (recoverFromStaleAssets(error)) return;\n // Caught by the RedirectBoundary, which is performing it.\n if (isRedirect(error)) return;\n\n console.error(error, errorInfo);\n },\n });\n\n // Depth 0 is a whole document and replaces the root. Anything deeper is one\n // segment: handing it to the boundary at that depth leaves the layouts above\n // it mounted, which is the point of asking for a partial render at all.\n setNavigateHandler((tree: unknown, key: string, segmentDepth: number) => {\n const newTree = tree as ReactNode;\n\n // From here on the boundary animates; the seed commit before this did not.\n noteNavigation();\n\n if (segmentDepth > 0) {\n setSegment(segmentDepth, key, newTree);\n\n return;\n }\n\n clearSegments();\n root.render(newTree);\n });\n\n // Back and forward reveal a page the boundaries are still holding, with the\n // form you were filling in still filled in, and without asking the server.\n setRestoreHandler((key: string, maxAge?: number) =>\n restoreSegments(key, maxAge),\n );\n\n window.addEventListener(\"popstate\", () => {\n // restore: back and forward reveal the page you were on, with its state.\n // Wherever the browser just went; not a literal this app wrote.\n navigate(window.location.href as Route, { replace: true, restore: true });\n });\n\n history.replaceState(\n { rscUrl: window.location.href },\n \"\",\n window.location.href,\n );\n\n // A tap held by the bootstrap script, navigated to once hydration has\n // committed - not now: the runtime's script running is seconds before\n // React can dispatch a click on a phone still downloading chunks, and\n // a tap in that window would be the browser's. See earlyClicks.ts.\n afterHydration(() => replayEarlyClicks((url) => navigate(url as Route)));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"createViteRscApp.js","sourceRoot":"","sources":["../../src/js/createViteRscApp.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,qFAAqF;AACrF,8EAA8E;AAC9E,4EAA4E;AAC5E,qCAAqC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,wBAAwB,EACxB,WAAW,EACX,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAk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AA4E;IAC5E,2EAA2E;IAC3E,iBAAiB,CAAC,CAAC,GAAW,EAAE,MAAe,EAAE,EAAE,CACjD,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAC7B,CAAC;IACF,eAAe,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAEpC,uEAAuE;IACvE,oEAAoE;IACpE,mBAAmB,CAAC,CAAC,IAAa,EAAE,GAAW,EAAE,YAAoB,EAAE,EAAE;QACvE,gBAAgB,CAAC,YAAY,EAAE,GAAG,EAAE,IAAiB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,GAAG,EAAE;QACvC,yEAAyE;QACzE,gEAAgE;QAChE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,YAAY,CAClB,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAChC,EAAE,EACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CACrB,CAAC;IAEF,sEAAsE;IACtE,sEAAsE;IACtE,sEAAsE;IACtE,mEAAmE;IACnE,cAAc,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAY,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["// Vite-engine client bootstrap. Uses @vitejs/plugin-rsc's browser runtime as\n// the Flight deserializer + action encoder, and drives the package's engine-agnostic\n// navigate.ts SPA engine (Link, prefetch, popstate) through it. This replaces\n// the bun engine's createRscApp + the hand-rolled webpack shim — the plugin\n// resolves client references itself.\nimport { SEARCH_PARAMS_FALLBACK } from \"./useSearchParams\";\nimport { recoverFromStaleAssets } from \"./staleAssets\";\nimport { afterHydration, replayEarlyClicks } from \"./earlyClicks\";\nimport { parseRedirectDigest } from \"../redirectDigest.js\";\nimport { showDevNotice } from \"./devNotice\";\nimport { caughtByLoading } from \"./fallbackReport\";\nimport { noteNavigation } from \"./segmentStore\";\nimport type { Route } from \"../routes.js\";\nimport { isSafeRedirect } from \"../safeUrl.js\";\nimport {\n createFromReadableStream,\n encodeReply,\n setServerCallback,\n} from \"@vitejs/plugin-rsc/browser\";\nimport { createElement, startTransition } from \"react\";\nimport { createRoot, hydrateRoot } from \"react-dom/client\";\nimport { activityMarkersIn } from \"./activityMarkers\";\nimport { ActivityRoot } from \"./ActivityRouter\";\nimport { ServerRedirectError, noteRedirected, throwForFailedAction } from \"./errors\";\nimport { fetchPagePayload } from \"./pagePayload\";\nimport { claimRead, setQueryCodec } from \"./queryClient\";\nimport { clearSegments, dropHidden, isHeld, prerenderSegment, restoreSegments, setSegment } from \"./segmentStore\";\nimport type { ReactNode } from \"react\";\nimport {\n cancelPrefetch,\n isPrefetched,\n navigate,\n setApiRoutes,\n refresh,\n applyRevalidations,\n prefetch,\n retentionKey,\n setCallServer,\n setHeldLayouts,\n setStaticPayloads,\n setStaticRoutes,\n seedStaticChain,\n payloadUrl,\n setDeserializer,\n setInterceptManifest,\n getHeldLayouts,\n setNavigateHandler,\n setHeldHandlers,\n setPrerenderHandler,\n setReplaceRootHandler,\n setRestoreHandler,\n setVersion,\n} from \"./navigate\";\n\n\n/**\n * A redirect that travelled as an error: the digest of the error itself, or\n * of the cause React wraps it in when it reports client-rendering a boundary\n * the server had already failed.\n */\nfunction isRedirect(error: unknown): boolean {\n const digest = (error as { digest?: unknown } | null)?.digest;\n const cause = (error as { cause?: { digest?: unknown } } | null)?.cause;\n\n return parseRedirectDigest(digest) !== null || parseRedirectDigest(cause?.digest) !== null;\n}\n\nexport async function createViteRscApp(\n container: Document | Element = document,\n interceptEntries: { urlPattern: string; slot: string }[] = [],\n options: { staticPayloads?: string | null; routes?: unknown[] | null; apiRoutes?: string[] } = {},\n): Promise<void> {\n // The urls a route.ts answers: a link to one is an anchor, never a\n // prefetch, never a payload fetch.\n if (options.apiRoutes) setApiRoutes(options.apiRoutes);\n // An exported build has no server to negotiate with, so payloads live at\n // their own urls rather than behind a header on the page's url.\n setStaticPayloads(options.staticPayloads ?? null);\n // Only an exported build ships this: with no server to negotiate with, the\n // client works out for itself how much of a page it still holds.\n if (options.routes) setStaticRoutes(options.routes as never);\n // The router has to recognise an intercepted link before it asks the server,\n // so the patterns are baked into the generated browser entry. Without them\n // every intercepted route falls through to a full-page navigation.\n setInterceptManifest(interceptEntries);\n\n async function callServer(id: string, args: unknown[]): Promise<unknown> {\n // A read opened a slot before calling the reference, and this is the first\n // point at which the id exists on the client — React keeps it private and\n // hands it over only here. Claiming the slot enqueues the read for the\n // batched GET instead of posting it.\n const read = claimRead(id, args);\n\n if (read) return await read;\n\n const encoded = await encodeReply(args);\n\n // encodeReply returns FormData as soon as an argument contains a File.\n // Sending that as multipart would make PHP consume php://input while\n // parsing it, leaving the action with an empty body — so serialize it to\n // raw bytes under an opaque content-type and send the real one in\n // X-RSC-Content-Type for the worker to rebuild FormData from.\n let body: BodyInit;\n let realContentType: string;\n\n if (encoded instanceof FormData) {\n const serialized = new Response(encoded);\n body = await serialized.arrayBuffer();\n realContentType =\n serialized.headers.get(\"content-type\") ?? \"multipart/form-data\";\n } else {\n body = encoded as BodyInit;\n realContentType = \"text/plain;charset=UTF-8\";\n }\n\n // Where the action was invoked from. The host resolves it to the\n // components that render the page, so anything the action says it\n // invalidated can come back with the answer instead of being fetched\n // afterwards - and what comes back is for this page, not whichever is\n // showing when it lands.\n const from = window.location.pathname + window.location.search;\n\n const res = await fetch(\"/_rsc/action\", {\n method: \"POST\",\n headers: {\n \"X-RSC-Action\": id,\n \"X-RSC-Referer\": from,\n \"X-RSC-Content-Type\": realContentType,\n \"Content-Type\": \"application/octet-stream\",\n \"X-XSRF-TOKEN\": decodeURIComponent(\n document.cookie.match(/XSRF-TOKEN=([^;]+)/)?.[1] ?? \"\",\n ),\n },\n body,\n });\n\n // A failed action does not answer with a Flight stream, and the decoder\n // cannot tell — it reports its own parse failure instead of what the\n // server said.\n try {\n await throwForFailedAction(res);\n } catch (err) {\n // A redirect is an instruction, not something for a form to display:\n // an expired session answers this way, and the destination is the login\n // page rather than a message about one.\n if (err instanceof ServerRedirectError) {\n // The destination came off a response header, so it is checked here\n // too — the engine refuses these at the source, but a proxy or a host\n // in front of it can write whatever it likes. A navigation, not a\n // document load: the layouts stay mounted and the history entry the\n // form was on is replaced, the way a redirect after a POST should\n // be - Back does not return to the submitted form.\n if (isSafeRedirect(err.location)) {\n void navigate(err.location as Route, { replace: true });\n }\n\n // Performed, so resolved - not thrown. The call's answer is \"you are\n // being taken somewhere\": an object saying so, the shape an action's\n // result already has, so a caller reading result.validationErrors\n // reads undefined rather than throwing. A caller that awaited the\n // action in a plain startTransition had no catch for a throw, the\n // rejection reached React, and the root unmounted to a white page\n // on every logout.\n noteRedirected(err.location);\n\n return { redirected: err.location };\n }\n\n throw err;\n }\n\n const answer = await createFromReadableStream(res.body!, { callServer });\n\n return unwrapRevalidated(answer, from);\n }\n\n /**\n * Put anything the action re-rendered on screen, and hand back its result.\n *\n * The trees travel with the answer rather than being fetched afterwards, so\n * the caller sees only what its action returned and never knows the page\n * was updated around it.\n */\n function unwrapRevalidated(answer: unknown, from: string): unknown {\n if (\n answer === null ||\n typeof answer !== \"object\" ||\n !(\"__rscRevalidated\" in answer)\n ) {\n return answer;\n }\n\n const envelope = answer as {\n __rscRevalidated: Record<string, unknown>;\n result: unknown;\n };\n\n applyRevalidations(from, envelope.__rscRevalidated as Record<string, ReactNode>);\n\n return envelope.result;\n }\n\n setDeserializer(createFromReadableStream as never);\n // The query transport speaks Flight too, and reaches the runtime through here\n // rather than importing it: a second import of the browser runtime from the\n // client-component graph is a second client-reference registry, and the\n // symptom is components that render as undefined with nothing logged.\n setQueryCodec({\n deserialize: (stream) =>\n createFromReadableStream(stream, { callServer }) as Promise<unknown>,\n encode: (args) => encodeReply(args) as Promise<string | FormData>,\n // The way back when a read cannot ride in a url. Re-entering callServer is\n // safe: the slot was cleared the moment the reference returned, so this\n // takes the ordinary POST path rather than claiming a read again.\n asAction: (id, args) => callServer(id, args),\n });\n setCallServer(callServer);\n // The plugin's own \"use server\" client stubs route through its registered\n // server callback — register the same transport there too.\n setServerCallback(callServer as never);\n\n // Link / Form / router live in a separate build graph and reach the SPA\n // engine through these globals.\n (window as unknown as { __rsc_navigate: typeof navigate }).__rsc_navigate =\n navigate;\n (window as unknown as { __rsc_prefetch: typeof prefetch }).__rsc_prefetch =\n prefetch;\n (\n window as unknown as { __rsc_cancel_prefetch: typeof cancelPrefetch }\n ).__rsc_cancel_prefetch = cancelPrefetch;\n (\n window as unknown as { __rsc_is_prefetched: typeof isPrefetched }\n ).__rsc_is_prefetched = isPrefetched;\n (window as unknown as { __rsc_refresh: typeof refresh }).__rsc_refresh =\n refresh;\n\n // Hydrate from the RSC endpoint (same url + X-RSC, no version header).\n //\n // Everything from here to the decode is failure handling, because this is\n // the one request with nothing watching it. A page whose shell is already\n // rendered looks fine while this fails, and its fallbacks stay on screen\n // indefinitely with nothing reported anywhere.\n const res = await fetchPagePayload(payloadUrl(window.location.href));\n\n // Seed the router with the build this DOCUMENT is, so a redeploy is caught\n // on the next navigation: the host answers 409 to a client of another\n // build, and the document is loaded again. From the document's own meta\n // first - a document a service worker served from its cache is the last\n // build's, while the payload just fetched is this one's, and seeding from\n // the payload would have the old client claim to be new. The header is\n // the fallback for a document with no meta.\n const documentBuild = document.querySelector('meta[name=\"rsc-kit:build\"]')?.getAttribute(\"content\");\n const servedVersion = documentBuild || res.headers.get(\"X-RSC-Version\");\n\n if (servedVersion) {\n setVersion(servedVersion);\n }\n\n // The chain this page is built from, so the next navigation can say what is\n // already mounted and be sent only what changed.\n // A server says what this page is built from; a file server says nothing,\n // so an exported build works it out from the table it was given.\n const servedLayouts = res.headers.get(\"X-RSC-Layouts\");\n\n if (servedLayouts !== null) {\n setHeldLayouts(servedLayouts.split(\",\"));\n } else if (!seedStaticChain(window.location.href)) {\n setHeldLayouts([]);\n }\n const tree = await createFromReadableStream(res.body!, { callServer });\n\n // Retaining the previous page behind <Activity> needs a wrapper above the\n // page, and React will not hydrate a *document* container through one: the\n // root child of a document has to be <html>, and wrapping it hangs the\n // renderer outright (React 19.2.7). An app whose root layout owns <html>\n // therefore hydrates the tree directly and navigations replace it, as before.\n //\n // Apps that hydrate into an element get retention. Giving it to document-\n // rooted apps means SPA navigation returning only the changed segment rather\n // than a whole document, which is an engine change, not a client one.\n const retains = container !== document;\n\n const shell = retains\n ? createElement(ActivityRoot, {\n initialKey: retentionKey(window.location.href, null),\n initialTree: tree as ReactNode,\n })\n : (tree as ReactNode);\n\n // A document that cannot be hydrated by this tree is client-rendered\n // instead - a repaint, not a freeze. React 19.2 does not recover from a\n // hydration mismatch at an <Activity>: it retries hydrating the boundary,\n // mismatches again, and never returns to the main thread. Every segment\n // boundary is an Activity, one per layout, so a document with none where\n // the page has layouts is that mismatch, guaranteed, before React starts.\n // What produced one: a parameterised route's PPR shell, rendered without\n // a page key and, by a build before this one, without the Activities too.\n // None rather than fewer: a boundary inside a Suspense hole the shell left\n // unfinished has no marker and is client-rendered by React on its own,\n // which is not a mismatch. The stale-asset reload does not apply - the\n // document would come back the same.\n const missing = retains && getHeldLayouts().length > 0 && activityMarkersIn(container) === 0;\n\n if (missing) {\n console.warn(\n \"[rsc-kit] The document has no <Activity> boundaries where the page has layouts, so it cannot be hydrated; rendering the page instead. A PPR shell built by an earlier release lacks them - rebuild.\",\n );\n }\n\n // The payload answered with an error status - the not-found page for a\n // url the shell was served for anyway. It is not the document on screen,\n // so it is rendered, not hydrated: a mismatch at an Activity is the loop\n // above, and this one is certain.\n const disagrees = !res.ok;\n\n const onRecoverableError = (error: unknown, errorInfo: unknown) => {\n // A client component whose chunk the server no longer has fails while\n // hydrating, and React reports that as recoverable: the page is loaded\n // again, with the current names.\n if (recoverFromStaleAssets(error)) return;\n\n // A redirect decided inside a boundary: the server's row carried it as\n // the digest, React client-renders the boundary and reports that it\n // did, and the RedirectBoundary is already performing it. Nothing to\n // read in the console about a page doing what it was told.\n if (isRedirect(error)) return;\n\n // A PPR shell is served with its Suspense boundaries deliberately\n // unfinished — the build aborts the render once the static part is out.\n // React reports that as #419 and client-renders the boundary from the\n // Flight payload, which is the intended path, not a fault to report.\n const message = String((error as { message?: string })?.message ?? error);\n\n if (\n message.includes(\"419\") ||\n message.includes(\"did not finish this Suspense boundary\")\n ) {\n return;\n }\n\n // A view transition the browser cancelled because the tab was not\n // visible. React reports it here; the update still landed, and a tab\n // in the background is not a fault in the page.\n if (message.includes(\"Transition was aborted\")) return;\n\n // A navigation another one overtook: its request was aborted, and a\n // row of its payload that a component was still reading rejects with\n // the abort. React recovers by rendering the root again synchronously\n // and reports the recovery here as #520, with the abort as the cause.\n // The page it recovered to is the one the second navigation asked for;\n // the abort was the design, not a fault.\n const cause = (error as { cause?: { name?: string; message?: string } } | null)?.cause;\n\n if (\n cause?.name === \"AbortError\" ||\n /\\baborted\\b/i.test(cause?.message ?? \"\") ||\n /\\baborted\\b/i.test(message)\n ) {\n return;\n }\n // A page whose query string was read under a boundary carries the\n // fallback there; React reports the recovery on hydration. Under a\n // boundary the developer wrote, that is the designed path and nothing\n // is said. With nothing closer than a loading.tsx, the whole segment\n // showed the fallback until the query arrived - said here, in the\n // page and the console, for whoever is looking at either. Production\n // has no stack to tell the two apart; the build's note on the route is\n // the record there.\n if (\n (error as { digest?: string })?.digest === SEARCH_PARAMS_FALLBACK ||\n message.includes(\"useSearchParams()\")\n ) {\n const stack = (errorInfo as { componentStack?: string } | null)\n ?.componentStack;\n\n if (!caughtByLoading(stack)) return;\n\n const hint =\n \"useSearchParams() was read on the server with nothing closer than a loading.tsx, so the \" +\n \"whole segment showed that fallback until the query arrived. A <Suspense> around the \" +\n \"component that reads keeps the rest of the page painted.\";\n\n showDevNotice(hint, stack);\n console.error(new Error(hint), errorInfo);\n\n return;\n }\n\n console.error(error, errorInfo);\n };\n\n const rootOptions = {\n onRecoverableError,\n // A chunk the deploy no longer serves is not a fault in the page; the\n // document is loaded again, and the new names come with it. Anything\n // else is reported the way React would have.\n onUncaughtError(error: unknown, errorInfo: unknown) {\n if (recoverFromStaleAssets(error)) return;\n\n console.error(error, errorInfo);\n },\n onCaughtError(error: unknown, errorInfo: unknown) {\n if (recoverFromStaleAssets(error)) return;\n // Caught by the RedirectBoundary, which is performing it.\n if (isRedirect(error)) return;\n\n console.error(error, errorInfo);\n },\n };\n\n const root = missing || disagrees\n ? (() => {\n const created = createRoot(container as Element, rootOptions);\n\n created.render(shell);\n\n return created;\n })()\n : hydrateRoot(container, shell, rootOptions);\n\n // Depth 0 is a whole document and replaces the root. Anything deeper is one\n // segment: handing it to the boundary at that depth leaves the layouts above\n // it mounted, which is the point of asking for a partial render at all.\n setNavigateHandler((tree: unknown, key: string, segmentDepth: number) => {\n const newTree = tree as ReactNode;\n\n // From here on the boundary animates; the seed commit before this did not.\n noteNavigation();\n\n if (segmentDepth > 0) {\n setSegment(segmentDepth, key, newTree);\n\n return;\n }\n\n clearSegments();\n root.render(newTree);\n });\n\n // The whole document again, in place - revalidate(\"all\"). Not through the\n // handler above: that clears the boundaries and renders the tree as a new\n // page, and a boundary emptied re-keys its Activity to the current url and\n // remounts everything under it. A port's \"added to cart\" went with the\n // form's state that way, on every product reached by a link. Here the root\n // takes the tree in a transition and each boundary hands its page the new\n // children under the key it has - see replaceActive.\n setReplaceRootHandler((tree: unknown) => {\n startTransition(() => root.render(tree as ReactNode));\n });\n\n // Back and forward reveal a page the boundaries are still holding, with the\n // form you were filling in still filled in, and without asking the server.\n setRestoreHandler((key: string, maxAge?: number) =>\n restoreSegments(key, maxAge),\n );\n setHeldHandlers(isHeld, dropHidden);\n\n // A touch or a settled hover: the page is rendered hidden now, and the\n // click reveals it. See warm() in navigate.ts and prerenderSegment.\n setPrerenderHandler((tree: unknown, key: string, segmentDepth: number) => {\n prerenderSegment(segmentDepth, key, tree as ReactNode);\n });\n\n window.addEventListener(\"popstate\", () => {\n // restore: back and forward reveal the page you were on, with its state.\n // Wherever the browser just went; not a literal this app wrote.\n navigate(window.location.href as Route, { replace: true, restore: true });\n });\n\n history.replaceState(\n { rscUrl: window.location.href },\n \"\",\n window.location.href,\n );\n\n // A tap held by the bootstrap script, navigated to once hydration has\n // committed - not now: the runtime's script running is seconds before\n // React can dispatch a click on a phone still downloading chunks, and\n // a tap in that window would be the browser's. See earlyClicks.ts.\n afterHydration(() => replayEarlyClicks((url) => navigate(url as Route)));\n}\n\n"]}
|
package/dist/js/earlyClicks.d.ts
CHANGED
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
export declare const EARLY_CLICKS: string;
|
|
25
25
|
/**
|
|
26
26
|
* Hand the clicks held before hydration to the router. The last one is the
|
|
27
|
-
* page the visitor meant; the ones before it were on the way there.
|
|
27
|
+
* page the visitor meant; the ones before it were on the way there. A form
|
|
28
|
+
* held is submitted again, now that React's handler is on it - a tap on a
|
|
29
|
+
* link after it wins, since the visitor left the form.
|
|
28
30
|
*/
|
|
29
31
|
export declare function replayEarlyClicks(navigate: (url: string) => Promise<void>): string | null;
|
|
30
32
|
/**
|
package/dist/js/earlyClicks.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* route.ts, a mailto or a foreign origin is not a page the router swaps in.
|
|
22
22
|
*/
|
|
23
23
|
/** Written into the bootstrap script, ahead of the runtime's import. No backticks: it lives in a template. */
|
|
24
|
-
export const EARLY_CLICKS = "(function(){var q=[];function h(e){" +
|
|
24
|
+
export const EARLY_CLICKS = "(function(){var q=[],fq=[];function h(e){" +
|
|
25
25
|
"if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;" +
|
|
26
26
|
"var t=e.target;var a=t&&t.closest?t.closest('a[data-rsc]'):null;" +
|
|
27
27
|
"if(!a||(a.target&&a.target!=='_self'))return;" +
|
|
@@ -36,11 +36,26 @@ export const EARLY_CLICKS = "(function(){var q=[];function h(e){" +
|
|
|
36
36
|
// hard limit for a runtime that started and never finished.
|
|
37
37
|
"setTimeout(function(){if(q.length&&!w.__rsc_hydrated&&!w.__rsc_navigate)location.href=q[q.length-1]},3000);" +
|
|
38
38
|
"setTimeout(function(){if(q.length&&!w.__rsc_hydrated)location.href=q[q.length-1]},15000)}" +
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// A form submitted before hydration. React renders a form whose action
|
|
40
|
+
// is a server action with $ACTION_ hidden fields so it posts natively
|
|
41
|
+
// without a runtime - the page reloads with the action applied, which is
|
|
42
|
+
// the right answer with no JavaScript and the wrong one with JavaScript
|
|
43
|
+
// a second away: "Add to cart" on a product page reloaded the page when
|
|
44
|
+
// tapped before the runtime hydrated. Held like a tap, and submitted
|
|
45
|
+
// again once hydration commits, when React's own handler takes it.
|
|
46
|
+
"function g(){var x=fq.pop();fq.length=0;if(x)HTMLFormElement.prototype.submit.call(x.f)}" +
|
|
47
|
+
"function s(e){if(e.defaultPrevented)return;var f=e.target;" +
|
|
48
|
+
"if(!f||f.tagName!=='FORM'||!f.querySelector('input[name^=\"$ACTION_\"]'))return;" +
|
|
49
|
+
"e.preventDefault();fq.push({f:f,s:e.submitter||null});f.setAttribute('data-pending','');" +
|
|
50
|
+
"setTimeout(function(){if(fq.length&&!w.__rsc_hydrated&&!w.__rsc_navigate)g()},3000);" +
|
|
51
|
+
"setTimeout(function(){if(fq.length&&!w.__rsc_hydrated)g()},15000)}" +
|
|
52
|
+
"var w=window;document.addEventListener('click',h,true);document.addEventListener('submit',s,true);" +
|
|
53
|
+
"w.__rsc_early={q:q,fq:fq,stop:function(){document.removeEventListener('click',h,true);document.removeEventListener('submit',s,true)}}})();";
|
|
41
54
|
/**
|
|
42
55
|
* Hand the clicks held before hydration to the router. The last one is the
|
|
43
|
-
* page the visitor meant; the ones before it were on the way there.
|
|
56
|
+
* page the visitor meant; the ones before it were on the way there. A form
|
|
57
|
+
* held is submitted again, now that React's handler is on it - a tap on a
|
|
58
|
+
* link after it wins, since the visitor left the form.
|
|
44
59
|
*/
|
|
45
60
|
export function replayEarlyClicks(navigate) {
|
|
46
61
|
const early = window.__rsc_early;
|
|
@@ -48,9 +63,17 @@ export function replayEarlyClicks(navigate) {
|
|
|
48
63
|
return null;
|
|
49
64
|
early.stop();
|
|
50
65
|
const last = early.q[early.q.length - 1] ?? null;
|
|
66
|
+
const form = early.fq?.[early.fq.length - 1] ?? null;
|
|
51
67
|
early.q.length = 0;
|
|
52
|
-
if (
|
|
68
|
+
if (early.fq)
|
|
69
|
+
early.fq.length = 0;
|
|
70
|
+
if (last) {
|
|
53
71
|
void navigate(last);
|
|
72
|
+
}
|
|
73
|
+
else if (form) {
|
|
74
|
+
form.f.removeAttribute("data-pending");
|
|
75
|
+
form.f.requestSubmit(form.s instanceof HTMLElement ? form.s : undefined);
|
|
76
|
+
}
|
|
54
77
|
return last;
|
|
55
78
|
}
|
|
56
79
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"earlyClicks.js","sourceRoot":"","sources":["../../src/js/earlyClicks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,8GAA8G;AAC9G,MAAM,CAAC,MAAM,YAAY,GACvB,
|
|
1
|
+
{"version":3,"file":"earlyClicks.js","sourceRoot":"","sources":["../../src/js/earlyClicks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,8GAA8G;AAC9G,MAAM,CAAC,MAAM,YAAY,GACvB,2CAA2C;IAC3C,yFAAyF;IACzF,kEAAkE;IAClE,+CAA+C;IAC/C,4EAA4E;IAC5E,uCAAuC;IACvC,0FAA0F;IAC1F,wEAAwE;IACxE,0EAA0E;IAC1E,yEAAyE;IACzE,oEAAoE;IACpE,uEAAuE;IACvE,4DAA4D;IAC5D,6GAA6G;IAC7G,2FAA2F;IAC3F,uEAAuE;IACvE,sEAAsE;IACtE,yEAAy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cAAc,EAAE,CAAC;QACrB,EAAE,EAAE,CAAC;QAEL,OAAO;IACT,CAAC;IAED,CAAC,CAAC,iBAAiB,GAAG,GAAG,EAAE;QACzB,CAAC,CAAC,iBAAiB,GAAG,SAAS,CAAC;QAChC,EAAE,EAAE,CAAC;IACP,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * A tap before the page can navigate.\n *\n * The document arrives, the bootstrap script starts the runtime, and on a\n * phone the runtime takes a while to arrive and hydrate - seconds, with a\n * tag manager or two on the main thread. A tap on a link in that window is\n * the browser's: a document load, of a page the router would have swapped\n * in. The port's \"Sign in is slow from the home page, and sometimes a full\n * reload\" was this, and only on a phone, where the window is wide.\n *\n * The first thing the bootstrap script does is listen: a click on one of\n * this package's links, before the page has hydrated, is held. When\n * hydration commits - not when the runtime's script runs, which is\n * seconds earlier on a phone whose chunks are still downloading, and where\n * a click is nobody's yet - the last one held is navigated to. A click\n * held for three seconds with no runtime started is given to the browser\n * as a document load, so nothing is lost if the runtime never comes; one\n * held while the runtime is running waits for hydration, up to fifteen.\n *\n * Only this package's links, marked `data-rsc`: a plain anchor to a file, a\n * route.ts, a mailto or a foreign origin is not a page the router swaps in.\n */\n\n/** Written into the bootstrap script, ahead of the runtime's import. No backticks: it lives in a template. */\nexport const EARLY_CLICKS =\n \"(function(){var q=[],fq=[];function h(e){\" +\n \"if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;\" +\n \"var t=e.target;var a=t&&t.closest?t.closest('a[data-rsc]'):null;\" +\n \"if(!a||(a.target&&a.target!=='_self'))return;\" +\n \"var u;try{u=new URL(a.getAttribute('href'),location.href)}catch(x){return}\" +\n \"if(u.origin!==location.origin)return;\" +\n \"e.preventDefault();q.push(u.pathname+u.search+u.hash);a.setAttribute('data-pending','');\" +\n // Given to the browser only when the runtime has not even started three\n // seconds after the tap - a script blocked, a chunk that failed. While it\n // is running, hydration is coming, and a phone's takes longer than three\n // seconds: a tap given up at three landed as a document load half a\n // second before the page would have handled it. Fifteen seconds is the\n // hard limit for a runtime that started and never finished.\n \"setTimeout(function(){if(q.length&&!w.__rsc_hydrated&&!w.__rsc_navigate)location.href=q[q.length-1]},3000);\" +\n \"setTimeout(function(){if(q.length&&!w.__rsc_hydrated)location.href=q[q.length-1]},15000)}\" +\n // A form submitted before hydration. React renders a form whose action\n // is a server action with $ACTION_ hidden fields so it posts natively\n // without a runtime - the page reloads with the action applied, which is\n // the right answer with no JavaScript and the wrong one with JavaScript\n // a second away: \"Add to cart\" on a product page reloaded the page when\n // tapped before the runtime hydrated. Held like a tap, and submitted\n // again once hydration commits, when React's own handler takes it.\n \"function g(){var x=fq.pop();fq.length=0;if(x)HTMLFormElement.prototype.submit.call(x.f)}\" +\n \"function s(e){if(e.defaultPrevented)return;var f=e.target;\" +\n \"if(!f||f.tagName!=='FORM'||!f.querySelector('input[name^=\\\"$ACTION_\\\"]'))return;\" +\n \"e.preventDefault();fq.push({f:f,s:e.submitter||null});f.setAttribute('data-pending','');\" +\n \"setTimeout(function(){if(fq.length&&!w.__rsc_hydrated&&!w.__rsc_navigate)g()},3000);\" +\n \"setTimeout(function(){if(fq.length&&!w.__rsc_hydrated)g()},15000)}\" +\n \"var w=window;document.addEventListener('click',h,true);document.addEventListener('submit',s,true);\" +\n \"w.__rsc_early={q:q,fq:fq,stop:function(){document.removeEventListener('click',h,true);document.removeEventListener('submit',s,true)}}})();\";\n\ninterface Early {\n q: string[];\n fq?: { f: HTMLFormElement; s: HTMLElement | null }[];\n stop(): void;\n}\n\n/**\n * Hand the clicks held before hydration to the router. The last one is the\n * page the visitor meant; the ones before it were on the way there. A form\n * held is submitted again, now that React's handler is on it - a tap on a\n * link after it wins, since the visitor left the form.\n */\nexport function replayEarlyClicks(navigate: (url: string) => Promise<void>): string | null {\n const early = (window as { __rsc_early?: Early }).__rsc_early;\n\n if (!early) return null;\n\n early.stop();\n\n const last = early.q[early.q.length - 1] ?? null;\n const form = early.fq?.[early.fq.length - 1] ?? null;\n\n early.q.length = 0;\n if (early.fq) early.fq.length = 0;\n\n if (last) {\n void navigate(last);\n } else if (form) {\n form.f.removeAttribute(\"data-pending\");\n form.f.requestSubmit(form.s instanceof HTMLElement ? (form.s as HTMLElement) : undefined);\n }\n\n return last;\n}\n\n/**\n * Run once hydration has committed - now, if it already has, or when the\n * outermost client component's first effect says so. Before that a click\n * is nobody's: the listener above is still holding them, and React has no\n * fibers to dispatch to.\n */\nexport function afterHydration(fn: () => void): void {\n const w = window as { __rsc_hydrated?: boolean; __rsc_on_hydrated?: () => void };\n\n if (w.__rsc_hydrated) {\n fn();\n\n return;\n }\n\n w.__rsc_on_hydrated = () => {\n w.__rsc_on_hydrated = undefined;\n fn();\n };\n}\n"]}
|
package/dist/js/errors.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ export declare function throwForFailedAction(response: Response): Promise<void>;
|
|
|
43
43
|
* decoder reports the decoder's confusion rather than the status.
|
|
44
44
|
*/
|
|
45
45
|
export declare function throwForFailedPayload(response: Response): void;
|
|
46
|
+
/** Whether a response is a Flight payload, whatever its status. */
|
|
47
|
+
export declare function isPayload(response: Response): boolean;
|
|
46
48
|
/**
|
|
47
49
|
* Announce a failure that nothing else will.
|
|
48
50
|
*
|
package/dist/js/errors.js
CHANGED
|
@@ -103,8 +103,19 @@ export async function throwForFailedAction(response) {
|
|
|
103
103
|
export function throwForFailedPayload(response) {
|
|
104
104
|
if (response.ok)
|
|
105
105
|
return;
|
|
106
|
+
// A 404 that is a payload is the not-found page, rendered: a url a
|
|
107
|
+
// pattern's shell answered with a 200 and a page that, run for real,
|
|
108
|
+
// found no row - a subcategory under the wrong category. The page is
|
|
109
|
+
// what the visitor should see; refusing it left the shell's content on
|
|
110
|
+
// screen with nothing hydrated behind it, and every tap dead.
|
|
111
|
+
if (isPayload(response))
|
|
112
|
+
return;
|
|
106
113
|
throw new Error(`RSC payload request failed with ${response.status}`);
|
|
107
114
|
}
|
|
115
|
+
/** Whether a response is a Flight payload, whatever its status. */
|
|
116
|
+
export function isPayload(response) {
|
|
117
|
+
return (response.headers.get("Content-Type") ?? "").includes("text/x-component");
|
|
118
|
+
}
|
|
108
119
|
/**
|
|
109
120
|
* Announce a failure that nothing else will.
|
|
110
121
|
*
|