@rsc-kit/core 0.20.13 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/apiPrerender.js +1 -1
  2. package/dist/apiPrerender.js.map +1 -1
  3. package/dist/appAssets.d.ts +6 -0
  4. package/dist/appAssets.js +34 -0
  5. package/dist/appAssets.js.map +1 -1
  6. package/dist/appleSplash.d.ts +10 -0
  7. package/dist/appleSplash.js +74 -0
  8. package/dist/appleSplash.js.map +1 -0
  9. package/dist/earlyHints.js +7 -2
  10. package/dist/earlyHints.js.map +1 -1
  11. package/dist/export.js +3 -1
  12. package/dist/export.js.map +1 -1
  13. package/dist/files.d.ts +0 -8
  14. package/dist/files.js +6 -0
  15. package/dist/files.js.map +1 -1
  16. package/dist/headers.d.ts +8 -0
  17. package/dist/headers.js +8 -0
  18. package/dist/headers.js.map +1 -1
  19. package/dist/host.d.ts +9 -0
  20. package/dist/host.js +109 -29
  21. package/dist/host.js.map +1 -1
  22. package/dist/js/Form.d.ts +47 -54
  23. package/dist/js/Form.js +41 -48
  24. package/dist/js/Form.js.map +1 -1
  25. package/dist/js/chunkPreload.d.ts +26 -0
  26. package/dist/js/chunkPreload.js +66 -0
  27. package/dist/js/chunkPreload.js.map +1 -0
  28. package/dist/js/installCapture.d.ts +15 -0
  29. package/dist/js/installCapture.js +17 -0
  30. package/dist/js/installCapture.js.map +1 -0
  31. package/dist/js/navigate.js +4 -0
  32. package/dist/js/navigate.js.map +1 -1
  33. package/dist/js/useInstall.d.ts +15 -0
  34. package/dist/js/useInstall.js +102 -0
  35. package/dist/js/useInstall.js.map +1 -0
  36. package/dist/manifest.d.ts +2 -0
  37. package/dist/manifest.js.map +1 -1
  38. package/dist/metadata.d.ts +31 -0
  39. package/dist/metadata.js.map +1 -1
  40. package/dist/prerender.d.ts +24 -5
  41. package/dist/prerender.js +107 -19
  42. package/dist/prerender.js.map +1 -1
  43. package/dist/request.js +3 -2
  44. package/dist/request.js.map +1 -1
  45. package/dist/shellHead.js +4 -2
  46. package/dist/shellHead.js.map +1 -1
  47. package/dist/stableNames.d.ts +52 -0
  48. package/dist/stableNames.js +91 -0
  49. package/dist/stableNames.js.map +1 -0
  50. package/dist/vite.d.ts +5 -3
  51. package/dist/vite.js +164 -10
  52. package/dist/vite.js.map +1 -1
  53. package/dist/webManifest.d.ts +37 -0
  54. package/dist/webManifest.js +51 -6
  55. package/dist/webManifest.js.map +1 -1
  56. package/package.json +8 -4
