@rsc-kit/core 0.30.39 → 0.30.42

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.
@@ -25,7 +25,8 @@ export declare function setStaticRoutes(routes: ManifestRoute[]): void;
25
25
  */
26
26
  export declare function seedStaticChain(url: string): boolean;
27
27
  export declare function setStaticPayloads(suffix: string | null): void;
28
- /** The url to request a payload from, which is the page's own unless exported. */
28
+ /** The url a page boots from: its payload, at its own url when the app answers it. */
29
+ export declare function bootPayloadUrl(url: string): string;
29
30
  export declare function payloadUrl(url: string, held?: string[]): string;
30
31
  export declare function setVersion(v: string): void;
31
32
  /**
@@ -50,6 +51,20 @@ export declare function setHeldHandlers(held: ((key: string, maxAge?: number) =>
50
51
  * for the back button are from before it too.
51
52
  */
52
53
  export declare function forgetOtherPages(): void;
54
+ /**
55
+ * Where an action that redirected sends the visitor: a navigation that
56
+ * replaces the form's history entry.
57
+ *
58
+ * A navigation names the layouts it holds and the server leaves them out -
59
+ * right for most redirects, which change nothing a layout reads, and cheap.
60
+ * An action that did change one says so the way any action does, with
61
+ * revalidate(), and the destination is then asked for whole, layouts
62
+ * included, as refresh('all') asks. Anything but 'page': a named section can
63
+ * live in a layout, and the destination's page is asked for fresh anyway.
64
+ * Before, the revalidation was dropped with the redirect, and a team switch
65
+ * that asked for 'all' still showed the old team's name in the sidebar.
66
+ */
67
+ export declare function followActionRedirect(location: string, revalidated?: string[]): Promise<void>;
53
68
  export declare function setPrerenderHandler(fn: ((tree: ReactNode, key: string, segmentDepth: number) => void) | null): void;
54
69
  /**
55
70
  * How the router reveals a page that is still mounted behind the current one.
@@ -11,6 +11,7 @@ import { navigationAbandoned, navigationCommitted, navigationReached, navigation
11
11
  import { preloadImages } from "./imagePreload.js";
12
12
  import { preloadChunks } from "./chunkPreload.js";
13
13
  import { isSafeRedirect } from "../safeUrl.js";
14
+ import { keyedPayloadUrl } from "./payloadKey.js";
14
15
  import { reportReachable } from "./onlineStore.js";
15
16
  import { clearSlots, setSlot } from "./slotStore.js";
16
17
  // Shared with the host: it stores a page under this key and the client looks
@@ -209,6 +210,18 @@ export function setStaticPayloads(suffix) {
209
210
  staticPayloadSuffix = suffix;
210
211
  }
211
212
  /** The url to request a payload from, which is the page's own unless exported. */
213
+ /**
214
+ * A payload asked for from the app gets its own url, keyed on the headers that
215
+ * shape it (payloadKey.ts), so a cache that ignores Vary cannot mix it up with
216
+ * the document. A static payload is a file with its own name already.
217
+ */
218
+ function keyed(url, headers) {
219
+ return staticPayloadSuffix === null ? keyedPayloadUrl(url, headers) : url;
220
+ }
221
+ /** The url a page boots from: its payload, at its own url when the app answers it. */
222
+ export function bootPayloadUrl(url) {
223
+ return keyed(payloadUrl(url), { "X-RSC": "1" });
224
+ }
212
225
  export function payloadUrl(url, held = heldLayouts) {
213
226
  if (staticPayloadSuffix === null)
214
227
  return url;
@@ -301,6 +314,25 @@ export function forgetOtherPages() {
301
314
  cache.clear();
302
315
  dropHeld?.();
303
316
  }
317
+ /**
318
+ * Where an action that redirected sends the visitor: a navigation that
319
+ * replaces the form's history entry.
320
+ *
321
+ * A navigation names the layouts it holds and the server leaves them out -
322
+ * right for most redirects, which change nothing a layout reads, and cheap.
323
+ * An action that did change one says so the way any action does, with
324
+ * revalidate(), and the destination is then asked for whole, layouts
325
+ * included, as refresh('all') asks. Anything but 'page': a named section can
326
+ * live in a layout, and the destination's page is asked for fresh anyway.
327
+ * Before, the revalidation was dropped with the redirect, and a team switch
328
+ * that asked for 'all' still showed the old team's name in the sidebar.
329
+ */
330
+ export async function followActionRedirect(location, revalidated = []) {
331
+ forgetOtherPages();
332
+ if (revalidated.some((target) => target !== "page"))
333
+ heldLayouts = [];
334
+ await navigate(location, { replace: true });
335
+ }
304
336
  export function setPrerenderHandler(fn) {
305
337
  onPrerender = fn;
306
338
  }
@@ -458,7 +490,7 @@ notFound = false) {
458
490
  }
459
491
  // `priority` is not in every lib.dom yet; browsers without it ignore it.
460
492
  const asked = staticSegments(url, chain);
461
- const request = fetch(payloadUrl(url, chain), {
493
+ const request = fetch(keyed(payloadUrl(url, chain), headers), {
462
494
  headers,
463
495
  signal,
464
496
  priority,
@@ -1011,16 +1043,15 @@ export async function refresh(target = "page", changedBy) {
1011
1043
  // from before.
1012
1044
  forgetOtherPages();
1013
1045
  if (target !== "page" && target !== "all") {
1014
- const response = await fetch(payloadUrl(url), {
1015
- headers: {
1016
- "X-RSC": "true",
1017
- "X-RSC-Version": version,
1018
- "X-RSC-Revalidate": target,
1019
- // Which change asked: tabs asking about the same one share a render
1020
- // of a shared section. Only ever set by the watcher.
1021
- ...(changedBy ? { "X-RSC-Changed": changedBy } : {}),
1022
- },
1023
- });
1046
+ const headers = {
1047
+ "X-RSC": "true",
1048
+ "X-RSC-Version": version,
1049
+ "X-RSC-Revalidate": target,
1050
+ // Which change asked: tabs asking about the same one share a render
1051
+ // of a shared section. Only ever set by the watcher.
1052
+ ...(changedBy ? { "X-RSC-Changed": changedBy } : {}),
1053
+ };
1054
+ const response = await fetch(keyed(payloadUrl(url), headers), { headers });
1024
1055
  if (!response.ok) {
1025
1056
  throw new Error(`Could not revalidate ${target}: the server answered ${response.status}`);
1026
1057
  }