@rsc-kit/core 0.31.2 → 0.32.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.
package/dist/devLock.d.ts CHANGED
@@ -11,7 +11,10 @@
11
11
  * `bun run dev` in a terminal.
12
12
  *
13
13
  * So the first dev server holds a lock in Vite's cache directory - the thing
14
- * they share - and a second one refuses to start, naming the first.
14
+ * they share - and a second one waits, naming the first, and starts when it
15
+ * stops. Waiting rather than exiting: `artisan dev` restarts a process that
16
+ * exits, so a refusal printed itself five times and gave up, and the app was
17
+ * left with no dev server once the first was stopped.
15
18
  */
16
19
  export interface DevServerHolder {
17
20
  pid: number;
@@ -27,4 +30,12 @@ export declare function claimDevServer(cacheDir: string, pid?: number): DevServe
27
30
  export declare function recordDevServerUrl(cacheDir: string, url: string, pid?: number): void;
28
31
  /** Lets go of the lock, if this process holds it. */
29
32
  export declare function releaseDevServer(cacheDir: string, pid?: number): void;
33
+ /**
34
+ * Waits until this process holds the lock: the holder stopped, or is gone.
35
+ * Resolves at once when the lock was free.
36
+ */
37
+ export declare function waitForDevServer(cacheDir: string, { pid, every }?: {
38
+ pid?: number;
39
+ every?: number;
40
+ }): Promise<void>;
30
41
  export declare function secondDevServerMessage(root: string, held: DevServerHolder): string;
package/dist/devLock.js CHANGED
@@ -11,7 +11,10 @@
11
11
  * `bun run dev` in a terminal.
12
12
  *
13
13
  * So the first dev server holds a lock in Vite's cache directory - the thing
14
- * they share - and a second one refuses to start, naming the first.
14
+ * they share - and a second one waits, naming the first, and starts when it
15
+ * stops. Waiting rather than exiting: `artisan dev` restarts a process that
16
+ * exits, so a refusal printed itself five times and gave up, and the app was
17
+ * left with no dev server once the first was stopped.
15
18
  */
16
19
  import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
17
20
  import { join } from "node:path";
@@ -64,11 +67,20 @@ export function releaseDevServer(cacheDir, pid = process.pid) {
64
67
  }
65
68
  catch { }
66
69
  }
70
+ /**
71
+ * Waits until this process holds the lock: the holder stopped, or is gone.
72
+ * Resolves at once when the lock was free.
73
+ */
74
+ export async function waitForDevServer(cacheDir, { pid = process.pid, every = 1000 } = {}) {
75
+ while (claimDevServer(cacheDir, pid)) {
76
+ await new Promise((resolve) => setTimeout(resolve, every));
77
+ }
78
+ }
67
79
  export function secondDevServerMessage(root, held) {
68
- return (`[rsc-kit] Another dev server is already running for ${root} ` +
69
- `(pid ${held.pid}${held.url ? `, ${held.url}` : ""}). ` +
70
- "Two would share one pre-bundle cache and one hot file, and break each other: " +
71
- "stale pre-bundles (ERR_OUTDATED_OPTIMIZED_DEP), and a backend that loses the renderer when either stops. " +
72
- "Stop that one, or use it - an editor or `artisan dev` may have started it for you.");
80
+ return (`[rsc-kit] A dev server is already running for ${root} ` +
81
+ `(pid ${held.pid}${held.url ? `, ${held.url}` : ""}) - use that one. ` +
82
+ "This one waits and starts when it stops: two at once would share one pre-bundle cache " +
83
+ "and one hot file, and break each other (ERR_OUTDATED_OPTIMIZED_DEP). " +
84
+ "An editor, Herd or `artisan dev` may have started the first for you.");
73
85
  }