package/dist/files.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,4CAA4C;AAE5C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC;;;;;;;;;;;;;;;;;OAiBG;IACH,IAAI,OAAO,GAAgC,IAAI,CAAA;IAE/C,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;IAC1C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC1C,IAAI,IAAI,GAAG,CAAC,CAAA;IAEZ,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,IAAY,EAAQ,EAAE;QACpD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;QAE5B,IAAI,IAAI,GAAG,iBAAiB,GAAG,CAAC;YAAE,OAAM;QAExC,OAAO,IAAI,GAAG,IAAI,GAAG,iBAAiB,IAAI,QAAQ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sE;IACtE,+CAA+C;IAC/C,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAA;IAE/C,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAErD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAE1D,CAAA;QAED,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,KAAK,IAAI,EAAE,CAAC;YAC7D,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAA;YACjG,MAAM,OAAO,GAAG,IAAI,MAAM,IAAI,CAAA;YAE9B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAAE,MAAM,CAAC,MAAM,CAAC,gBAAgB,GAAG,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,CAAA;YAElF,MAAM,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;QAC5D,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;QAC1E,uDAAuD;IACzD,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["// Reading built output off a disk.\n//\n// Kept apart from the host on purpose: it is the only part of serving an RSC\n// app that assumes a filesystem, and plenty of places to run one do not have\n// one. Nothing in `@rsc-kit/core/host` imports this module, so a bundle for a\n// host without a filesystem carries no reference to `node:fs` at all.\n//\n// Assets are not here any more — Nitro publishes and serves those. What is\n// left is the prerendered output: written by the build, read by the server it\n// generates, and copied by a static export.\n\nimport { cp, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\n\n/**\n * Read what the prerenderer wrote, from a directory.\n *\n * Missing is an answer, not an error: a partial prerender is a valid state,\n * and anything not found here is rendered on demand instead.\n */\nexport function prerenderedFrom(dir: string) {\n /**\n * What is on disk, listed once.\n *\n * A miss used to be a thrown ENOENT, and misses are the common case: the\n * host asks for `{url}.html`, then `{url}.ppr.html`, then the route's\n * pattern — so every request to a page served by a pattern shell threw and\n * caught two exceptions before finding anything. Measured at 3,000 req/s\n * against 28,000 for the same page read from memory.\n *\n * Contents are cached for the life of the process. A build's output does\n * not change under a running server - a deploy restarts it, and a server\n * that outlived a rebuild would be serving a stale engine against new\n * pages anyway - so the first read is the only one. Under load the same\n * page used to be opened, read and closed thousands of times a second,\n * which a profile showed as the one cost on a stored page that was ours\n * rather than React's. Capped by bytes, so a site with more pages than\n * memory holds the hot ones and re-reads the rest.\n */\n let present: Promise<Set<string>> | null = null\n\n const CONTENT_CAP_BYTES = 64 * 1024 * 1024\n const contents = new Map<string, string>()\n let held = 0\n\n const remember = (name: string, text: string): void => {\n const size = text.length * 2\n\n if (size > CONTENT_CAP_BYTES / 4) return\n\n while (held + size > CONTENT_CAP_BYTES && contents.size > 0) {\n const oldest = contents.keys().next().value as string\n held -= contents.get(oldest)!.length * 2\n contents.delete(oldest)\n }\n\n contents.set(name, text)\n held += size\n }\n\n const listing = async (): Promise<Set<string>> => {\n present ??= readdir(dir, { recursive: true })\n .then((names) => new Set(names.map((n) => String(n).replace(/\\\\/g, '/'))))\n // An absent directory is an empty one: a partial prerender is a valid\n // state, and everything falls through to being rendered.\n .catch(() => new Set<string>())\n\n return await present\n }\n\n return async (name: string): Promise<string | null> => {\n if (name.includes('..')) return null\n\n if (!(await listing()).has(name)) return null\n\n const cached = contents.get(name)\n\n if (cached !== undefined) return cached\n\n try {\n const text = await readFile(join(dir, name), 'utf-8')\n\n remember(name, text)\n\n return text\n } catch {\n return null\n }\n }\n}\n\n/**\n * The same reader, for a directory whose absolute path is not known until the\n * server runs.\n *\n * Nitro bundles the generated entry to a different depth depending on the\n * preset — `.output/server/index.mjs` for one, `.output/server/_ssr/rsc.mjs`\n * for another — so neither a fixed relative path nor a path baked in at build\n * time survives: the first is wrong for half the presets, and the second stops\n * being true the moment `.output/` is copied to the machine that serves it.\n *\n * So the caller passes its own `import.meta.url` and the directory is found by\n * walking up from it. A few levels, bounded, and resolved once.\n *\n * prerendered: prerenderedBeside(import.meta.url, 'rsc-static')\n *\n * Not finding it is a valid state and not an error: nothing was frozen, or\n * this host has no filesystem to have frozen it on. Every page renders live,\n * which is what happens today everywhere.\n */\n/**\n * Where a compiled binary puts the frozen pages.\n *\n * `bun build --compile` embeds what is imported statically and nothing a\n * computed import names, so the walk below finds no directory and no\n * module inside a binary. The build writes `compile.mjs` beside the\n * server: it imports the inline module by name - which embeds it - and\n * hands the pages over here before importing the server. Shared as a\n * global under a registered symbol, because the wrapper and this module\n * are bundled apart.\n */\nexport const EMBEDDED_PAGES = Symbol.for('rsc-kit.embedded-pages')\n\nfunction embeddedPages(): Record<string, string> | null {\n const pages = (globalThis as Record<symbol, unknown>)[EMBEDDED_PAGES]\n\n return pages && typeof pages === 'object' ? (pages as Record<string, string>) : null\n}\n\nexport function prerenderedBeside(moduleUrl: string, dirName: string, levels = 4) {\n let reader: Promise<(name: string) => Promise<string | null>> | null = null\n\n const resolveDir = async (): Promise<(name: string) => Promise<string | null>> => {\n const embedded = embeddedPages()\n\n if (embedded) return async (name) => embedded[name] ?? null\n\n let dir: string | null = null\n\n try {\n const { fileURLToPath } = await import('node:url')\n\n dir = dirname(fileURLToPath(moduleUrl))\n } catch {\n // No filesystem, or no file: url to speak of. The inline module below\n // is the only place the pages can be.\n }\n\n if (dir !== null) {\n for (let i = 0; i <= levels; i++) {\n const candidate = join(dir, ...Array(i).fill('..'), dirName)\n\n try {\n await readdir(candidate)\n\n return prerenderedFrom(candidate)\n } catch {\n // Not at this level. Keep walking.\n }\n }\n }\n\n // A Worker: the pages were uploaded as static assets, under a prefix\n // the Worker answers first, and are read back through the binding.\n const assets = await workersAssets()\n\n if (assets) return assetsReader(assets, `/${ASSETS_PREFIX(dirName)}`)\n\n const inline = await inlinePrerendered(moduleUrl, `${dirName}-inline.mjs`, levels)\n\n return inline ? async (name) => inline[name] ?? null : async () => null\n }\n\n return async (name: string): Promise<string | null> => {\n reader ??= resolveDir()\n\n return await (await reader)(name)\n }\n}\n\n/**\n * Where the stored pages live among a Worker's static assets.\n *\n * Under a prefix, beside the app's own public files, because that is the\n * one store a Worker has that costs nothing in script size: an inline module\n * counts against the bundle's limit, and a port's 571 stored category pages\n * came to 69 MB of module against a limit of 10. The prefix is one the\n * Worker answers first - `run_worker_first` in wrangler.json, written by\n * the build - so a browser asking for `/_rsc-static/x.ppr.html` reaches the\n * app, which has no such route, rather than the asset; a stored page of a\n * guarded route is served only by the host that runs the guard.\n */\nexport const ASSETS_PREFIX = (dirName: string): string => `_${dirName}`\n\n/** The Workers assets binding, where this runs on Workers and it is bound. */\nasync function workersAssets(): Promise<AssetsBinding | null> {\n if (typeof navigator === 'undefined' || navigator.userAgent !== 'Cloudflare-Workers') return null\n\n try {\n // Computed, so neither the bundler nor tsc looks for a module only the\n // Workers runtime has.\n const specifier = 'cloudflare:workers'\n const { env } = (await import(/* @vite-ignore */ specifier)) as { env: { ASSETS?: AssetsBinding } }\n\n return env.ASSETS && typeof env.ASSETS.fetch === 'function' ? env.ASSETS : null\n } catch {\n return null\n }\n}\n\ninterface AssetsBinding {\n fetch(input: Request | string): Promise<Response>\n}\n\n/**\n * Read stored pages through the assets binding, each name once per isolate.\n *\n * The host asks for `{url}.html`, then `{url}.ppr.html`, then the pattern's,\n * on every request: three asks per page, most of them misses. The binding\n * is a fetch, not a memory read, so the answers - misses included - are kept\n * for the life of the isolate, the way the disk reader keeps its listing.\n */\nexport function assetsReader(assets: AssetsBinding, prefix: string): (name: string) => Promise<string | null> {\n const known = new Map<string, Promise<string | null>>()\n\n return (name) => {\n let pending = known.get(name)\n\n if (!pending) {\n const path = `${prefix}/${name.split('/').map(encodeURIComponent).join('/')}`\n\n pending = assets\n .fetch(new Request(`https://assets.invalid${path}`))\n .then((response) => (response.ok ? response.text() : null))\n .catch(() => null)\n\n known.set(name, pending)\n }\n\n return pending\n }\n}\n\n/**\n * The frozen pages as one module, for a runtime with no filesystem.\n *\n * A Worker cannot readdir. Its modules are what wrangler uploaded, and a\n * sibling .mjs beside the bundle is one of them - so the build writes every\n * stored file into `rsc-static-inline.mjs` as strings, and this walks up from\n * the caller the way the disk reader does, importing rather than reading.\n * The specifier is computed, and marked for the bundler to leave alone: at\n * bundle time the file does not exist yet, because it is written by the\n * prerender that runs the bundle.\n *\n * Two forms of the specifier, because runtimes disagree. workerd resolves a\n * relative string against the importing module's name and refuses a url;\n * Node and Bun want the url, since a relative string would resolve against\n * this file rather than the caller's.\n */\nasync function inlinePrerendered(\n moduleUrl: string,\n fileName: string,\n levels: number,\n): Promise<Record<string, string> | null> {\n for (let i = 0; i <= levels; i++) {\n const relative = './' + '../'.repeat(i) + fileName\n\n for (const specifier of [relative, safeUrl(relative, moduleUrl)]) {\n if (!specifier) continue\n\n try {\n const loaded = (await import(/* @vite-ignore */ specifier)) as { default?: Record<string, string> }\n\n if (loaded.default && typeof loaded.default === 'object') return loaded.default\n } catch {\n // Not there, or not at this level.\n }\n }\n }\n\n return null\n}\n\nfunction safeUrl(relative: string, base: string): string | null {\n try {\n return new URL(relative, base).href\n } catch {\n return null\n }\n}\n\n/**\n * The entry a binary is compiled from, written beside the server.\n *\n * Two static imports, in this order: the inline module first - evaluating\n * it hands the pages over - and the server second. A module's imports are\n * evaluated in order, before its own body, so the pages are in place before\n * the server's first line runs. Bun embeds both.\n *\n * Static rather than `await import()`: a top-level await is what made Bun\n * skip `--bytecode` for this entry, silently, byte for byte - and a port\n * whose other Nitro app compiled with it asked why this one could not.\n * `bun build --compile --bytecode .output/server/compile.mjs` works now.\n */\nexport function compileEntrySource(dirName: string): string {\n return (\n '// The entry to compile into one binary:\\n' +\n '// bun build --compile .output/server/compile.mjs --outfile dist/app\\n' +\n '//\\n' +\n '//\\n' +\n '// A binary carries what is imported by name. The server reads its frozen pages\\n' +\n '// through a computed import, which a compile cannot see - imported here, they\\n' +\n '// travel inside the binary and are handed to the server before it starts.\\n' +\n '// Two static imports in this order, and no top-level await: imports evaluate\\n' +\n '// in order, and an await here is what stopped --bytecode from applying.\\n' +\n `import \"./${inlineModuleName(dirName)}\";\\n` +\n 'import \"./index.mjs\";\\n'\n )\n}\n\n/** The name the build writes the inline module under, beside the stored pages' directory. */\nexport function inlineModuleName(dirName: string): string {\n return `${dirName}-inline.mjs`\n}\n\n/**\n * Every stored file under `dir`, as the source of the inline module.\n * Strings only: a frozen page, its flight payload, its meta, an api answer.\n */\nexport async function inlineModuleSource(dir: string): Promise<string> {\n const { readdir: list, readFile: read } = await import('node:fs/promises')\n const entries: Record<string, string> = {}\n\n const walk = async (sub: string): Promise<void> => {\n for (const entry of await list(join(dir, sub), { withFileTypes: true })) {\n const rel = sub ? `${sub}/${entry.name}` : entry.name\n\n if (entry.isDirectory()) await walk(rel)\n else entries[rel] = await read(join(dir, rel), 'utf-8')\n }\n }\n\n await walk('')\n\n // Exported for the Worker, which imports it when the directory is not\n // there, and handed over as a global for the binary, whose compile entry\n // imports it first for exactly this side effect. The same data either way.\n return (\n '// @generated by the RSC build: the stored pages, for a runtime with no filesystem.\\n' +\n 'const pages = ' +\n JSON.stringify(entries) +\n ';\\n' +\n 'globalThis[Symbol.for(\"rsc-kit.embedded-pages\")] = pages;\\n' +\n 'export default pages;\\n'\n )\n}\n\nfunction contentTypeOf(pathname: string): string {\n if (pathname.endsWith('.js')) return 'text/javascript; charset=utf-8'\n if (pathname.endsWith('.css')) return 'text/css; charset=utf-8'\n if (pathname.endsWith('.map')) return 'application/json; charset=utf-8'\n if (pathname.endsWith('.svg')) return 'image/svg+xml'\n if (pathname.endsWith('.woff2')) return 'font/woff2'\n\n return 'application/octet-stream'\n}\n\n/**\n * Write build output into a directory.\n *\n * The sink `prerender` and `exportSite` take. Names are relative and may\n * contain directories — `docs/index.html` — so each one's parent is created\n * as it goes.\n */\nexport function writeTo(dir: string): ((name: string, contents: string) => Promise<void>) & { dir: string } {\n const write = async (name: string, contents: string): Promise<void> => {\n const path = join(dir, name)\n\n await mkdir(dirname(path), { recursive: true })\n await writeFile(path, contents)\n }\n\n // Where it wrote, for a caller that has to read it back. The embeddable\n // module has to list these files, and being told the directory a second time\n // is a second place for it to be wrong.\n return Object.assign(write, { dir })\n}\n\n/**\n * Copy the built browser bundle into an exported site.\n *\n * Separate from the export itself because copying a tree of files is a\n * filesystem operation by nature — a deploy that uploads them to a bucket\n * has its own way to do that, and passes its own callback instead.\n */\nexport function copyAssets(from: string, to: string, url = '/assets/') {\n return async (): Promise<void> => {\n const at = url.replace(/^\\/+|\\/+$/g, '')\n\n if (at === '') return\n\n const target = join(to, at)\n\n await mkdir(dirname(target), { recursive: true })\n await cp(from, target, { recursive: true })\n }\n}\n\n/**\n * Put the stored pages among a Worker's static assets, and have the Worker\n * answer their prefix first.\n *\n * Run after Nitro has written its public-asset list and wrangler.json, so\n * the copies are in neither: not served as assets ahead of the Worker, and\n * not needing a wrangler key Nitro would override. `run_worker_first` is\n * added to the written config for the one prefix. The server-side directory\n * is removed once copied, so nothing in it is uploaded twice. Returns how\n * many files were moved; none when nothing was stored.\n */\nexport async function storedPagesToAssets(staticDir: string, publicDir: string, wranglerPath: string): Promise<number> {\n const { cp, readFile: read, writeFile: write, stat, readdir: list } = await import('node:fs/promises')\n const prefix = ASSETS_PREFIX(staticDir.split(/[\\\\/]/).pop() || 'rsc-static')\n\n try {\n await stat(staticDir)\n } catch {\n return 0\n }\n\n let copied = 0\n const count = async (dir: string): Promise<void> => {\n for (const entry of await list(dir, { withFileTypes: true })) {\n if (entry.isDirectory()) await count(join(dir, entry.name))\n else copied++\n }\n }\n\n await count(staticDir)\n await cp(staticDir, join(publicDir, prefix), { recursive: true })\n\n // Moved, not copied: wrangler's default rules upload every .html and\n // .txt under the server directory as a text module, and 573 stored\n // shells left beside the bundle were 55 MB of modules against a 10 MB\n // limit - a deploy that happened to fit, once.\n const { rm } = await import('node:fs/promises')\n\n await rm(staticDir, { recursive: true, force: true })\n\n try {\n const config = JSON.parse(await read(wranglerPath, 'utf-8')) as {\n assets?: { run_worker_first?: boolean | string[] } & Record<string, unknown>\n }\n\n if (config.assets && config.assets.run_worker_first !== true) {\n const first = Array.isArray(config.assets.run_worker_first) ? config.assets.run_worker_first : []\n const pattern = `/${prefix}/*`\n\n if (!first.includes(pattern)) config.assets.run_worker_first = [...first, pattern]\n\n await write(wranglerPath, JSON.stringify(config, null, 2))\n }\n } catch {\n // No wrangler.json to amend: a deploy config the app writes itself, which\n // then carries the prefix in its own run_worker_first.\n }\n\n return copied\n}\n"]}
1
+ {"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,4CAA4C;AAE5C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC;;;;;;;;;;;;;;;;;OAiBG;IACH,IAAI,OAAO,GAAgC,IAAI,CAAA;IAE/C,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;IAC1C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC1C,IAAI,IAAI,GAAG,CAAC,CAAA;IAEZ,MAAM,QAAQ,GAAG,CAAC,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AAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;QAC5D,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;QAC1E,uDAAuD;IACzD,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["// Reading built output off a disk.\n//\n// Kept apart from the host on purpose: it is the only part of serving an RSC\n// app that assumes a filesystem, and plenty of places to run one do not have\n// one. Nothing in `@rsc-kit/core/host` imports this module, so a bundle for a\n// host without a filesystem carries no reference to `node:fs` at all.\n//\n// Assets are not here any more — Nitro publishes and serves those. What is\n// left is the prerendered output: written by the build, read by the server it\n// generates, and copied by a static export.\n\nimport { cp, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\n\n/**\n * Read what the prerenderer wrote, from a directory.\n *\n * Missing is an answer, not an error: a partial prerender is a valid state,\n * and anything not found here is rendered on demand instead.\n */\nexport function prerenderedFrom(dir: string) {\n /**\n * What is on disk, listed once.\n *\n * A miss used to be a thrown ENOENT, and misses are the common case: the\n * host asks for `{url}.html`, then `{url}.ppr.html`, then the route's\n * pattern — so every request to a page served by a pattern shell threw and\n * caught two exceptions before finding anything. Measured at 3,000 req/s\n * against 28,000 for the same page read from memory.\n *\n * Contents are cached for the life of the process. A build's output does\n * not change under a running server - a deploy restarts it, and a server\n * that outlived a rebuild would be serving a stale engine against new\n * pages anyway - so the first read is the only one. Under load the same\n * page used to be opened, read and closed thousands of times a second,\n * which a profile showed as the one cost on a stored page that was ours\n * rather than React's. Capped by bytes, so a site with more pages than\n * memory holds the hot ones and re-reads the rest.\n */\n let present: Promise<Set<string>> | null = null\n\n const CONTENT_CAP_BYTES = 64 * 1024 * 1024\n const contents = new Map<string, string>()\n let held = 0\n\n const remember = (name: string, text: string): void => {\n const size = text.length * 2\n\n if (size > CONTENT_CAP_BYTES / 4) return\n\n while (held + size > CONTENT_CAP_BYTES && contents.size > 0) {\n const oldest = contents.keys().next().value as string\n held -= contents.get(oldest)!.length * 2\n contents.delete(oldest)\n }\n\n contents.set(name, text)\n held += size\n }\n\n const listing = async (): Promise<Set<string>> => {\n present ??= readdir(dir, { recursive: true })\n .then((names) => new Set(names.map((n) => String(n).replace(/\\\\/g, '/'))))\n // An absent directory is an empty one: a partial prerender is a valid\n // state, and everything falls through to being rendered.\n .catch(() => new Set<string>())\n\n return await present\n }\n\n return async (name: string): Promise<string | null> => {\n if (name.includes('..')) return null\n\n if (!(await listing()).has(name)) return null\n\n const cached = contents.get(name)\n\n if (cached !== undefined) return cached\n\n try {\n const text = await readFile(join(dir, name), 'utf-8')\n\n remember(name, text)\n\n return text\n } catch {\n return null\n }\n }\n}\n\n/**\n * The same reader, for a directory whose absolute path is not known until the\n * server runs.\n *\n * Nitro bundles the generated entry to a different depth depending on the\n * preset — `.output/server/index.mjs` for one, `.output/server/_ssr/rsc.mjs`\n * for another — so neither a fixed relative path nor a path baked in at build\n * time survives: the first is wrong for half the presets, and the second stops\n * being true the moment `.output/` is copied to the machine that serves it.\n *\n * So the caller passes its own `import.meta.url` and the directory is found by\n * walking up from it. A few levels, bounded, and resolved once.\n *\n * prerendered: prerenderedBeside(import.meta.url, 'rsc-static')\n *\n * Not finding it is a valid state and not an error: nothing was frozen, or\n * this host has no filesystem to have frozen it on. Every page renders live,\n * which is what happens today everywhere.\n */\n/**\n * Where a compiled binary puts the frozen pages.\n *\n * `bun build --compile` embeds what is imported statically and nothing a\n * computed import names, so the walk below finds no directory and no\n * module inside a binary. The build writes `compile.mjs` beside the\n * server: it imports the inline module by name - which embeds it - and\n * hands the pages over here before importing the server. Shared as a\n * global under a registered symbol, because the wrapper and this module\n * are bundled apart.\n */\nexport const EMBEDDED_PAGES = Symbol.for('rsc-kit.embedded-pages')\n\nfunction embeddedPages(): Record<string, string> | null {\n const pages = (globalThis as Record<symbol, unknown>)[EMBEDDED_PAGES]\n\n return pages && typeof pages === 'object' ? (pages as Record<string, string>) : null\n}\n\nexport function prerenderedBeside(moduleUrl: string, dirName: string, levels = 4) {\n let reader: Promise<(name: string) => Promise<string | null>> | null = null\n\n const resolveDir = async (): Promise<(name: string) => Promise<string | null>> => {\n const embedded = embeddedPages()\n\n if (embedded) return async (name) => embedded[name] ?? null\n\n let dir: string | null = null\n\n try {\n const { fileURLToPath } = await import('node:url')\n\n dir = dirname(fileURLToPath(moduleUrl))\n } catch {\n // No filesystem, or no file: url to speak of. The inline module below\n // is the only place the pages can be.\n }\n\n if (dir !== null) {\n for (let i = 0; i <= levels; i++) {\n const candidate = join(dir, ...Array(i).fill('..'), dirName)\n\n try {\n await readdir(candidate)\n\n return prerenderedFrom(candidate)\n } catch {\n // Not at this level. Keep walking.\n }\n }\n }\n\n // A Worker: the pages were uploaded as static assets, under a prefix\n // the Worker answers first, and are read back through the binding.\n const assets = await workersAssets()\n\n if (assets) return assetsReader(assets, `/${ASSETS_PREFIX(dirName)}`)\n\n const inline = await inlinePrerendered(moduleUrl, `${dirName}-inline.mjs`, levels)\n\n return inline ? async (name) => inline[name] ?? null : async () => null\n }\n\n return async (name: string): Promise<string | null> => {\n reader ??= resolveDir()\n\n return await (await reader)(name)\n }\n}\n\n/**\n * Where the stored pages live among a Worker's static assets.\n *\n * Under a prefix, beside the app's own public files, because that is the\n * one store a Worker has that costs nothing in script size: an inline module\n * counts against the bundle's limit, and a port's 571 stored category pages\n * came to 69 MB of module against a limit of 10. The prefix is one the\n * Worker answers first - `run_worker_first` in wrangler.json, written by\n * the build - so a browser asking for `/_rsc-static/x.ppr.html` reaches the\n * app, which has no such route, rather than the asset; a stored page of a\n * guarded route is served only by the host that runs the guard.\n */\nexport const ASSETS_PREFIX = (dirName: string): string => `_${dirName}`\n\n/** The Workers assets binding, where this runs on Workers and it is bound. */\nasync function workersAssets(): Promise<AssetsBinding | null> {\n if (typeof navigator === 'undefined' || navigator.userAgent !== 'Cloudflare-Workers') return null\n\n try {\n // Computed, so neither the bundler nor tsc looks for a module only the\n // Workers runtime has.\n const specifier = 'cloudflare:workers'\n const { env } = (await import(/* @vite-ignore */ specifier)) as { env: { ASSETS?: AssetsBinding } }\n\n return env.ASSETS && typeof env.ASSETS.fetch === 'function' ? env.ASSETS : null\n } catch {\n return null\n }\n}\n\ninterface AssetsBinding {\n fetch(input: Request | string): Promise<Response>\n}\n\n/**\n * Read stored pages through the assets binding, each name once per isolate.\n *\n * The host asks for `{url}.html`, then `{url}.ppr.html`, then the pattern's,\n * on every request: three asks per page, most of them misses. The binding\n * is a fetch, not a memory read, so the answers - misses included - are kept\n * for the life of the isolate, the way the disk reader keeps its listing.\n */\nconst KNOWN_LIMIT = 4096\n\nexport function assetsReader(assets: AssetsBinding, prefix: string): (name: string) => Promise<string | null> {\n const known = new Map<string, Promise<string | null>>()\n\n return (name) => {\n let pending = known.get(name)\n\n if (!pending) {\n // Bounded. Misses are kept too, and every made-up path is three of\n // them: kept for the life of the isolate, a crawler of random urls grew\n // this without end. Dropping the oldest costs one fetch, later.\n if (known.size >= KNOWN_LIMIT) known.delete(known.keys().next().value!)\n\n const path = `${prefix}/${name.split('/').map(encodeURIComponent).join('/')}`\n\n pending = assets\n .fetch(new Request(`https://assets.invalid${path}`))\n .then((response) => (response.ok ? response.text() : null))\n .catch(() => null)\n\n known.set(name, pending)\n }\n\n return pending\n }\n}\n\n/**\n * The frozen pages as one module, for a runtime with no filesystem.\n *\n * A Worker cannot readdir. Its modules are what wrangler uploaded, and a\n * sibling .mjs beside the bundle is one of them - so the build writes every\n * stored file into `rsc-static-inline.mjs` as strings, and this walks up from\n * the caller the way the disk reader does, importing rather than reading.\n * The specifier is computed, and marked for the bundler to leave alone: at\n * bundle time the file does not exist yet, because it is written by the\n * prerender that runs the bundle.\n *\n * Two forms of the specifier, because runtimes disagree. workerd resolves a\n * relative string against the importing module's name and refuses a url;\n * Node and Bun want the url, since a relative string would resolve against\n * this file rather than the caller's.\n */\nasync function inlinePrerendered(\n moduleUrl: string,\n fileName: string,\n levels: number,\n): Promise<Record<string, string> | null> {\n for (let i = 0; i <= levels; i++) {\n const relative = './' + '../'.repeat(i) + fileName\n\n for (const specifier of [relative, safeUrl(relative, moduleUrl)]) {\n if (!specifier) continue\n\n try {\n const loaded = (await import(/* @vite-ignore */ specifier)) as { default?: Record<string, string> }\n\n if (loaded.default && typeof loaded.default === 'object') return loaded.default\n } catch {\n // Not there, or not at this level.\n }\n }\n }\n\n return null\n}\n\nfunction safeUrl(relative: string, base: string): string | null {\n try {\n return new URL(relative, base).href\n } catch {\n return null\n }\n}\n\n/**\n * The entry a binary is compiled from, written beside the server.\n *\n * Two static imports, in this order: the inline module first - evaluating\n * it hands the pages over - and the server second. A module's imports are\n * evaluated in order, before its own body, so the pages are in place before\n * the server's first line runs. Bun embeds both.\n *\n * Static rather than `await import()`: a top-level await is what made Bun\n * skip `--bytecode` for this entry, silently, byte for byte - and a port\n * whose other Nitro app compiled with it asked why this one could not.\n * `bun build --compile --bytecode .output/server/compile.mjs` works now.\n */\nexport function compileEntrySource(dirName: string): string {\n return (\n '// The entry to compile into one binary:\\n' +\n '// bun build --compile .output/server/compile.mjs --outfile dist/app\\n' +\n '//\\n' +\n '//\\n' +\n '// A binary carries what is imported by name. The server reads its frozen pages\\n' +\n '// through a computed import, which a compile cannot see - imported here, they\\n' +\n '// travel inside the binary and are handed to the server before it starts.\\n' +\n '// Two static imports in this order, and no top-level await: imports evaluate\\n' +\n '// in order, and an await here is what stopped --bytecode from applying.\\n' +\n `import \"./${inlineModuleName(dirName)}\";\\n` +\n 'import \"./index.mjs\";\\n'\n )\n}\n\n/** The name the build writes the inline module under, beside the stored pages' directory. */\nexport function inlineModuleName(dirName: string): string {\n return `${dirName}-inline.mjs`\n}\n\n/**\n * Every stored file under `dir`, as the source of the inline module.\n * Strings only: a frozen page, its flight payload, its meta, an api answer.\n */\nexport async function inlineModuleSource(dir: string): Promise<string> {\n const { readdir: list, readFile: read } = await import('node:fs/promises')\n const entries: Record<string, string> = {}\n\n const walk = async (sub: string): Promise<void> => {\n for (const entry of await list(join(dir, sub), { withFileTypes: true })) {\n const rel = sub ? `${sub}/${entry.name}` : entry.name\n\n if (entry.isDirectory()) await walk(rel)\n else entries[rel] = await read(join(dir, rel), 'utf-8')\n }\n }\n\n await walk('')\n\n // Exported for the Worker, which imports it when the directory is not\n // there, and handed over as a global for the binary, whose compile entry\n // imports it first for exactly this side effect. The same data either way.\n return (\n '// @generated by the RSC build: the stored pages, for a runtime with no filesystem.\\n' +\n 'const pages = ' +\n JSON.stringify(entries) +\n ';\\n' +\n 'globalThis[Symbol.for(\"rsc-kit.embedded-pages\")] = pages;\\n' +\n 'export default pages;\\n'\n )\n}\n\nfunction contentTypeOf(pathname: string): string {\n if (pathname.endsWith('.js')) return 'text/javascript; charset=utf-8'\n if (pathname.endsWith('.css')) return 'text/css; charset=utf-8'\n if (pathname.endsWith('.map')) return 'application/json; charset=utf-8'\n if (pathname.endsWith('.svg')) return 'image/svg+xml'\n if (pathname.endsWith('.woff2')) return 'font/woff2'\n\n return 'application/octet-stream'\n}\n\n/**\n * Write build output into a directory.\n *\n * The sink `prerender` and `exportSite` take. Names are relative and may\n * contain directories — `docs/index.html` — so each one's parent is created\n * as it goes.\n */\nexport function writeTo(dir: string): ((name: string, contents: string) => Promise<void>) & { dir: string } {\n const write = async (name: string, contents: string): Promise<void> => {\n const path = join(dir, name)\n\n await mkdir(dirname(path), { recursive: true })\n await writeFile(path, contents)\n }\n\n // Where it wrote, for a caller that has to read it back. The embeddable\n // module has to list these files, and being told the directory a second time\n // is a second place for it to be wrong.\n return Object.assign(write, { dir })\n}\n\n/**\n * Copy the built browser bundle into an exported site.\n *\n * Separate from the export itself because copying a tree of files is a\n * filesystem operation by nature — a deploy that uploads them to a bucket\n * has its own way to do that, and passes its own callback instead.\n */\nexport function copyAssets(from: string, to: string, url = '/assets/') {\n return async (): Promise<void> => {\n const at = url.replace(/^\\/+|\\/+$/g, '')\n\n if (at === '') return\n\n const target = join(to, at)\n\n await mkdir(dirname(target), { recursive: true })\n await cp(from, target, { recursive: true })\n }\n}\n\n/**\n * Put the stored pages among a Worker's static assets, and have the Worker\n * answer their prefix first.\n *\n * Run after Nitro has written its public-asset list and wrangler.json, so\n * the copies are in neither: not served as assets ahead of the Worker, and\n * not needing a wrangler key Nitro would override. `run_worker_first` is\n * added to the written config for the one prefix. The server-side directory\n * is removed once copied, so nothing in it is uploaded twice. Returns how\n * many files were moved; none when nothing was stored.\n */\nexport async function storedPagesToAssets(staticDir: string, publicDir: string, wranglerPath: string): Promise<number> {\n const { cp, readFile: read, writeFile: write, stat, readdir: list } = await import('node:fs/promises')\n const prefix = ASSETS_PREFIX(staticDir.split(/[\\\\/]/).pop() || 'rsc-static')\n\n try {\n await stat(staticDir)\n } catch {\n return 0\n }\n\n let copied = 0\n const count = async (dir: string): Promise<void> => {\n for (const entry of await list(dir, { withFileTypes: true })) {\n if (entry.isDirectory()) await count(join(dir, entry.name))\n else copied++\n }\n }\n\n await count(staticDir)\n await cp(staticDir, join(publicDir, prefix), { recursive: true })\n\n // Moved, not copied: wrangler's default rules upload every .html and\n // .txt under the server directory as a text module, and 573 stored\n // shells left beside the bundle were 55 MB of modules against a 10 MB\n // limit - a deploy that happened to fit, once.\n const { rm } = await import('node:fs/promises')\n\n await rm(staticDir, { recursive: true, force: true })\n\n try {\n const config = JSON.parse(await read(wranglerPath, 'utf-8')) as {\n assets?: { run_worker_first?: boolean | string[] } & Record<string, unknown>\n }\n\n if (config.assets && config.assets.run_worker_first !== true) {\n const first = Array.isArray(config.assets.run_worker_first) ? config.assets.run_worker_first : []\n const pattern = `/${prefix}/*`\n\n if (!first.includes(pattern)) config.assets.run_worker_first = [...first, pattern]\n\n await write(wranglerPath, JSON.stringify(config, null, 2))\n }\n } catch {\n // No wrangler.json to amend: a deploy config the app writes itself, which\n // then carries the prefix in its own run_worker_first.\n }\n\n return copied\n}\n"]}
package/dist/headers.d.ts CHANGED
@@ -102,3 +102,11 @@ export declare const PER_CLIENT = "private, no-store";
102
102
  * direction.
103
103
  */
104
104
  export declare const REVALIDATE = "public, max-age=0, must-revalidate";
105
+ /**
106
+ * And what a page rendered for one request says.
107
+ *
108
+ * It may have read the visitor's cookies, and nothing in the headers - which
109
+ * leave before the render has finished - can know whether it did. So a shared
110
+ * cache may not keep it; the visitor's own browser may, and must ask again.
111
+ */
112
+ export declare const PER_REQUEST = "private, max-age=0, must-revalidate";
package/dist/headers.js CHANGED
@@ -117,4 +117,12 @@ export const PER_CLIENT = 'private, no-store';
117
117
  * direction.
118
118
  */
119
119
  export const REVALIDATE = 'public, max-age=0, must-revalidate';
120
+ /**
121
+ * And what a page rendered for one request says.
122
+ *
123
+ * It may have read the visitor's cookies, and nothing in the headers - which
124
+ * leave before the render has finished - can know whether it did. So a shared
125
+ * cache may not keep it; the visitor's own browser may, and must ask again.
126
+ */
127
+ export const PER_REQUEST = 'private, max-age=0, must-revalidate';
120
128
  //# sourceMappingURL=headers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"headers.js","sourceRoot":"","sources":["../src/headers.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,EAAE;AACF,0EAA0E;AAC1E,sEAAsE;AACtE,wEAAwE;AACxE,2EAA2E;AAC3E,gCAAgC;AAChC,EAAE;AACF,gFAAgF;AAEhF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB;;;OAGG;IACH,GAAG,EAAE,OAAO;IAEZ,iFAAiF;IACjF,QAAQ,EAAE,gBAAgB;IAE1B,kEAAkE;IAClE,YAAY,EAAE,qBAAqB;IAEnC,wCAAwC;IACxC,OAAO,EAAE,eAAe;IAExB,gFAAgF;IAChF,OAAO,EAAE,eAAe;IAExB,uDAAuD;IACvD,SAAS,EAAE,iBAAiB;IAE5B,gDAAgD;IAChD,OAAO,EAAE,eAAe;IAExB,uEAAuE;IACvE,UAAU,EAAE,kBAAkB;IAE9B,0CAA0C;IAC1C,MAAM,EAAE,cAAc;IAEtB;;;;;;;OAOG;IACH,QAAQ,EAAE,gBAAgB;IAE1B;;;;;;OAMG;IACH,WAAW,EAAE,oBAAoB;IAEjC;;;;;OAKG;IACH,UAAU,EAAE,cAAc;IAC1B;;;;;;;;;OASG;IACH;;;;;;;OAOG;IACH,KAAK,EAAE,aAAa;IAEpB,SAAS,EAAE,aAAa;IACxB,mEAAmE;IACnE,YAAY,EAAE,iBAAiB;IAC/B,uDAAuD;IACvD,aAAa,EAAE,kBAAkB;CACzB,CAAA;AAEV,sBAAsB;AACtB,MAAM,CAAC,MAAM,WAAW,GAAG,iCAAiC,CAAA;AAE5D,2BAA2B;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,0BAA0B,CAAA;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,CAAC,GAAG;IACV,MAAM,CAAC,QAAQ;IACf,MAAM,CAAC,UAAU;IACjB,MAAM,CAAC,SAAS;IAChB,MAAM,CAAC,OAAO;CACf,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAEZ;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAA;AAE7C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,oCAAoC,CAAA","sourcesContent":["// The wire protocol, as names rather than string literals.\n//\n// A host writing these out by hand is how they drift. Two of them are not\n// negotiable at all — the client sends them or asks for them at fixed\n// addresses, and a host that spells one differently fails silently: the\n// request falls through, the decoder never runs, and a button does nothing\n// with no error on either side.\n//\n// PROTOCOL.md describes what each one means. This is the same list, importable.\n\nexport const HEADER = {\n /**\n * Present on a request for a Flight payload rather than the document. One\n * url serves both, which is why every answer must Vary on it.\n */\n rsc: 'X-RSC',\n\n /** The layout chain the client has mounted, outermost first, comma-separated. */\n segments: 'X-RSC-Segments',\n\n /** The boundary the answer replaces. 0 means a whole document. */\n segmentDepth: 'X-RSC-Segment-Depth',\n\n /** The chain to send back next time. */\n layouts: 'X-RSC-Layouts',\n\n /** Identifies the build, so a client can notice it is talking to an old one. */\n version: 'X-RSC-Version',\n\n /** The slot an intercepted navigation is targeting. */\n intercept: 'X-RSC-Intercept',\n\n /** Where the navigation or action came from. */\n referer: 'X-RSC-Referer',\n\n /** One named region of the current page to render and return alone. */\n revalidate: 'X-RSC-Revalidate',\n\n /** The server reference being invoked. */\n action: 'X-RSC-Action',\n\n /**\n * Go here instead.\n *\n * Used for a redirect the client has to perform itself: a failed action, and\n * a navigation whose render redirected. Never a 3xx for those — `fetch`\n * follows one transparently, so the client would get the destination's HTML\n * where it expected a Flight payload and decode it as one.\n */\n redirect: 'X-RSC-Redirect',\n\n /**\n * The body's real type.\n *\n * The body itself goes out as application/octet-stream so a host that parses\n * multipart cannot consume it before the action does — reading Content-Type\n * instead leaves an upload undecodable.\n */\n contentType: 'X-RSC-Content-Type',\n\n /**\n * Where the browser posts server actions.\n *\n * Not a convention this can choose: the client runtime posts here\n * unconditionally.\n */\n actionPath: '/_rsc/action',\n /**\n * Where the browser reads queries.\n *\n * A GET, and that is the whole point of it being a separate address: a POST\n * is cacheable by nothing, so a read routed through the action endpoint can\n * never be kept by an HTTP cache, a CDN or a service worker. Only functions\n * declared with `query()` are reachable here — the endpoint checks the mark\n * before invoking anything, because otherwise this address would run any\n * registered action over GET.\n */\n /**\n * Sent on every read, and required by the query endpoint.\n *\n * A GET with no unusual header is a simple request, so any page could\n * trigger one with an <img> and the visitor's cookies would ride along.\n * This header is not CORS-safelisted, so the browser preflights it — the\n * same thing that makes a POST carrying X-RSC-Action safe.\n */\n query: 'X-RSC-Query',\n\n queryPath: '/_rsc/query',\n /** Build-time shell for a PPR route, for an edge cache to hold. */\n pprShellPath: '/_rsc/ppr-shell',\n /** Finish a shell an edge cache is already serving. */\n pprResumePath: '/_rsc/ppr-resume',\n} as const\n\n/** Flight payload. */\nexport const FLIGHT_TYPE = 'text/x-component; charset=utf-8'\n\n/** A rendered document. */\nexport const HTML_TYPE = 'text/html; charset=utf-8'\n\n/**\n * Every request header that changes what a response body contains.\n *\n * One url answers with a whole document, a partial payload, a named region or\n * an interceptor depending on these — so a cache keyed on the url alone, or on\n * `X-RSC` alone, will hand one client another's answer. They are materially\n * different bodies, not variations in presentation.\n */\nexport const VARY_ON_RSC = [\n HEADER.rsc,\n HEADER.segments,\n HEADER.revalidate,\n HEADER.intercept,\n HEADER.referer,\n].join(', ')\n\n/**\n * What a response says about being stored, when it must not be.\n *\n * `Vary` alone is not enough on the platform this targets. Cloudflare ignores\n * `Vary` for everything except `Accept-Encoding`, and this package ships a\n * Workers story as a headline feature — so one url answering with a document,\n * a Flight payload, a segment and an interceptor, keyed only on the url, hands\n * one visitor another's body. Anything narrowed by a request header, and\n * anything behind a guard, says outright that it is not to be stored.\n */\nexport const PER_CLIENT = 'private, no-store'\n\n/**\n * And what a frozen, unguarded page says.\n *\n * Explicit rather than absent: with no directive at all, whether an\n * intermediary stores it comes down to that intermediary's heuristics, which\n * is not a decision this package should be leaving to chance in either\n * direction.\n */\nexport const REVALIDATE = 'public, max-age=0, must-revalidate'\n"]}
1
+ {"version":3,"file":"headers.js","sourceRoot":"","sources":["../src/headers.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,EAAE;AACF,0EAA0E;AAC1E,sEAAsE;AACtE,wEAAwE;AACxE,2EAA2E;AAC3E,gCAAgC;AAChC,EAAE;AACF,gFAAgF;AAEhF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB;;;OAGG;IACH,GAAG,EAAE,OAAO;IAEZ,iFAAiF;IACjF,QAAQ,EAAE,gBAAgB;IAE1B,kEAAkE;IAClE,YAAY,EAAE,qBAAqB;IAEnC,wCAAwC;IACxC,OAAO,EAAE,eAAe;IAExB,gFAAgF;IAChF,OAAO,EAAE,eAAe;IAExB,uDAAuD;IACvD,SAAS,EAAE,iBAAiB;IAE5B,gDAAgD;IAChD,OAAO,EAAE,eAAe;IAExB,uEAAuE;IACvE,UAAU,EAAE,kBAAkB;IAE9B,0CAA0C;IAC1C,MAAM,EAAE,cAAc;IAEtB;;;;;;;OAOG;IACH,QAAQ,EAAE,gBAAgB;IAE1B;;;;;;OAMG;IACH,WAAW,EAAE,oBAAoB;IAEjC;;;;;OAKG;IACH,UAAU,EAAE,cAAc;IAC1B;;;;;;;;;OASG;IACH;;;;;;;OAOG;IACH,KAAK,EAAE,aAAa;IAEpB,SAAS,EAAE,aAAa;IACxB,mEAAmE;IACnE,YAAY,EAAE,iBAAiB;IAC/B,uDAAuD;IACvD,aAAa,EAAE,kBAAkB;CACzB,CAAA;AAEV,sBAAsB;AACtB,MAAM,CAAC,MAAM,WAAW,GAAG,iCAAiC,CAAA;AAE5D,2BAA2B;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,0BAA0B,CAAA;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,CAAC,GAAG;IACV,MAAM,CAAC,QAAQ;IACf,MAAM,CAAC,UAAU;IACjB,MAAM,CAAC,SAAS;IAChB,MAAM,CAAC,OAAO;CACf,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAEZ;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAA;AAE7C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,oCAAoC,CAAA;AAE9D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,qCAAqC,CAAA","sourcesContent":["// The wire protocol, as names rather than string literals.\n//\n// A host writing these out by hand is how they drift. Two of them are not\n// negotiable at all — the client sends them or asks for them at fixed\n// addresses, and a host that spells one differently fails silently: the\n// request falls through, the decoder never runs, and a button does nothing\n// with no error on either side.\n//\n// PROTOCOL.md describes what each one means. This is the same list, importable.\n\nexport const HEADER = {\n /**\n * Present on a request for a Flight payload rather than the document. One\n * url serves both, which is why every answer must Vary on it.\n */\n rsc: 'X-RSC',\n\n /** The layout chain the client has mounted, outermost first, comma-separated. */\n segments: 'X-RSC-Segments',\n\n /** The boundary the answer replaces. 0 means a whole document. */\n segmentDepth: 'X-RSC-Segment-Depth',\n\n /** The chain to send back next time. */\n layouts: 'X-RSC-Layouts',\n\n /** Identifies the build, so a client can notice it is talking to an old one. */\n version: 'X-RSC-Version',\n\n /** The slot an intercepted navigation is targeting. */\n intercept: 'X-RSC-Intercept',\n\n /** Where the navigation or action came from. */\n referer: 'X-RSC-Referer',\n\n /** One named region of the current page to render and return alone. */\n revalidate: 'X-RSC-Revalidate',\n\n /** The server reference being invoked. */\n action: 'X-RSC-Action',\n\n /**\n * Go here instead.\n *\n * Used for a redirect the client has to perform itself: a failed action, and\n * a navigation whose render redirected. Never a 3xx for those — `fetch`\n * follows one transparently, so the client would get the destination's HTML\n * where it expected a Flight payload and decode it as one.\n */\n redirect: 'X-RSC-Redirect',\n\n /**\n * The body's real type.\n *\n * The body itself goes out as application/octet-stream so a host that parses\n * multipart cannot consume it before the action does — reading Content-Type\n * instead leaves an upload undecodable.\n */\n contentType: 'X-RSC-Content-Type',\n\n /**\n * Where the browser posts server actions.\n *\n * Not a convention this can choose: the client runtime posts here\n * unconditionally.\n */\n actionPath: '/_rsc/action',\n /**\n * Where the browser reads queries.\n *\n * A GET, and that is the whole point of it being a separate address: a POST\n * is cacheable by nothing, so a read routed through the action endpoint can\n * never be kept by an HTTP cache, a CDN or a service worker. Only functions\n * declared with `query()` are reachable here — the endpoint checks the mark\n * before invoking anything, because otherwise this address would run any\n * registered action over GET.\n */\n /**\n * Sent on every read, and required by the query endpoint.\n *\n * A GET with no unusual header is a simple request, so any page could\n * trigger one with an <img> and the visitor's cookies would ride along.\n * This header is not CORS-safelisted, so the browser preflights it — the\n * same thing that makes a POST carrying X-RSC-Action safe.\n */\n query: 'X-RSC-Query',\n\n queryPath: '/_rsc/query',\n /** Build-time shell for a PPR route, for an edge cache to hold. */\n pprShellPath: '/_rsc/ppr-shell',\n /** Finish a shell an edge cache is already serving. */\n pprResumePath: '/_rsc/ppr-resume',\n} as const\n\n/** Flight payload. */\nexport const FLIGHT_TYPE = 'text/x-component; charset=utf-8'\n\n/** A rendered document. */\nexport const HTML_TYPE = 'text/html; charset=utf-8'\n\n/**\n * Every request header that changes what a response body contains.\n *\n * One url answers with a whole document, a partial payload, a named region or\n * an interceptor depending on these — so a cache keyed on the url alone, or on\n * `X-RSC` alone, will hand one client another's answer. They are materially\n * different bodies, not variations in presentation.\n */\nexport const VARY_ON_RSC = [\n HEADER.rsc,\n HEADER.segments,\n HEADER.revalidate,\n HEADER.intercept,\n HEADER.referer,\n].join(', ')\n\n/**\n * What a response says about being stored, when it must not be.\n *\n * `Vary` alone is not enough on the platform this targets. Cloudflare ignores\n * `Vary` for everything except `Accept-Encoding`, and this package ships a\n * Workers story as a headline feature — so one url answering with a document,\n * a Flight payload, a segment and an interceptor, keyed only on the url, hands\n * one visitor another's body. Anything narrowed by a request header, and\n * anything behind a guard, says outright that it is not to be stored.\n */\nexport const PER_CLIENT = 'private, no-store'\n\n/**\n * And what a frozen, unguarded page says.\n *\n * Explicit rather than absent: with no directive at all, whether an\n * intermediary stores it comes down to that intermediary's heuristics, which\n * is not a decision this package should be leaving to chance in either\n * direction.\n */\nexport const REVALIDATE = 'public, max-age=0, must-revalidate'\n\n/**\n * And what a page rendered for one request says.\n *\n * It may have read the visitor's cookies, and nothing in the headers - which\n * leave before the render has finished - can know whether it did. So a shared\n * cache may not keep it; the visitor's own browser may, and must ask again.\n */\nexport const PER_REQUEST = 'private, max-age=0, must-revalidate'\n"]}
package/dist/host.d.ts CHANGED
@@ -224,4 +224,13 @@ export interface RscHostOptions {
224
224
  * the preflight.
225
225
  */
226
226
  export declare function actionOriginAllowed(request: Request, url: URL): boolean;
227
+ /**
228
+ * A page's props from its url: the query, then the route's params over it.
229
+ *
230
+ * Params last, because a query string may add props and must never replace a
231
+ * param. It did: `?domain=acme` was [domain] - which binds only from the host
232
+ * the request arrived on - set by whoever wrote the link, and a page or guard
233
+ * that trusted it acted for a tenant the visitor was not on.
234
+ */
235
+ export declare function queryAndParams(match: MatchedRoute, request: Request): Record<string, unknown>;
227
236
  export declare function createRscHandler(options: RscHostOptions): (request: Request) => Promise<Response | null>;
package/dist/host.js CHANGED
@@ -40,7 +40,7 @@ export { redirect } from "./redirect.js";
40
40
  // public surface so a host imports from one place.
41
41
  /** @internal For a host adapter. An app never matches its own routes. */
42
42
  export { matchIntercept, matchRoute, sharedDepth } from "./routing.js";
43
- import { FLIGHT_TYPE, HEADER, HTML_TYPE, PER_CLIENT, REVALIDATE, VARY_ON_RSC, } from "./headers.js";
43
+ import { FLIGHT_TYPE, HEADER, HTML_TYPE, PER_CLIENT, PER_REQUEST, REVALIDATE, VARY_ON_RSC, } from "./headers.js";
44
44
  import { ServerAuthenticationError, ServerAuthorizationError, } from "./js/errors.js";
45
45
  /**
46
46
  * The answer to a redirect that was decided before anything was written.
@@ -212,6 +212,8 @@ export function actionOriginAllowed(request, url) {
212
212
  }
213
213
  }
214
214
  const DEFAULT_MAX_ACTION_BODY = 8 * 1024 * 1024;
215
+ /** A form post whose body passed the ceiling: answered 413, never rendered. */
216
+ const TOO_LARGE = Symbol("too large");
215
217
  /**
216
218
  * The body, read whole, or null once it has passed the ceiling.
217
219
  *
@@ -284,9 +286,56 @@ const MAX_QUERY = 8_000;
284
286
  * are keyed by, and the matcher alone is told the leading part is the host's.
285
287
  */
286
288
  const hostOf = new WeakMap();
289
+ /** The stored file a response was read from, which is what its compressed bytes are kept under. */
290
+ const storedAs = new WeakMap();
287
291
  function matchPage(routes, url) {
288
292
  return matchRoute(routes, url.pathname, hostOf.get(url) ?? null);
289
293
  }
294
+ /**
295
+ * Whether anything decides who may see a route: a `middleware.ts` of the
296
+ * engine's, or middleware the host runs (`export const middleware = ['auth']`).
297
+ *
298
+ * One answer for every place that asks. Several asked only about the engine's,
299
+ * so a route guarded in the host's vocabulary - the one a Laravel app uses -
300
+ * had its shell handed out by the edge endpoint, was marked public, and was
301
+ * kept by the service worker.
302
+ */
303
+ function isGuarded(match) {
304
+ return (match?.route.middleware?.length ?? 0) > 0 || (match?.route.hostMiddleware?.length ?? 0) > 0;
305
+ }
306
+ /** What a stored file's name may end in beyond its url, which a url must not name itself. */
307
+ const STORED_SUFFIX = /\.(?:ppr|seg\d+|redirect|postponed|ppr-meta|meta)$/;
308
+ /**
309
+ * The name a url's stored files are under, or null when it may not read any.
310
+ *
311
+ * A stored page is found by name, and its guard by matching the url - so any
312
+ * url that NAMES another page's file without matching that page's route read
313
+ * it past its guard. `/admin.ppr` named the shell of the guarded `/admin`, and
314
+ * `/index` named the root page, skipping the root's middleware. So: only a url
315
+ * that matched a route reads anything, never one that spells the root's name,
316
+ * and never one ending in a suffix the build adds to a name.
317
+ */
318
+ function storedKeyFor(pathname, match) {
319
+ if (!match)
320
+ return null;
321
+ const key = pathKey(pathname);
322
+ if (key === "index" && pathname.replace(/\//g, "") !== "")
323
+ return null;
324
+ if (STORED_SUFFIX.test(key.slice(key.lastIndexOf("/") + 1)))
325
+ return null;
326
+ return key;
327
+ }
328
+ /**
329
+ * A page's props from its url: the query, then the route's params over it.
330
+ *
331
+ * Params last, because a query string may add props and must never replace a
332
+ * param. It did: `?domain=acme` was [domain] - which binds only from the host
333
+ * the request arrived on - set by whoever wrote the link, and a page or guard
334
+ * that trusted it acted for a tenant the visitor was not on.
335
+ */
336
+ export function queryAndParams(match, request) {
337
+ return { ...Object.fromEntries(new URL(request.url).searchParams), ...match.params };
338
+ }
290
339
  export function createRscHandler(options) {
291
340
  const { engine, assets } = options;
292
341
  // The build's own id, which is also what every document says it is - the
@@ -334,7 +383,9 @@ export function createRscHandler(options) {
334
383
  const source = options.prerendered;
335
384
  if (!source)
336
385
  return false;
337
- const key = pathKey(url.pathname);
386
+ const key = storedKeyFor(url.pathname, match);
387
+ if (key === null)
388
+ return false;
338
389
  if ((await source(`${key}.html`)) !== null)
339
390
  return false;
340
391
  if ((await source(`${key}.ppr.html`)) !== null)
@@ -430,8 +481,15 @@ export function createRscHandler(options) {
430
481
  return null;
431
482
  if (!actionOriginAllowed(request, url))
432
483
  return null;
484
+ // Through the same ceiling as an action. This path is reached with no
485
+ // guard and no session - any page url - and formData() reads whatever
486
+ // arrives: 50 MB posted to / was held whole while the action endpoint
487
+ // refused the same body with 413.
488
+ const body = await readBodyUpTo(request, maxActionBody);
489
+ if (body === null)
490
+ return TOO_LARGE;
433
491
  try {
434
- return await request.formData();
492
+ return await new Response(body, { headers: { "content-type": type } }).formData();
435
493
  }
436
494
  catch {
437
495
  return null;
@@ -447,14 +505,21 @@ export function createRscHandler(options) {
447
505
  * as Flight, silently, on every stored page in production.
448
506
  */
449
507
  function storedKey(request, response) {
450
- const url = new URL(request.url);
508
+ // The file that was served, not the url that asked for it. Keyed by url,
509
+ // two hosts routed to different pages - admin.example.com/ and
510
+ // example.com/ - shared one entry, and whichever was compressed first was
511
+ // what both got: the admin page, to anyone. And every distinct query was
512
+ // a new entry, so a thousand ?x= requests emptied the cache on demand.
513
+ const file = storedAs.get(response);
514
+ if (file === undefined)
515
+ return undefined;
451
516
  const varies = (response.headers.get("Vary") ?? "")
452
517
  .split(",")
453
518
  .map((name) => name.trim().toLowerCase())
454
519
  .filter((name) => name && name !== "*" && name !== "accept-encoding")
455
520
  .sort()
456
521
  .map((name) => `${name}=${request.headers.get(name) ?? ""}`);
457
- return [version ?? "", url.pathname + url.search, ...varies].join("\n");
522
+ return [version ?? "", file, ...varies].join("\n");
458
523
  }
459
524
  return async function handle(request) {
460
525
  if (version === undefined && engine.buildId)
@@ -628,7 +693,11 @@ export function createRscHandler(options) {
628
693
  // what the guide promises for a form that had to work without
629
694
  // javascript. Same-origin, as an action is; anything else that is not
630
695
  // a read is not this host's.
631
- const formPost = await formPostOf(request, url);
696
+ const posted = await formPostOf(request, url);
697
+ if (posted === TOO_LARGE) {
698
+ return new Response(`Form body over ${maxActionBody} bytes`, { status: 413 });
699
+ }
700
+ const formPost = posted;
632
701
  if (!formPost && request.method !== "GET" && request.method !== "HEAD")
633
702
  return null;
634
703
  // A client saying which build it runs, and it is not this one: its
@@ -674,7 +743,7 @@ export function createRscHandler(options) {
674
743
  const refusal = await refuseUnlessAllowed(request, match);
675
744
  if (refusal)
676
745
  return refusal;
677
- const frozen = await servePrerendered(request, url, options.prerendered);
746
+ const frozen = await servePrerendered(request, url, match, options.prerendered);
678
747
  // A whole page from a file, or a shell of one with the holes rendered
679
748
  // now: the header says which. servePrerendered marks the shell.
680
749
  if (frozen && !servedFrom.has(frozen))
@@ -757,11 +826,13 @@ export function createRscHandler(options) {
757
826
  Vary: VARY_ON_RSC,
758
827
  // The answer to a post is the result of something that happened
759
828
  // once; nothing may keep it.
829
+ // Rendered for this request, so it may be this visitor's: never
830
+ // public. A guarded one is not kept at all.
760
831
  "Cache-Control": formPost
761
832
  ? "no-store"
762
- : match.route.middleware?.length
833
+ : isGuarded(match)
763
834
  ? PER_CLIENT
764
- : REVALIDATE,
835
+ : PER_REQUEST,
765
836
  }),
766
837
  });
767
838
  });
@@ -862,9 +933,10 @@ export function createRscHandler(options) {
862
933
  return null;
863
934
  if (request.method !== "GET" && request.method !== "HEAD")
864
935
  return null;
865
- if (api.route.middleware.length > 0)
936
+ if (isGuarded(api))
866
937
  return null;
867
- const stored = await options.prerendered(apiKey(url.pathname));
938
+ const storedName = apiKey(url.pathname);
939
+ const stored = await options.prerendered(storedName);
868
940
  if (stored === null)
869
941
  return null;
870
942
  let frozen;
@@ -891,6 +963,7 @@ export function createRscHandler(options) {
891
963
  headers: withVersion(Object.fromEntries(frozen.headers)),
892
964
  });
893
965
  servedFrom.set(answer, "stored");
966
+ storedAs.set(answer, storedName);
894
967
  return answer;
895
968
  }
896
969
  async function servePprShell(request, url, read) {
@@ -904,10 +977,12 @@ export function createRscHandler(options) {
904
977
  const route = matchRoute(routes, new URL(target, url.origin).pathname);
905
978
  if (!route)
906
979
  return new Response("No such page", { status: 404 });
907
- if (route.route.middleware?.length) {
980
+ if (isGuarded(route)) {
908
981
  return new Response("This route is not edge-cacheable", { status: 404 });
909
982
  }
910
- const key = pathKey(new URL(target, url.origin).pathname);
983
+ const key = storedKeyFor(new URL(target, url.origin).pathname, route);
984
+ if (key === null)
985
+ return new Response("No such page", { status: 404 });
911
986
  const shell = (await read(`${key}.ppr.html`)) ??
912
987
  (await read(`${patternKey(route.route)}.ppr.html`));
913
988
  if (shell === null)
@@ -960,7 +1035,9 @@ export function createRscHandler(options) {
960
1035
  if (!engine.handleRscResume) {
961
1036
  return new Response("This engine cannot resume", { status: 500 });
962
1037
  }
963
- const key = pathKey(pathname);
1038
+ const key = storedKeyFor(pathname, route);
1039
+ if (key === null)
1040
+ return new Response("No such page", { status: 404 });
964
1041
  const pattern = patternKey(route.route);
965
1042
  let shellKey = null;
966
1043
  if ((await read(`${key}.ppr.html`)) !== null)
@@ -986,8 +1063,10 @@ export function createRscHandler(options) {
986
1063
  }),
987
1064
  });
988
1065
  }
989
- async function servePrerendered(request, url, source) {
990
- const key = pathKey(url.pathname);
1066
+ async function servePrerendered(request, url, route, source) {
1067
+ const key = storedKeyFor(url.pathname, route);
1068
+ if (key === null)
1069
+ return null;
991
1070
  const read = async (name) => await source(name);
992
1071
  // Before anything else: a route that only redirects was frozen as the
993
1072
  // redirect itself, so there is no page under this url and never will be.
@@ -1001,7 +1080,6 @@ export function createRscHandler(options) {
1001
1080
  // pattern. Nothing in a shell varies by param, so one shell serves every
1002
1081
  // url its route matches — which is the only way a route whose urls were
1003
1082
  // never listed gets anything frozen at all.
1004
- const route = matchPage(routes, url);
1005
1083
  const whole = await read(`${key}.html`);
1006
1084
  // A whole page is finished. Nothing to resume, nothing to render.
1007
1085
  if (whole !== null) {
@@ -1009,9 +1087,10 @@ export function createRscHandler(options) {
1009
1087
  headers: withVersion({
1010
1088
  "Content-Type": HTML_TYPE,
1011
1089
  Vary: VARY_ON_RSC,
1012
- "Cache-Control": route?.route.middleware?.length
1013
- ? PER_CLIENT
1014
- : REVALIDATE,
1090
+ // A guarded page is still stored - the content is the same for
1091
+ // everyone allowed to see it - but it is never public: the guard
1092
+ // ran for this visitor, and no cache between may answer the next.
1093
+ "Cache-Control": isGuarded(route) ? PER_CLIENT : REVALIDATE,
1015
1094
  }),
1016
1095
  });
1017
1096
  // Its head is in hand, so its fonts are too. Read once per file.
@@ -1021,6 +1100,7 @@ export function createRscHandler(options) {
1021
1100
  hintsByKey.set(key, found);
1022
1101
  }
1023
1102
  hinted.set(response, found);
1103
+ storedAs.set(response, `${key}.html`);
1024
1104
  return response;
1025
1105
  }
1026
1106
  // Then a shell, under this url or under the route's pattern. Which of the
@@ -1130,9 +1210,9 @@ export function createRscHandler(options) {
1130
1210
  unresumable.add(shellKey);
1131
1211
  console.warn(`[rsc-kit] The stored shell for ${shellKey} cannot be finished by this server: React found different ` +
1132
1212
  "components in the slots it recorded, so its holes were left to the browser. Pages under it will be " +
1133
- "rendered whole from now on. A second bundler between the build and the server is the usual cause - " +
1134
- "bun build --compile merges module scopes and renames components, and a name is how a replay matches " +
1135
- "a slot. Prerender and serve the same bundle, or run the built server rather than a compiled binary.");
1213
+ "rendered whole from now on. A replay matches a slot by component name, so something renamed a " +
1214
+ "component between the build and this server - a bundler run over the build's output, or code that " +
1215
+ "renders a different component above a <Suspense> than it did at build.");
1136
1216
  }
1137
1217
  }
1138
1218
  },
@@ -1179,8 +1259,8 @@ export function createRscHandler(options) {
1179
1259
  // Marked no-store, the service worker refused to keep it, and a
1180
1260
  // precached page rendered offline and never hydrated - the markup was
1181
1261
  // there and the payload it boots from was not.
1182
- const guarded = matchPage(routes, url)?.route.middleware?.length ?? 0;
1183
- return new Response(payload, {
1262
+ const guarded = isGuarded(route);
1263
+ const answer = new Response(payload, {
1184
1264
  headers: withVersion({
1185
1265
  "Content-Type": FLIGHT_TYPE,
1186
1266
  [HEADER.segmentDepth]: String(variant ? shared : 0),
@@ -1189,6 +1269,8 @@ export function createRscHandler(options) {
1189
1269
  "Cache-Control": guarded ? PER_CLIENT : REVALIDATE,
1190
1270
  }),
1191
1271
  });
1272
+ storedAs.set(answer, variant ? `${key}.seg${shared}.flight` : `${key}.flight`);
1273
+ return answer;
1192
1274
  }
1193
1275
  /**
1194
1276
  * The middleware of a route, or null to go ahead.
@@ -1207,9 +1289,7 @@ export function createRscHandler(options) {
1207
1289
  // until the build froze the page, then silently stop.
1208
1290
  if (!match)
1209
1291
  return null;
1210
- const guarded = (match.route.middleware?.length ?? 0) > 0 ||
1211
- (match.route.hostMiddleware?.length ?? 0) > 0;
1212
- if (!guarded)
1292
+ if (!isGuarded(match))
1213
1293
  return null;
1214
1294
  // A route that declares middleware and an engine that cannot run it is not
1215
1295
  // "no middleware" — it is a check that silently does not happen. Refusing
@@ -1363,7 +1443,7 @@ export function createRscHandler(options) {
1363
1443
  * HTML as though it were the api's answer.
1364
1444
  */
1365
1445
  async function refuseApiUnlessAllowed(request, api) {
1366
- if (!(api.route.middleware?.length ?? 0))
1446
+ if (!isGuarded(api))
1367
1447
  return null;
1368
1448
  // A route that declares middleware and an engine that cannot run it is not
1369
1449
  // "no middleware" — it is a check that silently does not happen.