@rsc-kit/core 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,8 @@ export interface ReportedRoute {
8
8
  reason: string | null;
9
9
  /** Something true and worth knowing that is not a failure. */
10
10
  warning: string | null;
11
+ /** A fact about how it was stored - "no client components, so ships no javascript". Absent from older reports. */
12
+ note?: string | null;
11
13
  /** Gzipped bytes of javascript this url makes the browser download. */
12
14
  clientJs: number | null;
13
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"buildReport.js","sourceRoot":"","sources":["../src/buildReport.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,yEAAyE;AACzE,iEAAiE;AACjE,EAAE;AACF,yEAAyE;AACzE,6EAA6E;AAC7E,+CAA+C;AAkD/C,8EAA8E;AAC9E,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAA;AAE9C,MAAM,UAAU,WAAW,CACzB,MAAuB,EACvB,IAAwB,EACxB,OAAO,GAAqB,EAAE;IAE9B,MAAM,KAAK,GAAG,CAAC,GAAG,KAAe,EAAE,EAAE,CACnC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM;QACnD,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAA;IAEnD,MAAM,MAAM,GAAgB;QAC1B,OAAO,EAAE,CAAC;QACV,MAAM;QACN,IAAI;QACJ,OAAO;QACP,MAAM,EAAE;YACN,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;YACvB,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;YACzB,yEAAyE;YACzE,uEAAuE;YACvE,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC;SAClC;KACF,CAAA;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAA;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,MAAuB;IAChD,MAAM,IAAI,GAA2B,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAA;IAE9F,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CACrB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAClF,CAAA;AACH,CAAC","sourcesContent":["// What the build decided, written down.\n//\n// The classification exists already — it is printed as the build runs, and\n// then it is gone. That is fine for a person watching a terminal and useless\n// for anything that wants to ask afterwards: a CI step asserting nothing\n// regressed, an editor, an agent being asked why a page is slow.\n//\n// So the same facts go to a file. Not a new computation and not a second\n// source of truth — the report is written from the results the build already\n// produced, in the same pass that prints them.\n\n/** One route, as the build left it. */\nexport interface ReportedRoute {\n url: string\n component: string\n /** frozen | shell | blocked | dynamic | error — see PrerenderResult. blocked and error failed the build. */\n type: string\n /** Why it is not frozen, in the words the build printed. */\n reason: string | null\n /** Something true and worth knowing that is not a failure. */\n warning: string | null\n /** Gzipped bytes of javascript this url makes the browser download. */\n clientJs: number | null\n}\n\n/** A server action, and whether anything checks who calls it. */\nexport interface ReportedAction {\n id: string\n name: string\n file: string\n /** Built by createActionClient, so its middleware ran. */\n client: boolean\n /** A read (GET) rather than a mutation. */\n query: boolean\n}\n\nexport interface ReportedApiRoute {\n url: string\n name: string\n type: string\n reason: string | null\n}\n\nexport interface BuildReport {\n version: 1\n /** Routes that render, in the order the build reported them. */\n routes: ReportedRoute[]\n /** route.ts endpoints. */\n apis: ReportedApiRoute[]\n /** Every \"use server\" export the app registered. Absent from reports older than this field. */\n actions?: ReportedAction[]\n totals: {\n static: number\n partial: number\n dynamic: number\n failed: number\n }\n}\n\n/** The name the report is written under, inside the build's own directory. */\nexport const REPORT_FILE = 'build-report.json'\n\nexport function buildReport(\n routes: ReportedRoute[],\n apis: ReportedApiRoute[],\n actions: ReportedAction[] = [],\n): string {\n const count = (...types: string[]) =>\n routes.filter((r) => types.includes(r.type)).length +\n apis.filter((a) => types.includes(a.type)).length\n\n const report: BuildReport = {\n version: 1,\n routes,\n apis,\n actions,\n totals: {\n static: count('frozen'),\n partial: count('shell'),\n dynamic: count('dynamic'),\n // Blocked is refused, not dynamic: a page that painted nothing before it\n // read the request has no shell to store and the build did not finish.\n failed: count('error', 'blocked'),\n },\n }\n\n return JSON.stringify(report, null, 2) + '\\n'\n}\n\n/**\n * The routes worth asking about, most interesting first.\n *\n * \"Interesting\" is not a judgement about the app — it is the order someone\n * looking for a problem reads in. A failure first, then a page that could not\n * be stored at all, then one that ships a shell, then the ones that are fine.\n */\nexport function byInterest(routes: ReportedRoute[]): ReportedRoute[] {\n const rank: Record<string, number> = { error: 0, blocked: 1, shell: 2, dynamic: 3, frozen: 4 }\n\n return [...routes].sort(\n (a, b) => (rank[a.type] ?? 9) - (rank[b.type] ?? 9) || a.url.localeCompare(b.url),\n )\n}\n"]}
1
+ {"version":3,"file":"buildReport.js","sourceRoot":"","sources":["../src/buildReport.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,yEAAyE;AACzE,iEAAiE;AACjE,EAAE;AACF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E,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAClF,CAAA;AACH,CAAC","sourcesContent":["// What the build decided, written down.\n//\n// The classification exists already — it is printed as the build runs, and\n// then it is gone. That is fine for a person watching a terminal and useless\n// for anything that wants to ask afterwards: a CI step asserting nothing\n// regressed, an editor, an agent being asked why a page is slow.\n//\n// So the same facts go to a file. Not a new computation and not a second\n// source of truth — the report is written from the results the build already\n// produced, in the same pass that prints them.\n\n/** One route, as the build left it. */\nexport interface ReportedRoute {\n url: string\n component: string\n /** frozen | shell | blocked | dynamic | error — see PrerenderResult. blocked and error failed the build. */\n type: string\n /** Why it is not frozen, in the words the build printed. */\n reason: string | null\n /** Something true and worth knowing that is not a failure. */\n warning: string | null\n /** A fact about how it was stored - \"no client components, so ships no javascript\". Absent from older reports. */\n note?: string | null\n /** Gzipped bytes of javascript this url makes the browser download. */\n clientJs: number | null\n}\n\n/** A server action, and whether anything checks who calls it. */\nexport interface ReportedAction {\n id: string\n name: string\n file: string\n /** Built by createActionClient, so its middleware ran. */\n client: boolean\n /** A read (GET) rather than a mutation. */\n query: boolean\n}\n\nexport interface ReportedApiRoute {\n url: string\n name: string\n type: string\n reason: string | null\n}\n\nexport interface BuildReport {\n version: 1\n /** Routes that render, in the order the build reported them. */\n routes: ReportedRoute[]\n /** route.ts endpoints. */\n apis: ReportedApiRoute[]\n /** Every \"use server\" export the app registered. Absent from reports older than this field. */\n actions?: ReportedAction[]\n totals: {\n static: number\n partial: number\n dynamic: number\n failed: number\n }\n}\n\n/** The name the report is written under, inside the build's own directory. */\nexport const REPORT_FILE = 'build-report.json'\n\nexport function buildReport(\n routes: ReportedRoute[],\n apis: ReportedApiRoute[],\n actions: ReportedAction[] = [],\n): string {\n const count = (...types: string[]) =>\n routes.filter((r) => types.includes(r.type)).length +\n apis.filter((a) => types.includes(a.type)).length\n\n const report: BuildReport = {\n version: 1,\n routes,\n apis,\n actions,\n totals: {\n static: count('frozen'),\n partial: count('shell'),\n dynamic: count('dynamic'),\n // Blocked is refused, not dynamic: a page that painted nothing before it\n // read the request has no shell to store and the build did not finish.\n failed: count('error', 'blocked'),\n },\n }\n\n return JSON.stringify(report, null, 2) + '\\n'\n}\n\n/**\n * The routes worth asking about, most interesting first.\n *\n * \"Interesting\" is not a judgement about the app — it is the order someone\n * looking for a problem reads in. A failure first, then a page that could not\n * be stored at all, then one that ships a shell, then the ones that are fine.\n */\nexport function byInterest(routes: ReportedRoute[]): ReportedRoute[] {\n const rank: Record<string, number> = { error: 0, blocked: 1, shell: 2, dynamic: 3, frozen: 4 }\n\n return [...routes].sort(\n (a, b) => (rank[a.type] ?? 9) - (rank[b.type] ?? 9) || a.url.localeCompare(b.url),\n )\n}\n"]}
@@ -66,8 +66,13 @@ export interface ManifestRoute {
66
66
  * client, no router. A client component on such a route is inert markup — a
67
67
  * button that does nothing — so the build refuses the combination rather
68
68
  * than shipping it.
69
+ *
70
+ * 'auto' when the page declares nothing: a route that freezes whole with no
71
+ * client component and no server action in it is stored without the
72
+ * bootstrap, because there is nothing for a runtime to do. `true` forces
73
+ * the runtime onto such a page.
69
74
  */
70
- clientJs: boolean;
75
+ clientJs: boolean | 'auto';
71
76
  }
72
77
  export interface ManifestIntercept {
73
78
  component: string;
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,gFAAgF;AAChF,uCAAuC;AACvC,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,oBAAoB","sourcesContent":["// The shape of routes.json — what the build discovered, for a host to read.\n//\n// The build already walks app/ to generate its entries, and every host needs\n// the same facts: which url a component answers, what layouts wrap it, which\n// slots and sections belong to it. Laravel used to scan the tree a second time\n// to work that out; a JS host would have had to write a third walk. This is the\n// one answer, and these are its types.\n//\n// Urls are segments rather than a pattern string, because the pattern is the\n// host's dialect: Laravel writes {slug}, Hono writes :slug, and neither is the\n// build's business.\n\nexport interface RouteSegment {\n type: 'static' | 'param' | 'catchAll'\n value: string\n}\n\nexport interface ManifestRoute {\n component: string\n segments: RouteSegment[]\n layouts: string[]\n loadings: string[]\n /**\n * `error.tsx` files above this route, outermost first.\n *\n * The nearest one to a failure catches it, the same way the nearest\n * `loading.tsx` is the fallback. Optional: a manifest from a build before\n * error boundaries existed has none.\n */\n errors?: string[]\n /**\n * `middleware.ts` files above this route, outermost first.\n *\n * Run before anything at or below them renders, on every path. A check is\n * not UI, and making it a layout meant the client could decline it: layouts\n * are skipped on a partial navigation, and what gets skipped is named in a\n * header nothing can verify.\n */\n middleware: string[]\n slots: Record<string, string>\n sections: string[]\n /**\n * The host's route-config file beside this page, if it named one, and the\n * ancestor ones that also apply — outermost first, this page's excluded.\n *\n * Relative to the project root: an absolute path is true only on the machine\n * that produced it, and building in a container is ordinary.\n */\n config: string | null\n ancestorConfigs: string[]\n /**\n * Host middleware names for this route, outermost first.\n *\n * Declared in a route.ts beside or above the page. The engine does not know\n * what they mean — they are the host's own vocabulary — it only runs them\n * past the host before anything at or below this route renders.\n *\n * Empty on a route that named none, and on every route in an app that never\n * wrote a route.ts, which is why this needs no flag.\n *\n * Optional because registration boots from the PREVIOUS build's manifest: a\n * shape change takes two builds to settle, and a required field would make\n * the first of those a hard failure rather than a route with no guards.\n */\n hostMiddleware?: string[]\n /**\n * Whether the page exports generateStaticParams.\n *\n * Recorded here so a host can plan a build — which routes to ask for urls,\n * which to leave on demand — without loading the server bundle first. The\n * function itself is reached through the bundle's getStaticParams(), because\n * only the bundle can run it.\n */\n staticParams: boolean\n /**\n * Whether this route ships the client runtime.\n *\n * False renders to HTML and stops: no bootstrap, so no React, no Flight\n * client, no router. A client component on such a route is inert markup — a\n * button that does nothing — so the build refuses the combination rather\n * than shipping it.\n */\n clientJs: boolean\n}\n\nexport interface ManifestIntercept {\n component: string\n slot: string\n segments: RouteSegment[]\n /** (.) same level, (..) one up, (...) from the root. */\n marker: string\n}\n\n/**\n * A `route.ts` — an api endpoint rather than a page.\n *\n * Separate from `routes` because it is matched before them and answered\n * without rendering anything: no layouts, no payload, no client. A url cannot\n * be both, and the build refuses one that is.\n */\nexport interface ManifestApiRoute {\n /** The module name, as the engine's registry keys it. */\n name: string\n segments: RouteSegment[]\n /** Which methods the file exports, so a 405 can name the rest. */\n methods: string[]\n /**\n * `middleware.ts` files above this route, outermost first.\n *\n * The same chain a page in that directory runs. A route.ts sits among the\n * pages it belongs with, so a guard on the directory covers it too —\n * anything else would mean adding an endpoint under a guarded path silently\n * opened a hole in it.\n */\n middleware: string[]\n}\n\nexport interface RouteManifest {\n version: number\n build: { output: string; exportPath: string; payloadName: string }\n routes: ManifestRoute[]\n intercepts: ManifestIntercept[]\n /** Optional: a manifest from a build before api routes existed has none. */\n apis?: ManifestApiRoute[]\n}\n"]}
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,gFAAgF;AAChF,uCAAuC;AACvC,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,oBAAoB","sourcesContent":["// The shape of routes.json — what the build discovered, for a host to read.\n//\n// The build already walks app/ to generate its entries, and every host needs\n// the same facts: which url a component answers, what layouts wrap it, which\n// slots and sections belong to it. Laravel used to scan the tree a second time\n// to work that out; a JS host would have had to write a third walk. This is the\n// one answer, and these are its types.\n//\n// Urls are segments rather than a pattern string, because the pattern is the\n// host's dialect: Laravel writes {slug}, Hono writes :slug, and neither is the\n// build's business.\n\nexport interface RouteSegment {\n type: 'static' | 'param' | 'catchAll'\n value: string\n}\n\nexport interface ManifestRoute {\n component: string\n segments: RouteSegment[]\n layouts: string[]\n loadings: string[]\n /**\n * `error.tsx` files above this route, outermost first.\n *\n * The nearest one to a failure catches it, the same way the nearest\n * `loading.tsx` is the fallback. Optional: a manifest from a build before\n * error boundaries existed has none.\n */\n errors?: string[]\n /**\n * `middleware.ts` files above this route, outermost first.\n *\n * Run before anything at or below them renders, on every path. A check is\n * not UI, and making it a layout meant the client could decline it: layouts\n * are skipped on a partial navigation, and what gets skipped is named in a\n * header nothing can verify.\n */\n middleware: string[]\n slots: Record<string, string>\n sections: string[]\n /**\n * The host's route-config file beside this page, if it named one, and the\n * ancestor ones that also apply — outermost first, this page's excluded.\n *\n * Relative to the project root: an absolute path is true only on the machine\n * that produced it, and building in a container is ordinary.\n */\n config: string | null\n ancestorConfigs: string[]\n /**\n * Host middleware names for this route, outermost first.\n *\n * Declared in a route.ts beside or above the page. The engine does not know\n * what they mean — they are the host's own vocabulary — it only runs them\n * past the host before anything at or below this route renders.\n *\n * Empty on a route that named none, and on every route in an app that never\n * wrote a route.ts, which is why this needs no flag.\n *\n * Optional because registration boots from the PREVIOUS build's manifest: a\n * shape change takes two builds to settle, and a required field would make\n * the first of those a hard failure rather than a route with no guards.\n */\n hostMiddleware?: string[]\n /**\n * Whether the page exports generateStaticParams.\n *\n * Recorded here so a host can plan a build — which routes to ask for urls,\n * which to leave on demand — without loading the server bundle first. The\n * function itself is reached through the bundle's getStaticParams(), because\n * only the bundle can run it.\n */\n staticParams: boolean\n /**\n * Whether this route ships the client runtime.\n *\n * False renders to HTML and stops: no bootstrap, so no React, no Flight\n * client, no router. A client component on such a route is inert markup — a\n * button that does nothing — so the build refuses the combination rather\n * than shipping it.\n *\n * 'auto' when the page declares nothing: a route that freezes whole with no\n * client component and no server action in it is stored without the\n * bootstrap, because there is nothing for a runtime to do. `true` forces\n * the runtime onto such a page.\n */\n clientJs: boolean | 'auto'\n}\n\nexport interface ManifestIntercept {\n component: string\n slot: string\n segments: RouteSegment[]\n /** (.) same level, (..) one up, (...) from the root. */\n marker: string\n}\n\n/**\n * A `route.ts` — an api endpoint rather than a page.\n *\n * Separate from `routes` because it is matched before them and answered\n * without rendering anything: no layouts, no payload, no client. A url cannot\n * be both, and the build refuses one that is.\n */\nexport interface ManifestApiRoute {\n /** The module name, as the engine's registry keys it. */\n name: string\n segments: RouteSegment[]\n /** Which methods the file exports, so a 405 can name the rest. */\n methods: string[]\n /**\n * `middleware.ts` files above this route, outermost first.\n *\n * The same chain a page in that directory runs. A route.ts sits among the\n * pages it belongs with, so a guard on the directory covers it too —\n * anything else would mean adding an endpoint under a guarded path silently\n * opened a hole in it.\n */\n middleware: string[]\n}\n\nexport interface RouteManifest {\n version: number\n build: { output: string; exportPath: string; payloadName: string }\n routes: ManifestRoute[]\n intercepts: ManifestIntercept[]\n /** Optional: a manifest from a build before api routes existed has none. */\n apis?: ManifestApiRoute[]\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { ManifestRoute, RouteManifest } from './manifest.js';
2
+ export declare function withWorkerRegistration(html: string): string;
2
3
  export interface PrerenderEngine {
3
4
  manifest?(): RouteManifest;
4
5
  /**
@@ -60,6 +61,8 @@ export interface PrerenderEngine {
60
61
  body: string;
61
62
  rscPayload: string;
62
63
  clientComponents: string[];
64
+ /** A server action is in the tree - a form or a client prop - so a runtime is needed to submit it. */
65
+ serverReferences?: boolean;
63
66
  usedDynamicApis?: boolean;
64
67
  }>;
65
68
  handleRscPayload(component: string, props?: Record<string, unknown>, layouts?: {
@@ -71,6 +74,13 @@ export interface PrerenderEngine {
71
74
  }
72
75
  export interface PrerenderOptions {
73
76
  engine: PrerenderEngine;
77
+ /**
78
+ * The app has a service worker. A page stored without the bootstrap has
79
+ * nothing to register it, so one line is put in its place - the worker is
80
+ * for the second visit, and a visitor who lands on such a page first should
81
+ * still get one.
82
+ */
83
+ serviceWorker?: boolean;
74
84
  /**
75
85
  * Where the output goes, as a sink rather than a directory.
76
86
  *
@@ -141,6 +151,8 @@ export interface PrerenderResult {
141
151
  * page in the app shows the same thing while this one's data arrives.
142
152
  */
143
153
  warning?: string;
154
+ /** A fact about how it was stored that is neither a reason nor a warning. */
155
+ note?: string;
144
156
  }
145
157
  /**
146
158
  * The file name a route's shell is stored under, with params standing in for
package/dist/prerender.js CHANGED
@@ -41,6 +41,31 @@ const ROOT_FALLBACK_BUDGET_MS = 200;
41
41
  * fixtures, where six was enough to turn a two-second budget into a timeout.
42
42
  */
43
43
  const DEFAULT_PRERENDER_CONCURRENCY = 4;
44
+ /**
45
+ * The client components the engine itself puts around every page when the
46
+ * bootstrap is on - the segment and slot boundaries, the title, the pathname
47
+ * provider, the error boundary. They are in every payload, they are not the
48
+ * app's, and a render without the bootstrap does not insert them. Anything
49
+ * else in the list is the app's, and needs the runtime.
50
+ */
51
+ const RUNTIME_OWN = new Set([
52
+ 'DocumentTitle',
53
+ 'PathnameProvider',
54
+ 'RouteErrorBoundary',
55
+ 'SegmentBoundary',
56
+ 'SlotBoundary',
57
+ ]);
58
+ /**
59
+ * The one line the bootstrap would have run for the worker, for a document
60
+ * stored without a bootstrap. Same timing as the runtime's: after load, so
61
+ * it competes with nothing the first visit needs. A page whose document has
62
+ * no closing body tag is left alone.
63
+ */
64
+ const WORKER_REGISTRATION = "<script>'serviceWorker'in navigator&&addEventListener('load',function(){navigator.serviceWorker.register('/sw.js').catch(function(){})})</script>";
65
+ export function withWorkerRegistration(html) {
66
+ const at = html.lastIndexOf('</body>');
67
+ return at === -1 ? html : html.slice(0, at) + WORKER_REGISTRATION + html.slice(at);
68
+ }
44
69
  /**
45
70
  * The build's refusal to store a route it cannot answer ahead of time.
46
71
  *
@@ -555,8 +580,26 @@ export async function prerender(options) {
555
580
  return said('error', `ships no client runtime, but the tree renders ${rendered.clientComponents.join(', ')}. ` +
556
581
  'These usually come from a shared layout rather than the page itself.');
557
582
  }
583
+ // Nothing for a runtime to do. No client component means nothing to
584
+ // hydrate, and no server reference means no form that would post through
585
+ // React - so the bootstrap is 70 kB of javascript that runs and changes
586
+ // nothing. Rendered once more without it and stored that way. Only when
587
+ // the page declared nothing: `clientJs = true` keeps the runtime, for a
588
+ // page that wants the service worker or the update prompt regardless.
589
+ let note;
590
+ let body = rendered.body;
591
+ if (route.clientJs === 'auto' &&
592
+ rendered.clientComponents.every((name) => RUNTIME_OWN.has(name)) &&
593
+ !rendered.serverReferences) {
594
+ // Only the document. The flight payload stays the bootstrap render's:
595
+ // a Link elsewhere navigating here fetches it and expects the segment
596
+ // and title wrappers that render puts in, which this one leaves out.
597
+ const bare = await engine.handleRsc(route.component, props, null, layouts, route.loadings, route.slots, 0, url, false, false);
598
+ body = options.serviceWorker ? withWorkerRegistration(bare.body) : bare.body;
599
+ note = 'no client components, so ships no javascript';
600
+ }
558
601
  const key = pathKey(url);
559
- await write(`${key}.html`, rendered.body);
602
+ await write(`${key}.html`, body);
560
603
  await write(`${key}.flight`, rendered.rscPayload);
561
604
  // One variant per depth the client might already hold. Without them every
562
605
  // navigation to a prerendered route is a whole document, which replaces the
@@ -568,7 +611,8 @@ export async function prerender(options) {
568
611
  await write(`${key}.seg${depth}.flight`, rscPayload);
569
612
  }
570
613
  await write(`${key}.meta.json`, JSON.stringify({ layouts: route.layouts, component: route.component, version: version ?? null }, null, 2));
571
- return noteNondeterminism(await withRootFallbackChecked(said('frozen', null)));
614
+ const frozen = noteNondeterminism(await withRootFallbackChecked(said('frozen', null)));
615
+ return note ? { ...frozen, note } : frozen;
572
616
  }
573
617
  /**
574
618
  * Freeze a shell, under the url when it is one and under the route's pattern
@@ -1 +1 @@
1
- {"version":3,"file":"prerender.js","sourceRoot":"","sources":["../src/prerender.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,4EAA4E;AAC5E,yEAAyE;AACzE,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,8CAA8C;AAC9C,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,4DAA4D;AA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,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAA;QACrE,MAAM,GAAG,GAAG,aAAa,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAEnF,MAAM,KAAK,CAAC,GAAG,GAAG,WAAW,EAAE,IAAI,CAAC,CAAA;QAEpC,sEAAsE;QACtE,0EAA0E;QAC1E,0EAA0E;QAC1E,uBAAuB;QACvB,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,KAAK,CAAC,GAAG,GAAG,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAA;QACjE,CAAC;QACD,MAAM,KAAK,CACT,GAAG,GAAG,gBAAgB,EACtB,IAAI,CAAC,SAAS,CACZ,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,EAC/F,IAAI,EACJ,CAAC,CACF,CACF,CAAA;IACH,CAAC;AAEH,CAAC","sourcesContent":["// Rendering pages at build time, for a JavaScript host.\n//\n// The engine does the rendering; this decides what to render and what to do\n// with the result. Two decisions, and both are easy to get subtly wrong:\n//\n// Which urls exist — a route with no params is one url, a route with params is\n// however many `generateStaticParams` returns, and a route with params that\n// declares none cannot be prerendered at all.\n//\n// Whether a page can be frozen — asked by rendering it, never declared. The\n// shell probe replaces the host global with a promise that never resolves, so\n// a page that reaches for request data suspends and says so by doing it. A\n// page that simply takes too long says so by not finishing.\n//\n// The file layout matches the one Laravel writes, so both hosts serve the same\n// shapes and anything that reads them works for either.\n\nimport type { ManifestRoute, RouteManifest } from './manifest.js'\nimport { withRedirect } from './redirect.js'\nimport { withCache } from './cache.js'\nimport { requestReadBy, requestWasRead, withRequest } from './request.js'\nimport { watchNondeterminism, whileRendering } from './nondeterminism.js'\n\n/** What a prerenderer needs from the built bundle, beyond serving a request. */\n/**\n * How long the root-fallback diagnostic waits before answering.\n *\n * Short on purpose: the question is whether anything painted, not what. See\n * the call site.\n */\nconst ROOT_FALLBACK_BUDGET_MS = 200\n\n/**\n * How many routes render at once.\n *\n * Each is a full React render, so this trades memory and CPU for wall time.\n * The gain flattens almost immediately — measured on a twelve-route example:\n * 10.2 s sequential, 4.1 s at four, 4.0 s at six, 4.0 s at twelve, beyond\n * which one route's own serial chain is the floor.\n *\n * Four rather than six because the difference between them is inside the\n * noise, and the smaller number leaves room for whatever else is running.\n * A build is rarely the only thing on a machine — it shares CI with other\n * jobs, and it shares a laptop with the test suite that renders its own\n * fixtures, where six was enough to turn a two-second budget into a timeout.\n */\nconst DEFAULT_PRERENDER_CONCURRENCY = 4\n\nexport interface PrerenderEngine {\n manifest?(): RouteManifest\n /**\n * A route.ts, answered. Optional: a bundle built before api routes existed\n * has none, and the build then simply stores no route.\n */\n handleApiRoute?(\n name: string,\n request: Request,\n params: Record<string, string>,\n allow: string,\n ): Promise<Response>\n getStaticParams?(component: string): Promise<Record<string, string>[] | null>\n handleRscPprShell(\n component: string,\n props?: Record<string, unknown>,\n layouts?: { component: string; props: Record<string, unknown> }[],\n loadings?: string[],\n parallelSlots?: Record<string, string>,\n pageKey?: string,\n /** How long to render before taking what has flushed. Defaults to the full budget. */\n budgetMs?: number,\n ): Promise<{\n shellHtml: string\n timedOut: boolean\n usedDynamicApis: boolean\n /**\n * The host calls this render made, by name.\n *\n * So the build can say which one kept the page from being frozen rather\n * than only that something did. Optional: an engine built before this\n * existed reports nothing, and the line is printed without a reason.\n */\n dynamicBecause?: string[]\n error?: string\n /**\n * Where the render stopped, when it stopped — React's own resumable state.\n *\n * Null when the page finished, which is the same thing as `timedOut` being\n * false. An engine built before this existed returns undefined, and the\n * shell is then served the way it always was: holes filled by the client\n * after hydration rather than resumed at the origin.\n */\n postponed?: unknown\n /**\n * Anything that failed while producing the shell, including a rejection a\n * Suspense boundary caught.\n *\n * Such a rejection never reaches the caller: React keeps the fallback and\n * the render finishes, so without this a page whose data source was\n * unreachable looked complete and its loading state was frozen as a\n * finished page.\n */\n renderFailure?: string\n }>\n handleRsc(\n component: string,\n props?: Record<string, unknown>,\n callbackSocket?: string | null,\n layouts?: { component: string; props: Record<string, unknown> }[],\n loadings?: string[],\n parallelSlots?: Record<string, string>,\n from?: number,\n pageKey?: string,\n bootstrap?: boolean,\n /**\n * Whether a host is installed to answer rpc().\n *\n * False during a build, where there is none: every host call then suspends\n * and the page reports that it reached for one, instead of resolving to\n * undefined and being frozen holding it.\n */\n canReachHost?: boolean,\n ): Promise<{\n body: string\n rscPayload: string\n clientComponents: string[]\n usedDynamicApis?: boolean\n }>\n handleRscPayload(\n component: string,\n props?: Record<string, unknown>,\n layouts?: { component: string; props: Record<string, unknown> }[],\n loadings?: string[],\n parallelSlots?: Record<string, string>,\n from?: number,\n pageKey?: string,\n ): Promise<{ rscPayload: string }>\n}\n\nexport interface PrerenderOptions {\n engine: PrerenderEngine\n /**\n * Where the output goes, as a sink rather than a directory.\n *\n * `writeTo` in `@rsc-kit/core/files` is the one for a disk, which is what a\n * build normally wants. A function because the read side is one — a host\n * that supplies a reader should be able to supply the matching writer —\n * and because a test can hand it a Map instead of a temp directory.\n */\n write: (name: string, contents: string) => Promise<void> | void\n /** The route table. Defaults to the one the bundle carries. */\n manifest?: RouteManifest\n /**\n * Props for a page at build time.\n *\n * There is no request here, which is the point: anything a page needs that\n * only a request can supply is exactly what makes it un-freezable. Defaults\n * to the url params alone.\n */\n props?: (route: ManifestRoute, params: Record<string, string>) => Record<string, unknown>\n /**\n * How many routes to render at once. Defaults to 6; 1 renders sequentially.\n *\n * Worth lowering when the pages talk to something that will not enjoy six\n * concurrent callers — a local database, a rate-limited API.\n */\n concurrency?: number\n /** Identifies the build in what gets written, so a stale page can be spotted. */\n version?: string\n /** Called as each url is decided, for build output. */\n onResult?: (result: PrerenderResult) => void\n}\n\n/**\n * The build's refusal to store a route it cannot answer ahead of time.\n *\n * Thrown rather than reported, because the alternative is a category: a bucket\n * of routes that quietly render per request, which is where the slow ones go\n * to be forgotten. Every route is either stored or has said it will not be.\n */\nexport class NotPrerenderable extends Error {\n public readonly routes: PrerenderResult[]\n\n constructor(routes: PrerenderResult[]) {\n // Two different problems arrive here, and the advice for one is useless for\n // the other. A page that reads the request above every boundary needs a\n // boundary; a page whose render threw needs whatever it was reaching for.\n const threw = routes.filter((r) => r.reason?.startsWith('could not be rendered'))\n const unpaintable = routes.filter((r) => !r.reason?.startsWith('could not be rendered'))\n\n const advice: string[] = []\n\n if (unpaintable.length > 0) {\n advice.push(\n 'These read request data — params, headers, cookies, or the host — above\\n' +\n 'every Suspense boundary, so nothing can paint without it:\\n\\n' +\n unpaintable.map((r) => ` ${r.url} — ${r.reason ?? 'nothing to paint'}`).join('\\n') +\n '\\n\\nPut the part that waits inside <Suspense>, or add a loading.tsx beside\\n' +\n 'the page, so there is something to store while the rest arrives.',\n )\n }\n\n if (threw.length > 0) {\n advice.push(\n 'These failed while rendering:\\n\\n' +\n threw.map((r) => ` ${r.url} — ${r.reason}`).join('\\n') +\n '\\n\\nPrerendering runs your application code, so it needs whatever that code\\n' +\n 'needs. If the page is fine and this machine simply cannot reach a\\n' +\n 'database or an API, either give the build access or turn prerendering\\n' +\n 'off with `rscKit({ prerender: false })`.\\n\\n' +\n 'Reaching for data through the host — `await rpc(...)` — avoids this\\n' +\n 'entirely: the build stubs that call, so the page freezes a shell\\n' +\n 'without the data being available.',\n )\n }\n\n super('Some routes could not be prerendered.\\n\\n' + advice.join('\\n\\n') + '\\n')\n this.name = 'NotPrerenderable'\n this.routes = routes\n\n // Not enumerable: Vite prints an error's own properties under its stack,\n // and this list is the message again, as an object dump.\n Object.defineProperty(this, 'routes', { value: routes, enumerable: false })\n }\n}\n\nexport interface PrerenderResult {\n url: string\n component: string\n /**\n * frozen — the whole page is on disk.\n * shell — the chrome is on disk and the rest is rendered per request.\n * blocked — nothing could be stored. Fails the build.\n * error — the render itself failed, or the build refused what it produced.\n *\n * dynamic — answered per request, and correctly so. Api routes only.\n *\n * There is no such outcome for a PAGE. A page that cannot be stored has its\n * boundary in the wrong place, and the fix is to move it — not to declare\n * the problem away, which is how the slow ones get forgotten. An api route\n * has no boundary to move: it either depends on the request or it does not,\n * and depending on it is the ordinary case rather than a mistake.\n */\n type: 'frozen' | 'shell' | 'blocked' | 'error' | 'dynamic'\n reason: string | null\n /**\n * Something worth knowing that is not a failure.\n *\n * The one that matters: a page whose only boundary is the root loading.tsx.\n * It is stored, so the build has nothing to refuse — but the fallback that\n * caught it belongs to the whole app rather than to this page, and every\n * page in the app shows the same thing while this one's data arrives.\n */\n warning?: string\n}\n\n/**\n * The file name a route's shell is stored under, with params standing in for\n * themselves: /posts/[slug] → posts/_slug_.\n *\n * A shell contains nothing that varies by param — everything that does is\n * behind a boundary the client fills — so one shell serves every url the\n * route matches, including the ones the app never listed.\n */\nexport function patternKey(route: ManifestRoute): string {\n const parts = route.segments.map((s) => (s.type === 'static' ? s.value : `_${s.value}_`))\n\n return parts.join('/') || 'index'\n}\n\n/** Close a document the render was aborted in the middle of. */\nexport function closeDocument(html: string): string {\n let out = html\n\n if (!/<\\/body>/i.test(out) && /<body/i.test(out)) out += '</body>'\n if (!/<\\/html>/i.test(out) && /<html/i.test(out)) out += '</html>'\n\n return out\n}\n\n/**\n * The file name a url is stored under: / → index, /a/b → a/b.\n *\n * Refuses a key that could leave the directory it is written into. The input is\n * whatever generateStaticParams() returned — typically slugs from a database or\n * a CMS — so a record named `../../../../etc/cron.d/x` is an arbitrary file\n * write on the build machine with content the same record influences.\n *\n * Checked here rather than in the writer, because the writer is supplied by the\n * host: `writeTo` on disk does the obvious thing, but a KV or edge binding has\n * no notion of a parent directory and no reason to look for one.\n */\n/**\n * The key, showing only the marks that actually appear above it.\n *\n * Wording follows Next's build output deliberately. Most people arriving here\n * have read that legend already, and inventing a second vocabulary for the same\n * three states costs them a translation for nothing.\n */\nexport function legend(results: { type: string }[]): string {\n const has = (type: string) => results.some((r) => r.type === type)\n const lines: string[] = []\n\n if (has('frozen')) {\n lines.push(' \\u25CB (Static) prerendered as static content')\n }\n\n if (has('shell')) {\n lines.push(\n ' \\u25D0 (Partial Prerender) prerendered as static HTML with dynamic server-streamed content',\n )\n }\n\n if (has('dynamic')) {\n lines.push(' \\u0192 (Dynamic) server-rendered on demand')\n }\n\n if (has('error') || has('blocked')) {\n lines.push(' \\u2717 (Failed) did not render, or painted nothing — the build stops here')\n }\n\n return lines.join('\\n')\n}\n\n/**\n * How much JavaScript a route makes the browser download.\n *\n * Gzipped, because that is what crosses the wire — uncompressed bytes are a\n * number nobody is served.\n *\n * A real per-route figure only because client components are chunked per\n * module. Grouped the way plugin-rsc groups them by default, every route in an\n * app loads every client component and this column is one number repeated down\n * the page.\n */\nexport function clientJsSize(bytes: number): string {\n if (bytes === 0) return 'no js'\n\n const kb = bytes / 1000\n\n return `${kb < 10 ? kb.toFixed(1) : Math.round(kb)} kB`\n}\n\n/**\n * The paragraph a mark cannot hold.\n *\n * \"dynamic — called rpc(\\\"getUser\\\")\" says what happened and not why the build\n * could not simply make the call, which is the first thing someone asks when a\n * page they expected to be static is not. The backend is running; the build is\n * not talking to it.\n *\n * Printed once under the summary rather than beside each route: an app where\n * every page reads from the backend would otherwise repeat the same paragraph\n * forty times.\n */\nexport function notes(results: { type?: string; reason?: string | null }[]): string {\n const said = (text: string) => results.some((r) => r.reason?.includes(text))\n const parts: string[] = []\n\n // Every route not frozen, all for one reason, is the shape a read in the\n // root layout leaves: one cookies() in a header component and nothing on\n // the site can be stored. The build cannot see which component read it -\n // only that every page did - so it says what that usually means.\n const pages = results.filter((r) => r.type && r.type !== 'error' && r.type !== 'blocked')\n const reasons = new Set(pages.map((r) => r.reason ?? ''))\n\n if (pages.length > 1 && !pages.some((r) => r.type === 'frozen') && reasons.size === 1) {\n const [reason] = reasons\n\n parts.push(\n ` Every route ${reason}. When one read makes every page dynamic it is usually\\n` +\n ' in the root layout - a header reading the session, a locale from a cookie.\\n' +\n ' Move that read into the component that needs it, under a <Suspense>, and\\n' +\n ' the rest of the site can freeze around it.',\n )\n }\n\n if (said('rpc(')) parts.push(rpcNote())\n\n return parts.join('\\n\\n')\n}\n\nfunction rpcNote(): string {\n return (\n ' A build has no backend to call. rpc() suspends instead of answering, so a page\\n' +\n ' that reads through one ships a shell and finishes for whoever asks — which is\\n' +\n ' almost always what you want, since that data is rarely the same for everyone.\\n' +\n '\\n' +\n ' If a page really should be frozen, move the read out of rpc(). If it really\\n' +\n ' should be per visitor, say so with await connection() and the intent is on the\\n' +\n ' page rather than inferred from a call that happened to suspend.'\n )\n}\n\n/**\n * The one-line tally under the legend, in the legend's own words.\n */\nexport function summary(results: { type: string }[]): string {\n const count = (type: string) => results.filter((r) => r.type === type).length\n const parts: string[] = []\n\n if (count('frozen')) parts.push(`${count('frozen')} static`)\n if (count('shell')) parts.push(`${count('shell')} partial prerender`)\n if (count('dynamic')) parts.push(`${count('dynamic')} dynamic`)\n if (count('error') + count('blocked')) parts.push(`${count('error') + count('blocked')} failed`)\n\n return parts.join(', ') || 'nothing to store'\n}\n\nexport function pathKey(url: string): string {\n const key = url.replace(/^\\/+|\\/+$/g, '') || 'index'\n\n if (key.split('/').some((segment) => segment === '..' || segment === '.')) {\n throw new Error(\n 'Refusing to store ' + JSON.stringify(url) + ': the path leaves the output directory. ' +\n 'A url segment came from generateStaticParams() or a route param and contains \"..\".',\n )\n }\n\n return key\n}\n\n/**\n * Substitute params into a route's segments to get a concrete url.\n *\n * A param is one segment, so a value carrying a slash is not a deeper url — it\n * is a value that was never a single segment. A catch-all is the exception and\n * is spelled as one in the route.\n */\nexport function urlFor(route: ManifestRoute, params: Record<string, string>): string {\n const parts = route.segments.map((segment) => {\n if (segment.type === 'static') return segment.value\n\n const value = params[segment.value] ?? ''\n\n if (segment.type !== 'catchAll' && /[/\\\\]/.test(value)) {\n throw new Error(\n 'The ' + segment.value + ' param is ' + JSON.stringify(value) + ', which is not one url ' +\n 'segment. A value with a slash in it has to be a catch-all route, or be encoded.',\n )\n }\n\n return value\n })\n\n return '/' + parts.filter((p) => p !== '').join('/')\n}\n\n/**\n * Every url this build should attempt, and the params each was built from.\n *\n * A parameterised route that declares no `generateStaticParams` yields\n * nothing — not an error: rendering on demand is a legitimate answer, and the\n * alternative is guessing at slugs the app never listed.\n */\n/** Stand-in values for a route whose real urls were never listed. */\nfunction placeholders(route: ManifestRoute): Record<string, string> {\n const params: Record<string, string> = {}\n\n for (const segment of route.segments) {\n if (segment.type !== 'static') params[segment.value] = '_'\n }\n\n return params\n}\n\nexport async function urlsToBuild(\n manifest: RouteManifest,\n engine: PrerenderEngine,\n): Promise<{ route: ManifestRoute; params: Record<string, string>; url: string }[]> {\n const entries: { route: ManifestRoute; params: Record<string, string>; url: string }[] = []\n\n for (const route of manifest.routes) {\n const parameterised = route.segments.some((s) => s.type !== 'static')\n\n if (!parameterised) {\n entries.push({ route, params: {}, url: urlFor(route, {}) })\n continue\n }\n\n // A route that lists no urls still gets one attempt, with placeholder\n // params, so it can ship a shell. Nothing in a shell varies by param.\n if (!route.staticParams) {\n entries.push({ route, params: placeholders(route), url: urlFor(route, placeholders(route)) })\n continue\n }\n\n const sets = (await engine.getStaticParams?.(route.component)) ?? null\n\n // Null means the route declares none, so it is rendered on demand. An\n // empty array means the app looked and there is nothing to build — both\n // produce no files, and only one of them is a mistake to warn about.\n if (!sets) continue\n\n for (const params of sets) {\n entries.push({ route, params, url: urlFor(route, params) })\n }\n }\n\n return entries\n}\n\nexport async function prerender(options: PrerenderOptions): Promise<PrerenderResult[]> {\n const { engine, write, version } = options\n const manifest = options.manifest ?? engine.manifest?.()\n\n if (!manifest) {\n throw new Error('No route table. Pass `manifest`, or build with a plugin version that embeds one.')\n }\n\n const entries = await urlsToBuild(manifest, engine)\n const results: PrerenderResult[] = new Array(entries.length)\n\n // Rendered a few at a time rather than one after another.\n //\n // Most of a build is this loop, and most of this loop is waiting: a page\n // whose shell is decided by a two-second budget spends two seconds doing\n // nothing while the next page waits its turn. Nothing here is shared between\n // routes — the probe's stand-in host is held in async context, so concurrent\n // renders cannot see each other's — which is what makes overlapping them\n // safe, and was not true until it was scoped.\n //\n // Bounded, because each one is a full React render: unbounded would turn a\n // large site into as many concurrent renders as it has pages.\n //\n // Results are placed by index, so what a build reports does not depend on\n // which page happened to finish first.\n const concurrency = Math.max(1, options.concurrency ?? DEFAULT_PRERENDER_CONCURRENCY)\n let next = 0\n\n const worker = async () => {\n while (true) {\n const index = next++\n\n if (index >= entries.length) return\n\n const { route, params, url } = entries[index]\n\n results[index] = await prerenderOne(route, params, url)\n options.onResult?.(results[index])\n }\n }\n\n const unwatch = watchNondeterminism()\n\n try {\n await Promise.all(Array.from({ length: Math.min(concurrency, entries.length) }, worker))\n } finally {\n unwatch()\n }\n\n const refused = results.filter((r) => r.type === 'blocked')\n\n if (refused.length > 0) {\n throw new NotPrerenderable(refused)\n }\n\n return results\n\n async function prerenderOne(\n route: ManifestRoute,\n params: Record<string, string>,\n url: string,\n ): Promise<PrerenderResult> {\n const props = options.props ? options.props(route, params) : params\n const layouts = route.layouts.map((component) => ({ component, props: {} }))\n const unlistedNow = route.segments.some((seg) => seg.type !== 'static') && !route.staticParams\n /**\n * Why this route ships a shell rather than a whole page.\n *\n * In the order that answers the question soonest. A named call is the most\n * actionable — you can go and look at it — so it wins over the two\n * structural reasons, either of which may also be true.\n */\n const shellReason = (calls: string[]): string | null => {\n if (calls.length) return 'dynamic — called ' + calls.join(', ')\n\n // One shell serving every url the route matches. generateStaticParams is\n // what turns it into a page per url.\n if (unlistedNow) return 'one shell for every url — add generateStaticParams to store each'\n\n // Nothing reached for the request; the data simply took too long. The\n // page is fine, it just finishes per visitor.\n if (shell?.timedOut) return 'data took longer than the build budget'\n\n return null\n }\n\n const said = (type: PrerenderResult['type'], reason: string | null): PrerenderResult => ({\n // A route standing in for many urls reports the pattern. Reporting the\n // placeholder url instead prints `/posts/_`, which looks like a page.\n url: unlistedNow ? '/' + patternKey(route) : url,\n component: route.component,\n type,\n reason,\n })\n\n const unlisted = route.segments.some((seg) => seg.type !== 'static') && !route.staticParams\n\n // Classify by rendering, never by asking. The probe is cheap and cannot\n // hang: anything still suspended when its budget expires is the answer.\n //\n // Wrapped so a redirect has somewhere to be recorded. Reading the scope\n // rather than inspecting the thrown error is the only thing that works\n // from out here: React catches what a component throws and re-raises its\n // own, whose message is stripped in production — so a redirect above the\n // boundaries arrives as a generic render failure, and one from inside a\n // boundary never arrives at all.\n // A build renders each url once, and each gets its own table: two routes\n // must not share an answer just because they were built in the same run.\n // No request, deliberately: a page that reads one is caught below rather\n // than frozen holding whatever the build machine happened to send.\n const [{ shell, redirected, readRequest, readBy }, nondeterministic] = await whileRendering(() =>\n withRequest(null, () =>\n withCache(() => withRedirect(async (taken) => {\n try {\n return {\n shell: await engine.handleRscPprShell(\n route.component,\n props,\n layouts,\n route.loadings,\n route.slots,\n // Only when this shell serves one url. A parameterised route's\n // shell is shared, so baking a url into it would put the wrong one\n // on every page but the one that happened to be built.\n unlistedNow ? '' : url,\n ),\n redirected: taken(),\n readRequest: requestWasRead(),\n // What reached for it, so the build can name the call rather than\n // only report that the page is dynamic.\n readBy: requestReadBy(),\n }\n } catch (error) {\n // A guard refusing throws out of the probe rather than being caught\n // inside it: middleware run before the render, so there is no render yet\n // to capture the failure. A refusal is a classification, not a build\n // error — the route is one that cannot be frozen.\n const refused = taken()\n\n if (!refused) throw error\n\n return { shell: null, redirected: refused, readRequest: requestWasRead(), readBy: requestReadBy() }\n }\n })),\n ),\n )\n\n // A page that leaves rather than renders is not a build failure, and it is\n // not something to freeze either: what would be stored is the redirect's\n // own emptiness, served for ever to everyone. Rendered on demand instead,\n // where the redirect can actually happen.\n /**\n * Did this page's own boundary catch the wait, or the app's?\n *\n * A root loading.tsx wraps every page, so a page that blocks — or throws,\n * which is how a client hook says it has no server answer — is caught\n * whatever it does. The route is stored either way and the build has\n * nothing to refuse, which makes a page whose boundary is in the wrong\n * place look exactly like one whose boundary is right.\n *\n * Asked by rendering again without the root fallback, and only for a route\n * that has no closer one.\n *\n * Only for a route that came out as a shell. A frozen one rendered to\n * completion with the root boundary present, and removing a boundary\n * cannot stop a render that already finished — so the second probe\n * finishes too, its markup is the whole document, and the emptiness test\n * cannot fire. It was being paid for anyway: a second full render of every\n * frozen page, which on a site whose pages are mostly frozen is most of\n * the prerender.\n */\n async function withRootFallbackChecked(result: PrerenderResult): Promise<PrerenderResult> {\n if (result.type !== 'shell') return result\n if (route.loadings.length !== 1 || !engine.handleRscPprShell) return result\n\n // A tenth of the shell budget, because this is a different question.\n //\n // Deciding what a page's shell IS means waiting out everything that can\n // resolve. Asking whether anything paints at all without the root\n // fallback is a boolean about the first flush — and a page that paints,\n // paints immediately. Given the full budget it cost two seconds a route\n // to learn what the first millisecond already said, which on this\n // example was 40% of the entire prerender.\n const withoutRoot = await withRequest(null, () =>\n withCache(() =>\n withRedirect(async () =>\n engine.handleRscPprShell(\n route.component,\n props,\n layouts,\n [],\n route.slots,\n url,\n ROOT_FALLBACK_BUDGET_MS,\n ),\n ),\n ),\n ).catch(() => null)\n\n if (withoutRoot && closeDocument(withoutRoot.shellHtml.trim()) === '') {\n result.warning =\n 'nothing painted without the root loading.tsx — the fallback the whole app shares ' +\n 'is standing in for this page. Put a boundary where the waiting is.'\n }\n\n return result\n }\n\n // A route that only redirects still has an answer to freeze — the answer\n // is the redirect, not a page. Rendering it per request re-derives a\n // constant, and on a static host there would be nothing to derive it with.\n if (redirected) {\n await write(\n `${pathKey(url)}.redirect.json`,\n JSON.stringify({ status: redirected.status, location: redirected.location }),\n )\n\n return said('frozen', `redirects to ${redirected.location}`)\n }\n\n if (!shell) return said('error', 'refused before it rendered')\n\n if (shell.error) return said('error', shell.error)\n\n // Something failed while rendering. Not necessarily the page's fault — a\n // build machine that cannot reach the database produces this, and so does a\n // genuinely broken component — so it is not fatal. It is simply not\n // something to freeze: whatever this render produced is a failure state,\n // and freezing it serves that state to everyone until the next build.\n //\n // Rendering per request is the honest answer. It works as soon as whatever\n // was missing is reachable, which at runtime it usually is.\n if (shell.renderFailure) {\n return said('blocked', `could not be rendered at build time: ${shell.renderFailure}`)\n }\n\n // A timeout is the ordinary path for a page that streams, not a failure:\n // the probe hands the page a host global that never resolves, React\n // flushes everything that does not depend on it, and the abort happens\n // once there is nothing left to flush. So the captured markup IS the\n // shell — layouts, static content, and the fallbacks standing in for what\n // has not arrived.\n if (shell.timedOut) {\n const body = closeDocument(shell.shellHtml.trim())\n\n // Nothing was flushed before the page blocked, so there is no shell to\n // ship — a page that blocks above every boundary can only be rendered on\n // demand. `reaches for the host` is the specific reason when both are\n // true; a page that merely ran long says the other thing.\n if (body === '') {\n return said(\n 'blocked',\n (readRequest\n ? 'reads the request'\n : shell.usedDynamicApis\n ? 'reaches for the host'\n : 'blocks') +\n ' before anything can paint. Add a loading.tsx beside it, or put a ' +\n '<Suspense> above the waiting, and it has a skeleton to store.',\n )\n }\n\n await writeShell(route, url, body, shell.postponed)\n\n // Why it is a shell rather than a whole page. \"◐ /orders\" on its own\n // leaves someone reading the build output to guess what did it, which is\n // the question this line exists to answer.\n const calls = [...(shell.dynamicBecause ?? []), ...(readBy ?? [])]\n\n return await withRootFallbackChecked(said('shell', shellReason(calls)))\n }\n\n // Warned, not refused.\n //\n // A frozen `new Date()` may be exactly what the author meant — a build\n // stamp, a copyright year — and the build cannot tell that from a\n // \"3 minutes ago\" that will still say three minutes next month. Refusing\n // would make the honest case unbuildable in order to protect the careless\n // one, and there is no flag to add here without inventing the declaration\n // this design exists to avoid.\n //\n // So it says what happened, names what was called, and gives the repair.\n // The escape hatch is that a warning does not stop the build — which is the\n // right weight for something that is occasionally correct.\n //\n // Only for a page frozen WHOLE. On a shell the call may sit inside a hole,\n // which renders per request, where it is correct.\n const noteNondeterminism = (result: PrerenderResult): PrerenderResult => {\n if (nondeterministic.length === 0) return result\n\n result.warning =\n `froze ${nondeterministic.join(' and ')} — a stored page keeps whatever that ` +\n 'returned at build time. If it should differ per visitor, await connection() so ' +\n 'the page renders per request; if only the browser needs it, use(browser()) keeps ' +\n 'it out of the build entirely.'\n\n return result\n }\n\n // Rendered whole, with params that were invented because the route listed\n // none. Freezing that stores a page whose id is literally `_`, and a shell\n // is no better: the value is in the markup rather than behind a boundary\n // the client fills. A route reaches this only by rendering its params\n // before it can paint, which is exactly the shape that cannot be shared\n // across urls.\n if (unlisted) {\n return said('blocked', 'renders its params before it can paint, and lists no urls to build')\n }\n\n const shipsJs = route.clientJs !== false\n\n const rendered = await engine.handleRsc(\n route.component,\n props,\n null,\n layouts,\n // Not empty: a page whose layout declares a parallel slot renders without\n // it otherwise, and nothing says so — the page comes out whole apart from\n // the missing region.\n route.loadings,\n route.slots,\n 0,\n url,\n shipsJs,\n // A build has no host to answer rpc(), so every host call must suspend\n // rather than resolve. Without this they found no host at all and the\n // page was frozen holding whatever undefined rendered to — a document\n // that looks right, hydrates against an undefined prop, and blanks.\n false,\n )\n\n // The render reached for the host, so its data is not the same for\n // everyone and there is no build-time answer for it. Not frozen: a shell\n // is shipped instead and the page finishes for whoever asks.\n if (rendered.usedDynamicApis) {\n return said('shell', 'reaches the host for data')\n }\n\n // A client component without a runtime is inert markup — a button that\n // does nothing. Refused rather than shipped, and named, because they are\n // usually inherited from a shared layout rather than written on the page.\n if (!shipsJs && rendered.clientComponents.length > 0) {\n return said(\n 'error',\n `ships no client runtime, but the tree renders ${rendered.clientComponents.join(', ')}. ` +\n 'These usually come from a shared layout rather than the page itself.',\n )\n }\n\n const key = pathKey(url)\n\n await write(`${key}.html`, rendered.body)\n await write(`${key}.flight`, rendered.rscPayload)\n\n // One variant per depth the client might already hold. Without them every\n // navigation to a prerendered route is a whole document, which replaces the\n // root and unmounts the pages retained behind it — so going back does not\n // restore the form you were filling in. Most routes in a real app are\n // prerendered, which makes this the common path rather than an edge case.\n for (let depth = 1; depth <= route.layouts.length; depth++) {\n const { rscPayload } = await engine.handleRscPayload(\n route.component,\n props,\n layouts,\n route.loadings,\n route.slots,\n depth,\n url,\n )\n\n await write(`${key}.seg${depth}.flight`, rscPayload)\n }\n\n await write(\n `${key}.meta.json`,\n JSON.stringify({ layouts: route.layouts, component: route.component, version: version ?? null }, null, 2),\n )\n\n return noteNondeterminism(await withRootFallbackChecked(said('frozen', null)))\n }\n\n /**\n * Freeze a shell, under the url when it is one and under the route's pattern\n * when it stands for many.\n *\n * A route whose urls were never listed still gets a shell: nothing in it\n * varies by param, so the same markup is correct for every url the route\n * matches. That is most of the value — the routes you can enumerate are the\n * ones you could already freeze whole.\n */\n async function writeShell(\n route: ManifestRoute,\n url: string,\n body: string,\n postponed?: unknown,\n ): Promise<void> {\n const parameterised = route.segments.some((s) => s.type !== 'static')\n const key = parameterised && !route.staticParams ? patternKey(route) : pathKey(url)\n\n await write(`${key}.ppr.html`, body)\n\n // Written only when there is something to resume from. Its absence is\n // meaningful rather than incidental: a host that finds no postponed state\n // serves the shell and lets the client fill it, which is what every build\n // before this one did.\n if (postponed != null) {\n await write(`${key}.postponed.json`, JSON.stringify(postponed))\n }\n await write(\n `${key}.ppr-meta.json`,\n JSON.stringify(\n { layouts: route.layouts, component: route.component, parameterised, version: version ?? null },\n null,\n 2,\n ),\n )\n }\n\n}\n"]}
1
+ {"version":3,"file":"prerender.js","sourceRoot":"","sources":["../src/prerender.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,4EAA4E;AAC5E,yEAAyE;AACzE,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,8CAA8C;AAC9C,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,4DAA4D;AAC5D,EAAE;AACF,+EAA+E;AAC/E,wDAAwD;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,aAA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AAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAA;QACrE,MAAM,GAAG,GAAG,aAAa,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAEnF,MAAM,KAAK,CAAC,GAAG,GAAG,WAAW,EAAE,IAAI,CAAC,CAAA;QAEpC,sEAAsE;QACtE,0EAA0E;QAC1E,0EAA0E;QAC1E,uBAAuB;QACvB,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,KAAK,CAAC,GAAG,GAAG,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAA;QACjE,CAAC;QACD,MAAM,KAAK,CACT,GAAG,GAAG,gBAAgB,EACtB,IAAI,CAAC,SAAS,CACZ,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,EAC/F,IAAI,EACJ,CAAC,CACF,CACF,CAAA;IACH,CAAC;AAEH,CAAC","sourcesContent":["// Rendering pages at build time, for a JavaScript host.\n//\n// The engine does the rendering; this decides what to render and what to do\n// with the result. Two decisions, and both are easy to get subtly wrong:\n//\n// Which urls exist — a route with no params is one url, a route with params is\n// however many `generateStaticParams` returns, and a route with params that\n// declares none cannot be prerendered at all.\n//\n// Whether a page can be frozen — asked by rendering it, never declared. The\n// shell probe replaces the host global with a promise that never resolves, so\n// a page that reaches for request data suspends and says so by doing it. A\n// page that simply takes too long says so by not finishing.\n//\n// The file layout matches the one Laravel writes, so both hosts serve the same\n// shapes and anything that reads them works for either.\n\nimport type { ManifestRoute, RouteManifest } from './manifest.js'\nimport { withRedirect } from './redirect.js'\nimport { withCache } from './cache.js'\nimport { requestReadBy, requestWasRead, withRequest } from './request.js'\nimport { watchNondeterminism, whileRendering } from './nondeterminism.js'\n\n/** What a prerenderer needs from the built bundle, beyond serving a request. */\n/**\n * How long the root-fallback diagnostic waits before answering.\n *\n * Short on purpose: the question is whether anything painted, not what. See\n * the call site.\n */\nconst ROOT_FALLBACK_BUDGET_MS = 200\n\n/**\n * How many routes render at once.\n *\n * Each is a full React render, so this trades memory and CPU for wall time.\n * The gain flattens almost immediately — measured on a twelve-route example:\n * 10.2 s sequential, 4.1 s at four, 4.0 s at six, 4.0 s at twelve, beyond\n * which one route's own serial chain is the floor.\n *\n * Four rather than six because the difference between them is inside the\n * noise, and the smaller number leaves room for whatever else is running.\n * A build is rarely the only thing on a machine — it shares CI with other\n * jobs, and it shares a laptop with the test suite that renders its own\n * fixtures, where six was enough to turn a two-second budget into a timeout.\n */\nconst DEFAULT_PRERENDER_CONCURRENCY = 4\n\n/**\n * The client components the engine itself puts around every page when the\n * bootstrap is on - the segment and slot boundaries, the title, the pathname\n * provider, the error boundary. They are in every payload, they are not the\n * app's, and a render without the bootstrap does not insert them. Anything\n * else in the list is the app's, and needs the runtime.\n */\nconst RUNTIME_OWN = new Set([\n 'DocumentTitle',\n 'PathnameProvider',\n 'RouteErrorBoundary',\n 'SegmentBoundary',\n 'SlotBoundary',\n])\n\n/**\n * The one line the bootstrap would have run for the worker, for a document\n * stored without a bootstrap. Same timing as the runtime's: after load, so\n * it competes with nothing the first visit needs. A page whose document has\n * no closing body tag is left alone.\n */\nconst WORKER_REGISTRATION =\n \"<script>'serviceWorker'in navigator&&addEventListener('load',function(){navigator.serviceWorker.register('/sw.js').catch(function(){})})</script>\"\n\nexport function withWorkerRegistration(html: string): string {\n const at = html.lastIndexOf('</body>')\n\n return at === -1 ? html : html.slice(0, at) + WORKER_REGISTRATION + html.slice(at)\n}\n\nexport interface PrerenderEngine {\n manifest?(): RouteManifest\n /**\n * A route.ts, answered. Optional: a bundle built before api routes existed\n * has none, and the build then simply stores no route.\n */\n handleApiRoute?(\n name: string,\n request: Request,\n params: Record<string, string>,\n allow: string,\n ): Promise<Response>\n getStaticParams?(component: string): Promise<Record<string, string>[] | null>\n handleRscPprShell(\n component: string,\n props?: Record<string, unknown>,\n layouts?: { component: string; props: Record<string, unknown> }[],\n loadings?: string[],\n parallelSlots?: Record<string, string>,\n pageKey?: string,\n /** How long to render before taking what has flushed. Defaults to the full budget. */\n budgetMs?: number,\n ): Promise<{\n shellHtml: string\n timedOut: boolean\n usedDynamicApis: boolean\n /**\n * The host calls this render made, by name.\n *\n * So the build can say which one kept the page from being frozen rather\n * than only that something did. Optional: an engine built before this\n * existed reports nothing, and the line is printed without a reason.\n */\n dynamicBecause?: string[]\n error?: string\n /**\n * Where the render stopped, when it stopped — React's own resumable state.\n *\n * Null when the page finished, which is the same thing as `timedOut` being\n * false. An engine built before this existed returns undefined, and the\n * shell is then served the way it always was: holes filled by the client\n * after hydration rather than resumed at the origin.\n */\n postponed?: unknown\n /**\n * Anything that failed while producing the shell, including a rejection a\n * Suspense boundary caught.\n *\n * Such a rejection never reaches the caller: React keeps the fallback and\n * the render finishes, so without this a page whose data source was\n * unreachable looked complete and its loading state was frozen as a\n * finished page.\n */\n renderFailure?: string\n }>\n handleRsc(\n component: string,\n props?: Record<string, unknown>,\n callbackSocket?: string | null,\n layouts?: { component: string; props: Record<string, unknown> }[],\n loadings?: string[],\n parallelSlots?: Record<string, string>,\n from?: number,\n pageKey?: string,\n bootstrap?: boolean,\n /**\n * Whether a host is installed to answer rpc().\n *\n * False during a build, where there is none: every host call then suspends\n * and the page reports that it reached for one, instead of resolving to\n * undefined and being frozen holding it.\n */\n canReachHost?: boolean,\n ): Promise<{\n body: string\n rscPayload: string\n clientComponents: string[]\n /** A server action is in the tree - a form or a client prop - so a runtime is needed to submit it. */\n serverReferences?: boolean\n usedDynamicApis?: boolean\n }>\n handleRscPayload(\n component: string,\n props?: Record<string, unknown>,\n layouts?: { component: string; props: Record<string, unknown> }[],\n loadings?: string[],\n parallelSlots?: Record<string, string>,\n from?: number,\n pageKey?: string,\n ): Promise<{ rscPayload: string }>\n}\n\nexport interface PrerenderOptions {\n engine: PrerenderEngine\n /**\n * The app has a service worker. A page stored without the bootstrap has\n * nothing to register it, so one line is put in its place - the worker is\n * for the second visit, and a visitor who lands on such a page first should\n * still get one.\n */\n serviceWorker?: boolean\n /**\n * Where the output goes, as a sink rather than a directory.\n *\n * `writeTo` in `@rsc-kit/core/files` is the one for a disk, which is what a\n * build normally wants. A function because the read side is one — a host\n * that supplies a reader should be able to supply the matching writer —\n * and because a test can hand it a Map instead of a temp directory.\n */\n write: (name: string, contents: string) => Promise<void> | void\n /** The route table. Defaults to the one the bundle carries. */\n manifest?: RouteManifest\n /**\n * Props for a page at build time.\n *\n * There is no request here, which is the point: anything a page needs that\n * only a request can supply is exactly what makes it un-freezable. Defaults\n * to the url params alone.\n */\n props?: (route: ManifestRoute, params: Record<string, string>) => Record<string, unknown>\n /**\n * How many routes to render at once. Defaults to 6; 1 renders sequentially.\n *\n * Worth lowering when the pages talk to something that will not enjoy six\n * concurrent callers — a local database, a rate-limited API.\n */\n concurrency?: number\n /** Identifies the build in what gets written, so a stale page can be spotted. */\n version?: string\n /** Called as each url is decided, for build output. */\n onResult?: (result: PrerenderResult) => void\n}\n\n/**\n * The build's refusal to store a route it cannot answer ahead of time.\n *\n * Thrown rather than reported, because the alternative is a category: a bucket\n * of routes that quietly render per request, which is where the slow ones go\n * to be forgotten. Every route is either stored or has said it will not be.\n */\nexport class NotPrerenderable extends Error {\n public readonly routes: PrerenderResult[]\n\n constructor(routes: PrerenderResult[]) {\n // Two different problems arrive here, and the advice for one is useless for\n // the other. A page that reads the request above every boundary needs a\n // boundary; a page whose render threw needs whatever it was reaching for.\n const threw = routes.filter((r) => r.reason?.startsWith('could not be rendered'))\n const unpaintable = routes.filter((r) => !r.reason?.startsWith('could not be rendered'))\n\n const advice: string[] = []\n\n if (unpaintable.length > 0) {\n advice.push(\n 'These read request data — params, headers, cookies, or the host — above\\n' +\n 'every Suspense boundary, so nothing can paint without it:\\n\\n' +\n unpaintable.map((r) => ` ${r.url} — ${r.reason ?? 'nothing to paint'}`).join('\\n') +\n '\\n\\nPut the part that waits inside <Suspense>, or add a loading.tsx beside\\n' +\n 'the page, so there is something to store while the rest arrives.',\n )\n }\n\n if (threw.length > 0) {\n advice.push(\n 'These failed while rendering:\\n\\n' +\n threw.map((r) => ` ${r.url} — ${r.reason}`).join('\\n') +\n '\\n\\nPrerendering runs your application code, so it needs whatever that code\\n' +\n 'needs. If the page is fine and this machine simply cannot reach a\\n' +\n 'database or an API, either give the build access or turn prerendering\\n' +\n 'off with `rscKit({ prerender: false })`.\\n\\n' +\n 'Reaching for data through the host — `await rpc(...)` — avoids this\\n' +\n 'entirely: the build stubs that call, so the page freezes a shell\\n' +\n 'without the data being available.',\n )\n }\n\n super('Some routes could not be prerendered.\\n\\n' + advice.join('\\n\\n') + '\\n')\n this.name = 'NotPrerenderable'\n this.routes = routes\n\n // Not enumerable: Vite prints an error's own properties under its stack,\n // and this list is the message again, as an object dump.\n Object.defineProperty(this, 'routes', { value: routes, enumerable: false })\n }\n}\n\nexport interface PrerenderResult {\n url: string\n component: string\n /**\n * frozen — the whole page is on disk.\n * shell — the chrome is on disk and the rest is rendered per request.\n * blocked — nothing could be stored. Fails the build.\n * error — the render itself failed, or the build refused what it produced.\n *\n * dynamic — answered per request, and correctly so. Api routes only.\n *\n * There is no such outcome for a PAGE. A page that cannot be stored has its\n * boundary in the wrong place, and the fix is to move it — not to declare\n * the problem away, which is how the slow ones get forgotten. An api route\n * has no boundary to move: it either depends on the request or it does not,\n * and depending on it is the ordinary case rather than a mistake.\n */\n type: 'frozen' | 'shell' | 'blocked' | 'error' | 'dynamic'\n reason: string | null\n /**\n * Something worth knowing that is not a failure.\n *\n * The one that matters: a page whose only boundary is the root loading.tsx.\n * It is stored, so the build has nothing to refuse — but the fallback that\n * caught it belongs to the whole app rather than to this page, and every\n * page in the app shows the same thing while this one's data arrives.\n */\n warning?: string\n /** A fact about how it was stored that is neither a reason nor a warning. */\n note?: string\n}\n\n/**\n * The file name a route's shell is stored under, with params standing in for\n * themselves: /posts/[slug] → posts/_slug_.\n *\n * A shell contains nothing that varies by param — everything that does is\n * behind a boundary the client fills — so one shell serves every url the\n * route matches, including the ones the app never listed.\n */\nexport function patternKey(route: ManifestRoute): string {\n const parts = route.segments.map((s) => (s.type === 'static' ? s.value : `_${s.value}_`))\n\n return parts.join('/') || 'index'\n}\n\n/** Close a document the render was aborted in the middle of. */\nexport function closeDocument(html: string): string {\n let out = html\n\n if (!/<\\/body>/i.test(out) && /<body/i.test(out)) out += '</body>'\n if (!/<\\/html>/i.test(out) && /<html/i.test(out)) out += '</html>'\n\n return out\n}\n\n/**\n * The file name a url is stored under: / → index, /a/b → a/b.\n *\n * Refuses a key that could leave the directory it is written into. The input is\n * whatever generateStaticParams() returned — typically slugs from a database or\n * a CMS — so a record named `../../../../etc/cron.d/x` is an arbitrary file\n * write on the build machine with content the same record influences.\n *\n * Checked here rather than in the writer, because the writer is supplied by the\n * host: `writeTo` on disk does the obvious thing, but a KV or edge binding has\n * no notion of a parent directory and no reason to look for one.\n */\n/**\n * The key, showing only the marks that actually appear above it.\n *\n * Wording follows Next's build output deliberately. Most people arriving here\n * have read that legend already, and inventing a second vocabulary for the same\n * three states costs them a translation for nothing.\n */\nexport function legend(results: { type: string }[]): string {\n const has = (type: string) => results.some((r) => r.type === type)\n const lines: string[] = []\n\n if (has('frozen')) {\n lines.push(' \\u25CB (Static) prerendered as static content')\n }\n\n if (has('shell')) {\n lines.push(\n ' \\u25D0 (Partial Prerender) prerendered as static HTML with dynamic server-streamed content',\n )\n }\n\n if (has('dynamic')) {\n lines.push(' \\u0192 (Dynamic) server-rendered on demand')\n }\n\n if (has('error') || has('blocked')) {\n lines.push(' \\u2717 (Failed) did not render, or painted nothing — the build stops here')\n }\n\n return lines.join('\\n')\n}\n\n/**\n * How much JavaScript a route makes the browser download.\n *\n * Gzipped, because that is what crosses the wire — uncompressed bytes are a\n * number nobody is served.\n *\n * A real per-route figure only because client components are chunked per\n * module. Grouped the way plugin-rsc groups them by default, every route in an\n * app loads every client component and this column is one number repeated down\n * the page.\n */\nexport function clientJsSize(bytes: number): string {\n if (bytes === 0) return 'no js'\n\n const kb = bytes / 1000\n\n return `${kb < 10 ? kb.toFixed(1) : Math.round(kb)} kB`\n}\n\n/**\n * The paragraph a mark cannot hold.\n *\n * \"dynamic — called rpc(\\\"getUser\\\")\" says what happened and not why the build\n * could not simply make the call, which is the first thing someone asks when a\n * page they expected to be static is not. The backend is running; the build is\n * not talking to it.\n *\n * Printed once under the summary rather than beside each route: an app where\n * every page reads from the backend would otherwise repeat the same paragraph\n * forty times.\n */\nexport function notes(results: { type?: string; reason?: string | null }[]): string {\n const said = (text: string) => results.some((r) => r.reason?.includes(text))\n const parts: string[] = []\n\n // Every route not frozen, all for one reason, is the shape a read in the\n // root layout leaves: one cookies() in a header component and nothing on\n // the site can be stored. The build cannot see which component read it -\n // only that every page did - so it says what that usually means.\n const pages = results.filter((r) => r.type && r.type !== 'error' && r.type !== 'blocked')\n const reasons = new Set(pages.map((r) => r.reason ?? ''))\n\n if (pages.length > 1 && !pages.some((r) => r.type === 'frozen') && reasons.size === 1) {\n const [reason] = reasons\n\n parts.push(\n ` Every route ${reason}. When one read makes every page dynamic it is usually\\n` +\n ' in the root layout - a header reading the session, a locale from a cookie.\\n' +\n ' Move that read into the component that needs it, under a <Suspense>, and\\n' +\n ' the rest of the site can freeze around it.',\n )\n }\n\n if (said('rpc(')) parts.push(rpcNote())\n\n return parts.join('\\n\\n')\n}\n\nfunction rpcNote(): string {\n return (\n ' A build has no backend to call. rpc() suspends instead of answering, so a page\\n' +\n ' that reads through one ships a shell and finishes for whoever asks — which is\\n' +\n ' almost always what you want, since that data is rarely the same for everyone.\\n' +\n '\\n' +\n ' If a page really should be frozen, move the read out of rpc(). If it really\\n' +\n ' should be per visitor, say so with await connection() and the intent is on the\\n' +\n ' page rather than inferred from a call that happened to suspend.'\n )\n}\n\n/**\n * The one-line tally under the legend, in the legend's own words.\n */\nexport function summary(results: { type: string }[]): string {\n const count = (type: string) => results.filter((r) => r.type === type).length\n const parts: string[] = []\n\n if (count('frozen')) parts.push(`${count('frozen')} static`)\n if (count('shell')) parts.push(`${count('shell')} partial prerender`)\n if (count('dynamic')) parts.push(`${count('dynamic')} dynamic`)\n if (count('error') + count('blocked')) parts.push(`${count('error') + count('blocked')} failed`)\n\n return parts.join(', ') || 'nothing to store'\n}\n\nexport function pathKey(url: string): string {\n const key = url.replace(/^\\/+|\\/+$/g, '') || 'index'\n\n if (key.split('/').some((segment) => segment === '..' || segment === '.')) {\n throw new Error(\n 'Refusing to store ' + JSON.stringify(url) + ': the path leaves the output directory. ' +\n 'A url segment came from generateStaticParams() or a route param and contains \"..\".',\n )\n }\n\n return key\n}\n\n/**\n * Substitute params into a route's segments to get a concrete url.\n *\n * A param is one segment, so a value carrying a slash is not a deeper url — it\n * is a value that was never a single segment. A catch-all is the exception and\n * is spelled as one in the route.\n */\nexport function urlFor(route: ManifestRoute, params: Record<string, string>): string {\n const parts = route.segments.map((segment) => {\n if (segment.type === 'static') return segment.value\n\n const value = params[segment.value] ?? ''\n\n if (segment.type !== 'catchAll' && /[/\\\\]/.test(value)) {\n throw new Error(\n 'The ' + segment.value + ' param is ' + JSON.stringify(value) + ', which is not one url ' +\n 'segment. A value with a slash in it has to be a catch-all route, or be encoded.',\n )\n }\n\n return value\n })\n\n return '/' + parts.filter((p) => p !== '').join('/')\n}\n\n/**\n * Every url this build should attempt, and the params each was built from.\n *\n * A parameterised route that declares no `generateStaticParams` yields\n * nothing — not an error: rendering on demand is a legitimate answer, and the\n * alternative is guessing at slugs the app never listed.\n */\n/** Stand-in values for a route whose real urls were never listed. */\nfunction placeholders(route: ManifestRoute): Record<string, string> {\n const params: Record<string, string> = {}\n\n for (const segment of route.segments) {\n if (segment.type !== 'static') params[segment.value] = '_'\n }\n\n return params\n}\n\nexport async function urlsToBuild(\n manifest: RouteManifest,\n engine: PrerenderEngine,\n): Promise<{ route: ManifestRoute; params: Record<string, string>; url: string }[]> {\n const entries: { route: ManifestRoute; params: Record<string, string>; url: string }[] = []\n\n for (const route of manifest.routes) {\n const parameterised = route.segments.some((s) => s.type !== 'static')\n\n if (!parameterised) {\n entries.push({ route, params: {}, url: urlFor(route, {}) })\n continue\n }\n\n // A route that lists no urls still gets one attempt, with placeholder\n // params, so it can ship a shell. Nothing in a shell varies by param.\n if (!route.staticParams) {\n entries.push({ route, params: placeholders(route), url: urlFor(route, placeholders(route)) })\n continue\n }\n\n const sets = (await engine.getStaticParams?.(route.component)) ?? null\n\n // Null means the route declares none, so it is rendered on demand. An\n // empty array means the app looked and there is nothing to build — both\n // produce no files, and only one of them is a mistake to warn about.\n if (!sets) continue\n\n for (const params of sets) {\n entries.push({ route, params, url: urlFor(route, params) })\n }\n }\n\n return entries\n}\n\nexport async function prerender(options: PrerenderOptions): Promise<PrerenderResult[]> {\n const { engine, write, version } = options\n const manifest = options.manifest ?? engine.manifest?.()\n\n if (!manifest) {\n throw new Error('No route table. Pass `manifest`, or build with a plugin version that embeds one.')\n }\n\n const entries = await urlsToBuild(manifest, engine)\n const results: PrerenderResult[] = new Array(entries.length)\n\n // Rendered a few at a time rather than one after another.\n //\n // Most of a build is this loop, and most of this loop is waiting: a page\n // whose shell is decided by a two-second budget spends two seconds doing\n // nothing while the next page waits its turn. Nothing here is shared between\n // routes — the probe's stand-in host is held in async context, so concurrent\n // renders cannot see each other's — which is what makes overlapping them\n // safe, and was not true until it was scoped.\n //\n // Bounded, because each one is a full React render: unbounded would turn a\n // large site into as many concurrent renders as it has pages.\n //\n // Results are placed by index, so what a build reports does not depend on\n // which page happened to finish first.\n const concurrency = Math.max(1, options.concurrency ?? DEFAULT_PRERENDER_CONCURRENCY)\n let next = 0\n\n const worker = async () => {\n while (true) {\n const index = next++\n\n if (index >= entries.length) return\n\n const { route, params, url } = entries[index]\n\n results[index] = await prerenderOne(route, params, url)\n options.onResult?.(results[index])\n }\n }\n\n const unwatch = watchNondeterminism()\n\n try {\n await Promise.all(Array.from({ length: Math.min(concurrency, entries.length) }, worker))\n } finally {\n unwatch()\n }\n\n const refused = results.filter((r) => r.type === 'blocked')\n\n if (refused.length > 0) {\n throw new NotPrerenderable(refused)\n }\n\n return results\n\n async function prerenderOne(\n route: ManifestRoute,\n params: Record<string, string>,\n url: string,\n ): Promise<PrerenderResult> {\n const props = options.props ? options.props(route, params) : params\n const layouts = route.layouts.map((component) => ({ component, props: {} }))\n const unlistedNow = route.segments.some((seg) => seg.type !== 'static') && !route.staticParams\n /**\n * Why this route ships a shell rather than a whole page.\n *\n * In the order that answers the question soonest. A named call is the most\n * actionable — you can go and look at it — so it wins over the two\n * structural reasons, either of which may also be true.\n */\n const shellReason = (calls: string[]): string | null => {\n if (calls.length) return 'dynamic — called ' + calls.join(', ')\n\n // One shell serving every url the route matches. generateStaticParams is\n // what turns it into a page per url.\n if (unlistedNow) return 'one shell for every url — add generateStaticParams to store each'\n\n // Nothing reached for the request; the data simply took too long. The\n // page is fine, it just finishes per visitor.\n if (shell?.timedOut) return 'data took longer than the build budget'\n\n return null\n }\n\n const said = (type: PrerenderResult['type'], reason: string | null): PrerenderResult => ({\n // A route standing in for many urls reports the pattern. Reporting the\n // placeholder url instead prints `/posts/_`, which looks like a page.\n url: unlistedNow ? '/' + patternKey(route) : url,\n component: route.component,\n type,\n reason,\n })\n\n const unlisted = route.segments.some((seg) => seg.type !== 'static') && !route.staticParams\n\n // Classify by rendering, never by asking. The probe is cheap and cannot\n // hang: anything still suspended when its budget expires is the answer.\n //\n // Wrapped so a redirect has somewhere to be recorded. Reading the scope\n // rather than inspecting the thrown error is the only thing that works\n // from out here: React catches what a component throws and re-raises its\n // own, whose message is stripped in production — so a redirect above the\n // boundaries arrives as a generic render failure, and one from inside a\n // boundary never arrives at all.\n // A build renders each url once, and each gets its own table: two routes\n // must not share an answer just because they were built in the same run.\n // No request, deliberately: a page that reads one is caught below rather\n // than frozen holding whatever the build machine happened to send.\n const [{ shell, redirected, readRequest, readBy }, nondeterministic] = await whileRendering(() =>\n withRequest(null, () =>\n withCache(() => withRedirect(async (taken) => {\n try {\n return {\n shell: await engine.handleRscPprShell(\n route.component,\n props,\n layouts,\n route.loadings,\n route.slots,\n // Only when this shell serves one url. A parameterised route's\n // shell is shared, so baking a url into it would put the wrong one\n // on every page but the one that happened to be built.\n unlistedNow ? '' : url,\n ),\n redirected: taken(),\n readRequest: requestWasRead(),\n // What reached for it, so the build can name the call rather than\n // only report that the page is dynamic.\n readBy: requestReadBy(),\n }\n } catch (error) {\n // A guard refusing throws out of the probe rather than being caught\n // inside it: middleware run before the render, so there is no render yet\n // to capture the failure. A refusal is a classification, not a build\n // error — the route is one that cannot be frozen.\n const refused = taken()\n\n if (!refused) throw error\n\n return { shell: null, redirected: refused, readRequest: requestWasRead(), readBy: requestReadBy() }\n }\n })),\n ),\n )\n\n // A page that leaves rather than renders is not a build failure, and it is\n // not something to freeze either: what would be stored is the redirect's\n // own emptiness, served for ever to everyone. Rendered on demand instead,\n // where the redirect can actually happen.\n /**\n * Did this page's own boundary catch the wait, or the app's?\n *\n * A root loading.tsx wraps every page, so a page that blocks — or throws,\n * which is how a client hook says it has no server answer — is caught\n * whatever it does. The route is stored either way and the build has\n * nothing to refuse, which makes a page whose boundary is in the wrong\n * place look exactly like one whose boundary is right.\n *\n * Asked by rendering again without the root fallback, and only for a route\n * that has no closer one.\n *\n * Only for a route that came out as a shell. A frozen one rendered to\n * completion with the root boundary present, and removing a boundary\n * cannot stop a render that already finished — so the second probe\n * finishes too, its markup is the whole document, and the emptiness test\n * cannot fire. It was being paid for anyway: a second full render of every\n * frozen page, which on a site whose pages are mostly frozen is most of\n * the prerender.\n */\n async function withRootFallbackChecked(result: PrerenderResult): Promise<PrerenderResult> {\n if (result.type !== 'shell') return result\n if (route.loadings.length !== 1 || !engine.handleRscPprShell) return result\n\n // A tenth of the shell budget, because this is a different question.\n //\n // Deciding what a page's shell IS means waiting out everything that can\n // resolve. Asking whether anything paints at all without the root\n // fallback is a boolean about the first flush — and a page that paints,\n // paints immediately. Given the full budget it cost two seconds a route\n // to learn what the first millisecond already said, which on this\n // example was 40% of the entire prerender.\n const withoutRoot = await withRequest(null, () =>\n withCache(() =>\n withRedirect(async () =>\n engine.handleRscPprShell(\n route.component,\n props,\n layouts,\n [],\n route.slots,\n url,\n ROOT_FALLBACK_BUDGET_MS,\n ),\n ),\n ),\n ).catch(() => null)\n\n if (withoutRoot && closeDocument(withoutRoot.shellHtml.trim()) === '') {\n result.warning =\n 'nothing painted without the root loading.tsx — the fallback the whole app shares ' +\n 'is standing in for this page. Put a boundary where the waiting is.'\n }\n\n return result\n }\n\n // A route that only redirects still has an answer to freeze — the answer\n // is the redirect, not a page. Rendering it per request re-derives a\n // constant, and on a static host there would be nothing to derive it with.\n if (redirected) {\n await write(\n `${pathKey(url)}.redirect.json`,\n JSON.stringify({ status: redirected.status, location: redirected.location }),\n )\n\n return said('frozen', `redirects to ${redirected.location}`)\n }\n\n if (!shell) return said('error', 'refused before it rendered')\n\n if (shell.error) return said('error', shell.error)\n\n // Something failed while rendering. Not necessarily the page's fault — a\n // build machine that cannot reach the database produces this, and so does a\n // genuinely broken component — so it is not fatal. It is simply not\n // something to freeze: whatever this render produced is a failure state,\n // and freezing it serves that state to everyone until the next build.\n //\n // Rendering per request is the honest answer. It works as soon as whatever\n // was missing is reachable, which at runtime it usually is.\n if (shell.renderFailure) {\n return said('blocked', `could not be rendered at build time: ${shell.renderFailure}`)\n }\n\n // A timeout is the ordinary path for a page that streams, not a failure:\n // the probe hands the page a host global that never resolves, React\n // flushes everything that does not depend on it, and the abort happens\n // once there is nothing left to flush. So the captured markup IS the\n // shell — layouts, static content, and the fallbacks standing in for what\n // has not arrived.\n if (shell.timedOut) {\n const body = closeDocument(shell.shellHtml.trim())\n\n // Nothing was flushed before the page blocked, so there is no shell to\n // ship — a page that blocks above every boundary can only be rendered on\n // demand. `reaches for the host` is the specific reason when both are\n // true; a page that merely ran long says the other thing.\n if (body === '') {\n return said(\n 'blocked',\n (readRequest\n ? 'reads the request'\n : shell.usedDynamicApis\n ? 'reaches for the host'\n : 'blocks') +\n ' before anything can paint. Add a loading.tsx beside it, or put a ' +\n '<Suspense> above the waiting, and it has a skeleton to store.',\n )\n }\n\n await writeShell(route, url, body, shell.postponed)\n\n // Why it is a shell rather than a whole page. \"◐ /orders\" on its own\n // leaves someone reading the build output to guess what did it, which is\n // the question this line exists to answer.\n const calls = [...(shell.dynamicBecause ?? []), ...(readBy ?? [])]\n\n return await withRootFallbackChecked(said('shell', shellReason(calls)))\n }\n\n // Warned, not refused.\n //\n // A frozen `new Date()` may be exactly what the author meant — a build\n // stamp, a copyright year — and the build cannot tell that from a\n // \"3 minutes ago\" that will still say three minutes next month. Refusing\n // would make the honest case unbuildable in order to protect the careless\n // one, and there is no flag to add here without inventing the declaration\n // this design exists to avoid.\n //\n // So it says what happened, names what was called, and gives the repair.\n // The escape hatch is that a warning does not stop the build — which is the\n // right weight for something that is occasionally correct.\n //\n // Only for a page frozen WHOLE. On a shell the call may sit inside a hole,\n // which renders per request, where it is correct.\n const noteNondeterminism = (result: PrerenderResult): PrerenderResult => {\n if (nondeterministic.length === 0) return result\n\n result.warning =\n `froze ${nondeterministic.join(' and ')} — a stored page keeps whatever that ` +\n 'returned at build time. If it should differ per visitor, await connection() so ' +\n 'the page renders per request; if only the browser needs it, use(browser()) keeps ' +\n 'it out of the build entirely.'\n\n return result\n }\n\n // Rendered whole, with params that were invented because the route listed\n // none. Freezing that stores a page whose id is literally `_`, and a shell\n // is no better: the value is in the markup rather than behind a boundary\n // the client fills. A route reaches this only by rendering its params\n // before it can paint, which is exactly the shape that cannot be shared\n // across urls.\n if (unlisted) {\n return said('blocked', 'renders its params before it can paint, and lists no urls to build')\n }\n\n const shipsJs = route.clientJs !== false\n\n const rendered = await engine.handleRsc(\n route.component,\n props,\n null,\n layouts,\n // Not empty: a page whose layout declares a parallel slot renders without\n // it otherwise, and nothing says so — the page comes out whole apart from\n // the missing region.\n route.loadings,\n route.slots,\n 0,\n url,\n shipsJs,\n // A build has no host to answer rpc(), so every host call must suspend\n // rather than resolve. Without this they found no host at all and the\n // page was frozen holding whatever undefined rendered to — a document\n // that looks right, hydrates against an undefined prop, and blanks.\n false,\n )\n\n // The render reached for the host, so its data is not the same for\n // everyone and there is no build-time answer for it. Not frozen: a shell\n // is shipped instead and the page finishes for whoever asks.\n if (rendered.usedDynamicApis) {\n return said('shell', 'reaches the host for data')\n }\n\n // A client component without a runtime is inert markup — a button that\n // does nothing. Refused rather than shipped, and named, because they are\n // usually inherited from a shared layout rather than written on the page.\n if (!shipsJs && rendered.clientComponents.length > 0) {\n return said(\n 'error',\n `ships no client runtime, but the tree renders ${rendered.clientComponents.join(', ')}. ` +\n 'These usually come from a shared layout rather than the page itself.',\n )\n }\n\n // Nothing for a runtime to do. No client component means nothing to\n // hydrate, and no server reference means no form that would post through\n // React - so the bootstrap is 70 kB of javascript that runs and changes\n // nothing. Rendered once more without it and stored that way. Only when\n // the page declared nothing: `clientJs = true` keeps the runtime, for a\n // page that wants the service worker or the update prompt regardless.\n let note: string | undefined\n let body = rendered.body\n\n if (\n route.clientJs === 'auto' &&\n rendered.clientComponents.every((name) => RUNTIME_OWN.has(name)) &&\n !rendered.serverReferences\n ) {\n // Only the document. The flight payload stays the bootstrap render's:\n // a Link elsewhere navigating here fetches it and expects the segment\n // and title wrappers that render puts in, which this one leaves out.\n const bare = await engine.handleRsc(\n route.component,\n props,\n null,\n layouts,\n route.loadings,\n route.slots,\n 0,\n url,\n false,\n false,\n )\n\n body = options.serviceWorker ? withWorkerRegistration(bare.body) : bare.body\n note = 'no client components, so ships no javascript'\n }\n\n const key = pathKey(url)\n\n await write(`${key}.html`, body)\n await write(`${key}.flight`, rendered.rscPayload)\n\n // One variant per depth the client might already hold. Without them every\n // navigation to a prerendered route is a whole document, which replaces the\n // root and unmounts the pages retained behind it — so going back does not\n // restore the form you were filling in. Most routes in a real app are\n // prerendered, which makes this the common path rather than an edge case.\n for (let depth = 1; depth <= route.layouts.length; depth++) {\n const { rscPayload } = await engine.handleRscPayload(\n route.component,\n props,\n layouts,\n route.loadings,\n route.slots,\n depth,\n url,\n )\n\n await write(`${key}.seg${depth}.flight`, rscPayload)\n }\n\n await write(\n `${key}.meta.json`,\n JSON.stringify({ layouts: route.layouts, component: route.component, version: version ?? null }, null, 2),\n )\n\n const frozen = noteNondeterminism(await withRootFallbackChecked(said('frozen', null)))\n\n return note ? { ...frozen, note } : frozen\n }\n\n /**\n * Freeze a shell, under the url when it is one and under the route's pattern\n * when it stands for many.\n *\n * A route whose urls were never listed still gets a shell: nothing in it\n * varies by param, so the same markup is correct for every url the route\n * matches. That is most of the value — the routes you can enumerate are the\n * ones you could already freeze whole.\n */\n async function writeShell(\n route: ManifestRoute,\n url: string,\n body: string,\n postponed?: unknown,\n ): Promise<void> {\n const parameterised = route.segments.some((s) => s.type !== 'static')\n const key = parameterised && !route.staticParams ? patternKey(route) : pathKey(url)\n\n await write(`${key}.ppr.html`, body)\n\n // Written only when there is something to resume from. Its absence is\n // meaningful rather than incidental: a host that finds no postponed state\n // serves the shell and lets the client fill it, which is what every build\n // before this one did.\n if (postponed != null) {\n await write(`${key}.postponed.json`, JSON.stringify(postponed))\n }\n await write(\n `${key}.ppr-meta.json`,\n JSON.stringify(\n { layouts: route.layouts, component: route.component, parameterised, version: version ?? null },\n null,\n 2,\n ),\n )\n }\n\n}\n"]}
package/dist/vite.js CHANGED
@@ -1084,6 +1084,7 @@ async function prerenderAfterBundles(bundle, staticDir, assetsDir, knownActions
1084
1084
  results = await prerender({
1085
1085
  engine,
1086
1086
  write: writeTo(staticDir),
1087
+ serviceWorker: offline,
1087
1088
  onResult: (r) => {
1088
1089
  collected.push(r);
1089
1090
  if (r.type === 'error' || r.type === 'blocked')
@@ -1100,6 +1101,7 @@ async function prerenderAfterBundles(bundle, staticDir, assetsDir, knownActions
1100
1101
  bytes,
1101
1102
  extra: [
1102
1103
  ...(r.reason ? [` ${r.reason}`] : []),
1104
+ ...(r.note ? [` ${r.note}`] : []),
1103
1105
  ...(r.warning ? [` ⚠ ${r.warning}`] : []),
1104
1106
  ],
1105
1107
  });
@@ -1158,6 +1160,7 @@ async function prerenderAfterBundles(bundle, staticDir, assetsDir, knownActions
1158
1160
  type: r.type,
1159
1161
  reason: r.reason,
1160
1162
  warning: r.warning ?? null,
1163
+ note: r.note ?? null,
1161
1164
  clientJs: sized.get(r.url) ?? null,
1162
1165
  })), apis.map((a) => ({ url: a.url, name: a.name, type: a.type, reason: a.reason })), audited));
1163
1166
  const note = notes(results);
@@ -1505,7 +1508,8 @@ function metadataExports(absPath) {
1505
1508
  */
1506
1509
  function shipsClientJs(absPath) {
1507
1510
  const src = readFileSync(absPath, 'utf-8');
1508
- return !/export\s+const\s+clientJs\s*(:[^=]+)?=\s*false/.test(src);
1511
+ const declared = /export\s+const\s+clientJs\s*(:[^=]+)?=\s*(true|false)/.exec(src);
1512
+ return declared ? declared[2] === 'true' : 'auto';
1509
1513
  }
1510
1514
  /**
1511
1515
  * Which urls exist for a parameterised route.
@@ -3134,7 +3138,7 @@ export async function handleRsc(
3134
3138
  pageKey = '',
3135
3139
  bootstrap = true,
3136
3140
  canReachHost = true,
3137
- ): Promise<{ body: string; rscPayload: string; clientChunks: unknown; usedDynamicApis: boolean; dynamicBecause: string[]; clientComponents: string[] }> {
3141
+ ): Promise<{ body: string; rscPayload: string; clientChunks: unknown; usedDynamicApis: boolean; dynamicBecause: string[]; clientComponents: string[]; serverReferences: boolean }> {
3138
3142
  applyHost()
3139
3143
 
3140
3144
  // A build renders this with no host installed, so every rpc() has to suspend
@@ -3189,6 +3193,7 @@ export async function handleRsc(
3189
3193
  // says which components forced the decision, since they are usually in a
3190
3194
  // shared layout rather than the page itself.
3191
3195
  clientComponents: clientReferenceNames(rscPayload),
3196
+ serverReferences: hasServerReference(rscPayload),
3192
3197
  }
3193
3198
  }
3194
3199
 
@@ -3202,14 +3207,35 @@ export async function handleRsc(
3202
3207
  function clientReferenceNames(payload: string): string[] {
3203
3208
  const names = new Set<string>()
3204
3209
 
3210
+ // A string React has already sent is referenced by row - "$1" for the
3211
+ // string in row 1 - rather than repeated. The export name of a client
3212
+ // reference is exactly the kind of string that repeats, so it arrives that
3213
+ // way and has to be looked up, or the refusal names a component "$1".
3214
+ const strings = new Map<string, string>()
3215
+
3216
+ for (const line of payload.split('\\n')) {
3217
+ const match = /^(\\d+):"(.*)"$/.exec(line)
3218
+ if (match) strings.set('$' + match[1], match[2]!)
3219
+ }
3220
+
3205
3221
  for (const row of payload.split(':I[').slice(1)) {
3206
3222
  const name = row.split('"')[3]
3207
- if (name) names.add(name)
3223
+ if (name) names.add(strings.get(name) ?? name)
3208
3224
  }
3209
3225
 
3210
3226
  return [...names]
3211
3227
  }
3212
3228
 
3229
+ /**
3230
+ * Whether the payload carries a server reference - an action handed to a
3231
+ * form or a client component. A row of {"id":"...","bound":...} is one,
3232
+ * however it is pointed at ($F for a function prop, $h for a form action).
3233
+ * A page with one needs the runtime to submit it.
3234
+ */
3235
+ export function hasServerReference(payload: string): boolean {
3236
+ return /^\\d+:\\{"id":"[^"]+","bound":/m.test(payload)
3237
+ }
3238
+
3213
3239
  // Flight payload only (worker: rsc-payload — build-time).
3214
3240
  //
3215
3241
  // The segment variant of a prerendered route needs the payload and nothing