74
86
  //# sourceMappingURL=devLock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"devLock.js","sourceRoot":"","sources":["../src/devLock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAOhC,MAAM,QAAQ,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAE5D,SAAS,KAAK,CAAC,GAAW;IACxB,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAErB,OAAO,IAAI,CAAC;IACd,CAAC;IAA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AE,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,gBAAgB,CAAC,QAAgB,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG;IAClE,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,KAAK,GAAG;QAAE,OAAO;IAExC,IAAI,CAAC;QACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAY,EAAE,IAAqB;IACxE,OAAO,CACL,uDAAuD,IAAI,GAAG;QAC9D,QAAQ,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK;QACvD,+EAA+E;QAC/E,2GAA2G;QAC3G,oFAAoF,CACrF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * One dev server per app.\n *\n * Two `vite dev` processes in one project share everything that makes dev\n * work: Vite's pre-bundle cache, rsc-host.json and the hot file the backend\n * finds the renderer by. Each re-bundles the cache under the other, which\n * answers its next request with ERR_OUTDATED_OPTIMIZED_DEP; each writes the\n * hot file, and the one stopped first deletes it from under the one still\n * running, so the backend reports no renderer at all. Nothing pointed at the\n * cause. It happens easily: `artisan dev` started by an editor or Herd, and\n * `bun run dev` in a terminal.\n *\n * So the first dev server holds a lock in Vite's cache directory - the thing\n * they share - and a second one refuses to start, naming the first.\n */\n\nimport { mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nconst LOCK = \"rsc-kit-dev.json\";\n\nexport interface DevServerHolder {\n pid: number;\n url?: string;\n}\n\nconst lockPath = (cacheDir: string) => join(cacheDir, LOCK);\n\nfunction alive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n\n return true;\n } catch (error) {\n // EPERM: it exists, and belongs to someone else.\n return (error as NodeJS.ErrnoException).code === \"EPERM\";\n }\n}\n\nfunction read(cacheDir: string): DevServerHolder | null {\n try {\n const held = JSON.parse(readFileSync(lockPath(cacheDir), \"utf-8\")) as DevServerHolder;\n\n return Number.isInteger(held?.pid) ? held : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Takes the lock for this process, or returns the dev server that holds it.\n * A lock left by a process that is gone - killed, crashed - is taken over.\n * This process's own (a restart) is kept.\n */\nexport function claimDevServer(cacheDir: string, pid = process.pid): DevServerHolder | null {\n const held = read(cacheDir);\n\n if (held && held.pid !== pid && alive(held.pid)) return held;\n\n mkdirSync(cacheDir, { recursive: true });\n writeFileSync(lockPath(cacheDir), JSON.stringify({ pid }));\n\n return null;\n}\n\n/** Records where this server listens, for the message a second one prints. */\nexport function recordDevServerUrl(cacheDir: string, url: string, pid = process.pid): void {\n if (read(cacheDir)?.pid !== pid) return;\n\n writeFileSync(lockPath(cacheDir), JSON.stringify({ pid, url }));\n}\n\n/** Lets go of the lock, if this process holds it. */\nexport function releaseDevServer(cacheDir: string, pid = process.pid): void {\n if (read(cacheDir)?.pid !== pid) return;\n\n try {\n rmSync(lockPath(cacheDir));\n } catch {}\n}\n\nexport function secondDevServerMessage(root: string, held: DevServerHolder): string {\n return (\n `[rsc-kit] Another dev server is already running for ${root} ` +\n `(pid ${held.pid}${held.url ? `, ${held.url}` : \"\"}). ` +\n \"Two would share one pre-bundle cache and one hot file, and break each other: \" +\n \"stale pre-bundles (ERR_OUTDATED_OPTIMIZED_DEP), and a backend that loses the renderer when either stops. \" +\n \"Stop that one, or use it - an editor or `artisan dev` may have started it for you.\"\n );\n}\n"]}
