@rsc-kit/core 0.31.3 → 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.
@@ -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,EAA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iB,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,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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
@@ -6539,6 +6539,7 @@ import { isNotFoundDigest } from ${JSON.stringify(notFoundModule)}
6539
6539
  import { EARLY_CLICKS } from ${JSON.stringify(earlyClicks)}
6540
6540
  import { READ_BLOCKS } from ${JSON.stringify(inlineFlightModule)}
6541
6541
  import { searchSnapshotContext } from ${JSON.stringify(join(packageDir, "js/useSearchParams"))}
6542
+ import { nonceContext } from ${JSON.stringify(join(packageDir, "js/useNonce"))}
6542
6543
  import { createElement as h } from 'react'
6543
6544
  ${webManifestOptions ? `import { INSTALL_CAPTURE } from ${JSON.stringify(installCapture)}` : ""}
6544
6545
 
@@ -6596,8 +6597,15 @@ function decodedBy(stream: ReadableStream): unknown {
6596
6597
  * its holes resumed per request must be the same tree, or React cannot line
6597
6598
  * them up.
6598
6599
  */
6599
- function withSearch(root: unknown, search: string | null | undefined): unknown {
6600
- 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
+ )
6601
6609
  }
6602
6610
 
6603
6611
  export async function handleSsr(
@@ -6614,7 +6622,7 @@ export async function handleSsr(
6614
6622
  // Declared here so the runtime knows before its first chunk arrives.
6615
6623
  inline = false,
6616
6624
  ): Promise<ReadableStream> {
6617
- const root = withSearch(decodedBy(rscStream), search)
6625
+ const root = withSearch(decodedBy(rscStream), search, nonce)
6618
6626
 
6619
6627
  // Without the bootstrap the page ships no client runtime at all: no React,
6620
6628
  // no Flight client, no router. HTML only. A page with nothing interactive on
@@ -6779,7 +6787,7 @@ export async function handleSsrResume(
6779
6787
  ): Promise<ReadableStream> {
6780
6788
  // The same tree the shell was prerendered with, now holding this
6781
6789
  // request's query: the holes are filled per request.
6782
- const root = withSearch(decodedBy(rscStream), search)
6790
+ const root = withSearch(decodedBy(rscStream), search, nonce)
6783
6791
 
6784
6792
  const html = await resume(root as any, postponed as any, {
6785
6793
  nonce: nonce ? { script: nonce, style: nonce } : undefined,