1
+ {"version":3,"file":"devLock.js","sourceRoot":"","sources":["../src/devLock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,IAAI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E;QACvE,sEAAsE,CACvE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * One dev server per app.\n *\n * Two `vite dev` processes in one project share everything that makes dev\n * work: Vite's pre-bundle cache, rsc-host.json and the hot file the backend\n * finds the renderer by. Each re-bundles the cache under the other, which\n * answers its next request with ERR_OUTDATED_OPTIMIZED_DEP; each writes the\n * hot file, and the one stopped first deletes it from under the one still\n * running, so the backend reports no renderer at all. Nothing pointed at the\n * cause. It happens easily: `artisan dev` started by an editor or Herd, and\n * `bun run dev` in a terminal.\n *\n * So the first dev server holds a lock in Vite's cache directory - the thing\n * they share - and a second one waits, naming the first, and starts when it\n * stops. Waiting rather than exiting: `artisan dev` restarts a process that\n * exits, so a refusal printed itself five times and gave up, and the app was\n * left with no dev server once the first was stopped.\n */\n\nimport { mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nconst LOCK = \"rsc-kit-dev.json\";\n\nexport interface DevServerHolder {\n pid: number;\n url?: string;\n}\n\nconst lockPath = (cacheDir: string) => join(cacheDir, LOCK);\n\nfunction alive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n\n return true;\n } catch (error) {\n // EPERM: it exists, and belongs to someone else.\n return (error as NodeJS.ErrnoException).code === \"EPERM\";\n }\n}\n\nfunction read(cacheDir: string): DevServerHolder | null {\n try {\n const held = JSON.parse(readFileSync(lockPath(cacheDir), \"utf-8\")) as DevServerHolder;\n\n return Number.isInteger(held?.pid) ? held : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Takes the lock for this process, or returns the dev server that holds it.\n * A lock left by a process that is gone - killed, crashed - is taken over.\n * This process's own (a restart) is kept.\n */\nexport function claimDevServer(cacheDir: string, pid = process.pid): DevServerHolder | null {\n const held = read(cacheDir);\n\n if (held && held.pid !== pid && alive(held.pid)) return held;\n\n mkdirSync(cacheDir, { recursive: true });\n writeFileSync(lockPath(cacheDir), JSON.stringify({ pid }));\n\n return null;\n}\n\n/** Records where this server listens, for the message a second one prints. */\nexport function recordDevServerUrl(cacheDir: string, url: string, pid = process.pid): void {\n if (read(cacheDir)?.pid !== pid) return;\n\n writeFileSync(lockPath(cacheDir), JSON.stringify({ pid, url }));\n}\n\n/** Lets go of the lock, if this process holds it. */\nexport function releaseDevServer(cacheDir: string, pid = process.pid): void {\n if (read(cacheDir)?.pid !== pid) return;\n\n try {\n rmSync(lockPath(cacheDir));\n } catch {}\n}\n\n/**\n * Waits until this process holds the lock: the holder stopped, or is gone.\n * Resolves at once when the lock was free.\n */\nexport async function waitForDevServer(\n cacheDir: string,\n { pid = process.pid, every = 1000 }: { pid?: number; every?: number } = {},\n): Promise<void> {\n while (claimDevServer(cacheDir, pid)) {\n await new Promise((resolve) => setTimeout(resolve, every));\n }\n}\n\nexport function secondDevServerMessage(root: string, held: DevServerHolder): string {\n return (\n `[rsc-kit] A dev server is already running for ${root} ` +\n `(pid ${held.pid}${held.url ? `, ${held.url}` : \"\"}) - use that one. ` +\n \"This one waits and starts when it stops: two at once would share one pre-bundle cache \" +\n \"and one hot file, and break each other (ERR_OUTDATED_OPTIMIZED_DEP). \" +\n \"An editor, Herd or `artisan dev` may have started the first for you.\"\n );\n}\n"]}
@@ -26,6 +26,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
26
26
  * and swallows a second tap; and reduced motion should mean none.
27
27
  */
28
28
  import { ViewTransition, useEffect, useState } from "react";
29
+ import { useNonce } from "./useNonce.js";
29
30
  /**
30
31
  * Whether this browser rasterises a transition snapshot at full element
31
32
  * height. Apple's vendor string is WebKit's, wherever WebKit runs: Safari,
@@ -48,10 +49,13 @@ export function pageTransitionCss(transition, durationMs) {
48
49
  }
49
50
  export function PageTransition({ children, className, transition = "page", duration = 120, webkit = "skip", }) {
50
51
  const [skip, setSkip] = useState(false);
52
+ // React inserts this style itself in the browser when it was not in the
53
+ // HTML it hydrated, and under a policy a style without the nonce is refused.
54
+ const nonce = useNonce();
51
55
  useEffect(() => {
52
56
  if ((webkit === "skip" && snapshotsWholePage()) || prefersReducedMotion())
53
57
  setSkip(true);
54
58
  }, [webkit]);
55
- return (_jsx(ViewTransition, { default: { "rsc-navigation": skip ? "none" : transition, default: "none" }, children: _jsxs("div", { className: className, children: [_jsx("style", { href: `rsc-kit-page-transition-${transition}`, precedence: "rsc-kit", children: pageTransitionCss(transition, duration) }), children] }) }));
59
+ return (_jsx(ViewTransition, { default: { "rsc-navigation": skip ? "none" : transition, default: "none" }, children: _jsxs("div", { className: className, children: [_jsx("style", { href: `rsc-kit-page-transition-${transition}`, precedence: "rsc-kit", nonce: nonce, children: pageTransitionCss(transition, duration) }), children] }) }));
56
60
  }
57
61
  //# sourceMappingURL=PageTransition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PageTransition.js","sourceRoot":"","sources":["../../src/js/PageTransition.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5D;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,MAAM,KAAK,sBAAsB,CAAC;AACzF,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,oBAAoB;IAClC,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,kCAAkC,CAAC,CAAC,OAAO,CAAC;AACnJ,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,iBAAiB,CAAC,UAAkB,EAAE,UAAkB;IACtE,OAAO,CACL,0BAA0B,UAAU,4BAA4B,UAAU,IAAI;QAC9E,yGAAyG,UAAU,KAAK;QACxH,wCAAwC;QACxC,sIAAsI,CACvI,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAC7B,QAAQ,EACR,SAAS,EACT,UAAU,GAAG,MAAM,EACnB,QAAQ,GAAG,GAAG,EACd,MAAM,GAAG,MAAM,GAehB;IACC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,kBAAkB,EAAE,CAAC,IAAI,oBAAoB,EAAE;YAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3F,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO,CACL,KAAC,cAAc,IAAC,OAAO,EAAE,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,YACxF,eAAK,SAAS,EAAE,SAAS,aACvB,gBAAO,IAAI,EAAE,2BAA2B,UAAU,EAAE,EAAE,UAAU,EAAC,SAAS,YACvE,iBAAiB,CAAC,UAAU,EAAE,QAAQ,CAAC,GAClC,EACP,QAAQ,IACL,GACS,CAClB,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\n/**\n * The page-level view transition, with WebKit left out of it.\n *\n * WebKit - Safari, and every browser on iOS, Chrome included - rasterises\n * the outgoing snapshot at the element's full height rather than the\n * viewport's. A landing page 12,000 px tall is 44 megapixels at 3×: a port\n * measured 600-900 ms with the screen frozen on every navigation away from\n * it, and the memory can have iOS discard the tab, which comes back as a\n * reload nobody asked for. Chromium caps the snapshot, so a desktop never\n * shows it. Other sites' transitions work on the same phone because they\n * name the root, which the spec clips to the viewport; React's\n * <ViewTransition> names the element it wraps, and the page is tall.\n *\n * So the cross-fade runs where it is cheap and is skipped where it is not.\n * Decided after mount, from navigator.vendor - a server render has no\n * navigator, and a transition class only matters on an update, so the\n * first render agrees with the server either way. Skipped, React starts\n * no transition at all: no snapshot, no overlay, nothing to wait for.\n *\n * The CSS the fade needs travels with it, because every app rediscovered\n * the same three lines on a phone: the group and root pairs keep the\n * browser's 250 ms whatever the page pair is set to, so a \"120 ms\" fade\n * ran 290; the pseudo-element tree sits over the document while it runs\n * and swallows a second tap; and reduced motion should mean none.\n */\n\nimport { ViewTransition, useEffect, useState } from \"react\";\nimport type { ReactNode } from \"react\";\n\n/**\n * Whether this browser rasterises a transition snapshot at full element\n * height. Apple's vendor string is WebKit's, wherever WebKit runs: Safari,\n * every iOS browser, and WebKitGTK (Epiphany) too - all of them charge by\n * snapshot size, so all of them are right to skip. Not a bug to \"fix\".\n */\nexport function snapshotsWholePage(): boolean {\n return typeof navigator !== \"undefined\" && navigator.vendor === \"Apple Computer, Inc.\";\n}\n\n/** Whether the visitor asked for no motion; a transition then costs a snapshot for nothing. */\nexport function prefersReducedMotion(): boolean {\n return typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\n/** The rules a page fade needs, for the class the navigation carries. */\nexport function pageTransitionCss(transition: string, durationMs: number): string {\n return (\n `::view-transition-old(.${transition}),::view-transition-new(.${transition}),` +\n `::view-transition-group(*),::view-transition-old(root),::view-transition-new(root){animation-duration:${durationMs}ms}` +\n `::view-transition{pointer-events:none}` +\n `@media (prefers-reduced-motion:reduce){::view-transition-old(*),::view-transition-new(*),::view-transition-group(*){animation:none}}`\n );\n}\n\nexport function PageTransition({\n children,\n className,\n transition = \"page\",\n duration = 120,\n webkit = \"skip\",\n}: {\n children: ReactNode;\n /** On the wrapper element the pair is made of; carry the body's layout here. */\n className?: string;\n /** The view-transition class a navigation gets, for CSS of your own on top. */\n transition?: string;\n /** How long the fade runs, in milliseconds. The group and root pairs match it. */\n duration?: number;\n /**\n * What WebKit gets. `skip` for an app with long pages - the default,\n * since a landing page usually is one; `run` for an app whose pages are\n * a screen tall, where the snapshot is small and the fade is fine.\n */\n webkit?: \"skip\" | \"run\";\n}) {\n const [skip, setSkip] = useState(false);\n\n useEffect(() => {\n if ((webkit === \"skip\" && snapshotsWholePage()) || prefersReducedMotion()) setSkip(true);\n }, [webkit]);\n\n return (\n <ViewTransition default={{ \"rsc-navigation\": skip ? \"none\" : transition, default: \"none\" }}>\n <div className={className}>\n <style href={`rsc-kit-page-transition-${transition}`} precedence=\"rsc-kit\">\n {pageTransitionCss(transition, duration)}\n </style>\n {children}\n </div>\n </ViewTransition>\n );\n}\n"]}
1
+ {"version":3,"file":"PageTransition.js","sourceRoot":"","sources":["../../src/js/PageTransition.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,MAAM,KAAK,sBAAsB,CAAC;AACzF,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,oBAAoB;IAClC,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,kCAAkC,CAAC,CAAC,OAAO,CAAC;AACnJ,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,iBAAiB,CAAC,UAAkB,EAAE,UAAkB;IACtE,OAAO,CACL,0BAA0B,UAAU,4BAA4B,UAAU,IAAI;QAC9E,yGAAyG,UAAU,KAAK;QACxH,wCAAwC;QACxC,sIAAsI,CACvI,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAC7B,QAAQ,EACR,SAAS,EACT,UAAU,GAAG,MAAM,EACnB,QAAQ,GAAG,GAAG,EACd,MAAM,GAAG,MAAM,GAehB;IACC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxC,wEAAwE;IACxE,6EAA6E;IAC7E,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IAEzB,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,kBAAkB,EAAE,CAAC,IAAI,oBAAoB,EAAE;YAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3F,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO,CACL,KAAC,cAAc,IAAC,OAAO,EAAE,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,YACxF,eAAK,SAAS,EAAE,SAAS,aACvB,gBAAO,IAAI,EAAE,2BAA2B,UAAU,EAAE,EAAE,UAAU,EAAC,SAAS,EAAC,KAAK,EAAE,KAAK,YACpF,iBAAiB,CAAC,UAAU,EAAE,QAAQ,CAAC,GAClC,EACP,QAAQ,IACL,GACS,CAClB,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\n/**\n * The page-level view transition, with WebKit left out of it.\n *\n * WebKit - Safari, and every browser on iOS, Chrome included - rasterises\n * the outgoing snapshot at the element's full height rather than the\n * viewport's. A landing page 12,000 px tall is 44 megapixels at 3×: a port\n * measured 600-900 ms with the screen frozen on every navigation away from\n * it, and the memory can have iOS discard the tab, which comes back as a\n * reload nobody asked for. Chromium caps the snapshot, so a desktop never\n * shows it. Other sites' transitions work on the same phone because they\n * name the root, which the spec clips to the viewport; React's\n * <ViewTransition> names the element it wraps, and the page is tall.\n *\n * So the cross-fade runs where it is cheap and is skipped where it is not.\n * Decided after mount, from navigator.vendor - a server render has no\n * navigator, and a transition class only matters on an update, so the\n * first render agrees with the server either way. Skipped, React starts\n * no transition at all: no snapshot, no overlay, nothing to wait for.\n *\n * The CSS the fade needs travels with it, because every app rediscovered\n * the same three lines on a phone: the group and root pairs keep the\n * browser's 250 ms whatever the page pair is set to, so a \"120 ms\" fade\n * ran 290; the pseudo-element tree sits over the document while it runs\n * and swallows a second tap; and reduced motion should mean none.\n */\n\nimport { ViewTransition, useEffect, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { useNonce } from \"./useNonce.js\";\n\n/**\n * Whether this browser rasterises a transition snapshot at full element\n * height. Apple's vendor string is WebKit's, wherever WebKit runs: Safari,\n * every iOS browser, and WebKitGTK (Epiphany) too - all of them charge by\n * snapshot size, so all of them are right to skip. Not a bug to \"fix\".\n */\nexport function snapshotsWholePage(): boolean {\n return typeof navigator !== \"undefined\" && navigator.vendor === \"Apple Computer, Inc.\";\n}\n\n/** Whether the visitor asked for no motion; a transition then costs a snapshot for nothing. */\nexport function prefersReducedMotion(): boolean {\n return typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\n/** The rules a page fade needs, for the class the navigation carries. */\nexport function pageTransitionCss(transition: string, durationMs: number): string {\n return (\n `::view-transition-old(.${transition}),::view-transition-new(.${transition}),` +\n `::view-transition-group(*),::view-transition-old(root),::view-transition-new(root){animation-duration:${durationMs}ms}` +\n `::view-transition{pointer-events:none}` +\n `@media (prefers-reduced-motion:reduce){::view-transition-old(*),::view-transition-new(*),::view-transition-group(*){animation:none}}`\n );\n}\n\nexport function PageTransition({\n children,\n className,\n transition = \"page\",\n duration = 120,\n webkit = \"skip\",\n}: {\n children: ReactNode;\n /** On the wrapper element the pair is made of; carry the body's layout here. */\n className?: string;\n /** The view-transition class a navigation gets, for CSS of your own on top. */\n transition?: string;\n /** How long the fade runs, in milliseconds. The group and root pairs match it. */\n duration?: number;\n /**\n * What WebKit gets. `skip` for an app with long pages - the default,\n * since a landing page usually is one; `run` for an app whose pages are\n * a screen tall, where the snapshot is small and the fade is fine.\n */\n webkit?: \"skip\" | \"run\";\n}) {\n const [skip, setSkip] = useState(false);\n // React inserts this style itself in the browser when it was not in the\n // HTML it hydrated, and under a policy a style without the nonce is refused.\n const nonce = useNonce();\n\n useEffect(() => {\n if ((webkit === \"skip\" && snapshotsWholePage()) || prefersReducedMotion()) setSkip(true);\n }, [webkit]);\n\n return (\n <ViewTransition default={{ \"rsc-navigation\": skip ? \"none\" : transition, default: \"none\" }}>\n <div className={className}>\n <style href={`rsc-kit-page-transition-${transition}`} precedence=\"rsc-kit\" nonce={nonce}>\n {pageTransitionCss(transition, duration)}\n </style>\n {children}\n </div>\n </ViewTransition>\n );\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import type { Context } from "react";
2
+ /**
3
+ * The nonce of the response the server is rendering. Set by the server's
4
+ * render around the whole tree; absent in the browser.
5
+ *
6
+ * Kept on a global symbol so the server's entry and the copy of this module
7
+ * the client components were bundled with agree on one context.
8
+ */
9
+ export declare function nonceContext(): Context<string | undefined>;
10
+ /**
11
+ * The nonce the document's own scripts carry. The attribute reads empty once
12
+ * the browser has applied the policy - it hides it from the page's other
13
+ * scripts - so it is the property that is read. Only a found nonce is kept:
14
+ * a shell's holes, and their nonced scripts, can arrive after the first read.
15
+ */
16
+ export declare function nonceOfDocument(): string | undefined;
17
+ export declare function useNonce(): string | undefined;
18
+ export default useNonce;
@@ -0,0 +1,56 @@
1
+ "use client";
2
+ /**
3
+ * The nonce the page's Content-Security-Policy allows inline code by, for a
4
+ * library that writes its own: next-themes' `nonce` prop, a `<style>` a
5
+ * component inserts, an analytics snippet.
6
+ *
7
+ * A client hook, not a server function, because the nonce that matters is
8
+ * the document's. The policy is fixed by the response that delivered the
9
+ * document; a navigation's payload is rendered later, with a nonce of its
10
+ * own that the document has never heard of. A layout handing a server-read
11
+ * nonce down as a prop would hand down the wrong one the first time it was
12
+ * re-rendered by a navigation or a refresh. So the server render supplies the
13
+ * nonce it is writing the document with, and the browser reads it back from
14
+ * the document itself - the scripts React wrote carry it.
15
+ *
16
+ * Undefined where the page has no nonce: no policy, or a page whose inline
17
+ * code is allowed by hash - one stored at build, a shell, a render a cache
18
+ * keeps. An inline script rendered into such a page is hashed with the rest
19
+ * of it and runs without one; code inserted later, after hydration, has
20
+ * nothing to run by.
21
+ */
22
+ import { createContext, useContext } from "react";
23
+ /**
24
+ * The nonce of the response the server is rendering. Set by the server's
25
+ * render around the whole tree; absent in the browser.
26
+ *
27
+ * Kept on a global symbol so the server's entry and the copy of this module
28
+ * the client components were bundled with agree on one context.
29
+ */
30
+ export function nonceContext() {
31
+ const key = Symbol.for("rsc-kit.nonce");
32
+ const store = globalThis;
33
+ return (store[key] ??= createContext(undefined));
34
+ }
35
+ let documentNonce;
36
+ /**
37
+ * The nonce the document's own scripts carry. The attribute reads empty once
38
+ * the browser has applied the policy - it hides it from the page's other
39
+ * scripts - so it is the property that is read. Only a found nonce is kept:
40
+ * a shell's holes, and their nonced scripts, can arrive after the first read.
41
+ */
42
+ export function nonceOfDocument() {
43
+ if (documentNonce || typeof document === "undefined")
44
+ return documentNonce;
45
+ for (const script of document.querySelectorAll("script[nonce]")) {
46
+ if (script.nonce)
47
+ return (documentNonce = script.nonce);
48
+ }
49
+ return undefined;
50
+ }
51
+ export function useNonce() {
52
+ const rendering = useContext(nonceContext());
53
+ return typeof document === "undefined" ? rendering : nonceOfDocument();
54
+ }
55
+ export default useNonce;
56
+ //# sourceMappingURL=useNonce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNonce.js","sourceRoot":"","sources":["../../src/js/useNonce.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGlD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,UAAqE,CAAC;IAEpF,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,aAAa,CAAqB,SAAS,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,IAAI,aAAiC,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI,aAAa,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO,aAAa,CAAC;IAE3E,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,gBAAgB,CAAoB,eAAe,CAAC,EAAE,CAAC;QACnF,IAAI,MAAM,CAAC,KAAK;YAAE,OAAO,CAAC,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY,EAAE,CAAC,CAAC;IAE7C,OAAO,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;AACzE,CAAC;AAED,eAAe,QAAQ,CAAC","sourcesContent":["\"use client\";\n\n/**\n * The nonce the page's Content-Security-Policy allows inline code by, for a\n * library that writes its own: next-themes' `nonce` prop, a `<style>` a\n * component inserts, an analytics snippet.\n *\n * A client hook, not a server function, because the nonce that matters is\n * the document's. The policy is fixed by the response that delivered the\n * document; a navigation's payload is rendered later, with a nonce of its\n * own that the document has never heard of. A layout handing a server-read\n * nonce down as a prop would hand down the wrong one the first time it was\n * re-rendered by a navigation or a refresh. So the server render supplies the\n * nonce it is writing the document with, and the browser reads it back from\n * the document itself - the scripts React wrote carry it.\n *\n * Undefined where the page has no nonce: no policy, or a page whose inline\n * code is allowed by hash - one stored at build, a shell, a render a cache\n * keeps. An inline script rendered into such a page is hashed with the rest\n * of it and runs without one; code inserted later, after hydration, has\n * nothing to run by.\n */\n\nimport { createContext, useContext } from \"react\";\nimport type { Context } from \"react\";\n\n/**\n * The nonce of the response the server is rendering. Set by the server's\n * render around the whole tree; absent in the browser.\n *\n * Kept on a global symbol so the server's entry and the copy of this module\n * the client components were bundled with agree on one context.\n */\nexport function nonceContext(): Context<string | undefined> {\n const key = Symbol.for(\"rsc-kit.nonce\");\n const store = globalThis as Record<symbol, Context<string | undefined> | undefined>;\n\n return (store[key] ??= createContext<string | undefined>(undefined));\n}\n\nlet documentNonce: string | undefined;\n\n/**\n * The nonce the document's own scripts carry. The attribute reads empty once\n * the browser has applied the policy - it hides it from the page's other\n * scripts - so it is the property that is read. Only a found nonce is kept:\n * a shell's holes, and their nonced scripts, can arrive after the first read.\n */\nexport function nonceOfDocument(): string | undefined {\n if (documentNonce || typeof document === \"undefined\") return documentNonce;\n\n for (const script of document.querySelectorAll<HTMLScriptElement>(\"script[nonce]\")) {\n if (script.nonce) return (documentNonce = script.nonce);\n }\n\n return undefined;\n}\n\nexport function useNonce(): string | undefined {\n const rendering = useContext(nonceContext());\n\n return typeof document === \"undefined\" ? rendering : nonceOfDocument();\n}\n\nexport default useNonce;\n"]}
package/dist/vite.js CHANGED
@@ -26,7 +26,7 @@ import { stampDisplayNames } from "./stableNames.js";
26
26
  import { REPORT_FILE, buildReport } from "./buildReport.js";
27
27
  import { contractPath, edgeGuarded, edgeMarker, edgeShells, edgeStatic } from "./edgeShells.js";
28
28
  import { EDGE, EDGE_HEADERS } from "./headers.js";
29
- import { claimDevServer, recordDevServerUrl, releaseDevServer, secondDevServerMessage } from "./devLock.js";
29
+ import { claimDevServer, recordDevServerUrl, releaseDevServer, secondDevServerMessage, waitForDevServer } from "./devLock.js";
30
30
  import { devContentSecurityPolicy, normaliseContentSecurityPolicy, } from "./csp.js";
31
31
  import { MANIFEST_PATH, manifestWarning, webManifest } from "./webManifest.js";
32
32
  import { ASSET_BASE, allAppAssets, assetFile, appAssets, headTags, shareImageUrls, typeOf, } from "./appAssets.js";
@@ -264,6 +264,8 @@ function devPolicy() {
264
264
  return contentSecurityPolicy;
265
265
  return devContentSecurityPolicy(contentSecurityPolicy, { origin: devOrigin || undefined });
266
266
  }
267
+ /** The dev server lock this process holds, once it holds one - see devLock.ts. */
268
+ let devLockDir;
267
269
  /** Resolved from RscKitOptions.openapi; null when off. */
268
270
  let openapi = null;
269
271
  let foundAssets = {
@@ -6537,6 +6539,7 @@ import { isNotFoundDigest } from ${JSON.stringify(notFoundModule)}
6537
6539
  import { EARLY_CLICKS } from ${JSON.stringify(earlyClicks)}
6538
6540
  import { READ_BLOCKS } from ${JSON.stringify(inlineFlightModule)}
6539
6541
  import { searchSnapshotContext } from ${JSON.stringify(join(packageDir, "js/useSearchParams"))}
6542
+ import { nonceContext } from ${JSON.stringify(join(packageDir, "js/useNonce"))}
6540
6543
  import { createElement as h } from 'react'
6541
6544
  ${webManifestOptions ? `import { INSTALL_CAPTURE } from ${JSON.stringify(installCapture)}` : ""}
6542
6545
 
@@ -6594,8 +6597,15 @@ function decodedBy(stream: ReadableStream): unknown {
6594
6597
  * its holes resumed per request must be the same tree, or React cannot line
6595
6598
  * them up.
6596
6599
  */
6597
- function withSearch(root: unknown, search: string | null | undefined): unknown {
6598
- return h(searchSnapshotContext().Provider, { value: search ?? null }, root as any)
6600
+ function withSearch(root: unknown, search: string | null | undefined, nonce?: string): unknown {
6601
+ // And the response's nonce, for useNonce(): undefined where the HTML may
6602
+ // be stored, which is allowed by hash instead. Always wrapped, for the
6603
+ // same reason.
6604
+ return h(
6605
+ searchSnapshotContext().Provider,
6606
+ { value: search ?? null },
6607
+ h(nonceContext().Provider, { value: nonce }, root as any),
6608
+ )
6599
6609
  }
6600
6610
 
6601
6611
  export async function handleSsr(
@@ -6612,7 +6622,7 @@ export async function handleSsr(
6612
6622
  // Declared here so the runtime knows before its first chunk arrives.
6613
6623
  inline = false,
6614
6624
  ): Promise<ReadableStream> {
6615
- const root = withSearch(decodedBy(rscStream), search)
6625
+ const root = withSearch(decodedBy(rscStream), search, nonce)
6616
6626
 
6617
6627
  // Without the bootstrap the page ships no client runtime at all: no React,
6618
6628
  // no Flight client, no router. HTML only. A page with nothing interactive on
@@ -6777,7 +6787,7 @@ export async function handleSsrResume(
6777
6787
  ): Promise<ReadableStream> {
6778
6788
  // The same tree the shell was prerendered with, now holding this
6779
6789
  // request's query: the holes are filled per request.
6780
- const root = withSearch(decodedBy(rscStream), search)
6790
+ const root = withSearch(decodedBy(rscStream), search, nonce)
6781
6791
 
6782
6792
  const html = await resume(root as any, postponed as any, {
6783
6793
  nonce: nonce ? { script: nonce, style: nonce } : undefined,
@@ -8063,7 +8073,27 @@ export function rscKit(options = {}) {
8063
8073
  nitro.options.plugins = [...(nitro.options.plugins ?? []), "#rsc-kit/startup"];
8064
8074
  },
8065
8075
  },
8066
- config(_config, env) {
8076
+ async config(_config, env) {
8077
+ // One dev server per app - see devLock.ts. Here, the first hook, and
8078
+ // not in configureServer: waiting there, other plugins carried on
8079
+ // around it - Nitro imported the entries before plugin-rsc had its
8080
+ // server, and the failed import answered every request with a 500
8081
+ // once this one started. Before any environment exists nothing runs.
8082
+ if (env.command === "serve" && !env.isPreview) {
8083
+ const lockDir = join(projectRoot, "node_modules", ".vite");
8084
+ const holder = claimDevServer(lockDir);
8085
+ if (holder) {
8086
+ log(secondDevServerMessage(projectRoot, holder).replace(/^\[rsc-kit\] /, ""));
8087
+ await waitForDevServer(lockDir);
8088
+ log("the other dev server stopped — starting this one");
8089
+ }
8090
+ // Released when the process exits, never when its http server
8091
+ // closes: a restart opens the new server before closing the old.
8092
+ if (!devLockDir) {
8093
+ devLockDir = lockDir;
8094
+ process.once("exit", () => releaseDevServer(lockDir));
8095
+ }
8096
+ }
8067
8097
  // Here and not only in configResolved: the entries below are written
8068
8098
  // in this hook, and the 404's policy in them is dev's or the build's.
8069
8099
  devServer = env.command === "serve";
@@ -8403,18 +8433,11 @@ export function rscKit(options = {}) {
8403
8433
  // Swapping the plugins in the app's config is not a fix: Nitro then loads
8404
8434
  // .env too late for the app's first request.
8405
8435
  configureServer: { order: "pre", handler(server) {
8406
- // One dev server per app - see devLock.ts. Released when the process
8407
- // exits, never when its http server closes: a restart opens the new
8408
- // server in this process before closing the old one.
8409
- const cacheDir = server.config.cacheDir;
8410
- const holder = claimDevServer(cacheDir);
8411
- if (holder)
8412
- throw new Error(secondDevServerMessage(projectRoot, holder));
8413
- process.once("exit", () => releaseDevServer(cacheDir));
8436
+ // Where this one listens, for the message a second one prints.
8414
8437
  server.httpServer?.once("listening", () => {
8415
8438
  const url = server.resolvedUrls?.local?.[0];
8416
- if (url)
8417
- recordDevServerUrl(cacheDir, url.replace(/\/$/, ""));
8439
+ if (url && devLockDir)
8440
+ recordDevServerUrl(devLockDir, url.replace(/\/$/, ""));
8418
8441
  });
8419
8442
  // The rules an agent follows here say which rsc-kit wrote them. One
8420
8443
  // line when they are older than the rsc-kit running - never a rewrite: