@govtechsg/sgds-web-component 3.30.1-rc.3 → 3.30.1-rc.4

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.
@@ -32036,7 +32036,7 @@
32036
32036
  "package": {
32037
32037
  "name": "@govtechsg/sgds-web-component",
32038
32038
  "description": "",
32039
- "version": "3.30.1-rc.3",
32039
+ "version": "3.30.1-rc.4",
32040
32040
  "author": "GovTechSG",
32041
32041
  "license": "MIT"
32042
32042
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@govtechsg/sgds-web-component",
3
- "version": "3.30.1-rc.3",
3
+ "version": "3.30.1-rc.4",
4
4
  "description": "",
5
5
  "main": "./index.umd.js",
6
6
  "module": "./index.js",
@@ -1 +1 @@
1
- export { setCSPNonce, getCSPNonce, registerSSRNonce } from '../../utils/ssr-nonce';
1
+ export { setCSPNonce, getCSPNonce } from '../../utils/ssr-nonce';
@@ -1,2 +1,2 @@
1
- import { getCSPNonce, registerSSRNonce, setCSPNonce } from "./utils/ssr-nonce.js";
2
- export { getCSPNonce, registerSSRNonce, setCSPNonce };
1
+ import { getCSPNonce, setCSPNonce } from "./utils/ssr-nonce.js";
2
+ export { getCSPNonce, setCSPNonce };
@@ -3,50 +3,13 @@ function getCSPNonce() {
3
3
  return globalThis["litNonce"] ?? null;
4
4
  }
5
5
  /**
6
- * Patch LitElementRenderer.renderShadow() to inject CSP nonces into
7
- * DSD <style> tags. Call this ONCE at server startup from instrumentation.ts.
8
- *
9
- * This must run before any SSR request is handled. Next.js's
10
- * instrumentation.ts `register()` hook guarantees this.
11
- */
12
- async function registerSSRNonce() {
13
- if (typeof window !== "undefined") return;
14
- try {
15
- const { LitElementRenderer } = await import("@lit-labs/ssr/lib/lit-element-renderer.js");
16
- if (LitElementRenderer._sgdsNoncePatched) return;
17
- LitElementRenderer._sgdsNoncePatched = true;
18
- const originalRenderShadow = LitElementRenderer.prototype.renderShadow;
19
- LitElementRenderer.prototype.renderShadow = function(renderInfo) {
20
- const result = originalRenderShadow.call(this, renderInfo);
21
- if (!result) return result;
22
- const litNonce = globalThis["litNonce"];
23
- if (!litNonce) return result;
24
- return result.map((item) => {
25
- if (typeof item === "string" && item === "<style>") return `<style nonce="${litNonce}">`;
26
- return item;
27
- });
28
- };
29
- } catch {}
30
- }
31
- /**
32
6
  * CSP nonce for Declarative Shadow DOM (DSD) styles.
33
7
  *
34
- * Two functions:
35
- * - `registerSSRNonce()` — call ONCE at server startup (instrumentation.ts).
36
- * Patches LitElementRenderer to respect globalThis.litNonce.
37
- * - `setCSPNonce()` — call per-request in layout.tsx.
38
- * Sets globalThis.litNonce for the current request.
8
+ * Sets globalThis.litNonce — the standard Lit mechanism for CSP nonces.
9
+ * The ssr-nonce-patch.raw.js file reads this value at render time and
10
+ * injects it into DSD <style> tags.
39
11
  *
40
12
  * @example
41
- * ```ts
42
- * // instrumentation.ts
43
- * import { registerSSRNonce } from '@govtechsg/sgds-web-component/react/ssr';
44
- *
45
- * export async function register() {
46
- * await registerSSRNonce();
47
- * }
48
- * ```
49
- *
50
13
  * ```tsx
51
14
  * // app/layout.tsx (server component)
52
15
  * import { setCSPNonce } from '@govtechsg/sgds-web-component/react/ssr';
@@ -68,6 +31,6 @@ function setCSPNonce(nonce) {
68
31
  globalThis["litNonce"] = nonce ?? void 0;
69
32
  }
70
33
  //#endregion
71
- export { getCSPNonce, registerSSRNonce, setCSPNonce };
34
+ export { getCSPNonce, setCSPNonce };
72
35
 
73
36
  //# sourceMappingURL=ssr-nonce.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-nonce.js","names":[],"sources":["../../../../src/utils/ssr-nonce.ts"],"sourcesContent":["export function getCSPNonce(): string | null {\n return ((globalThis as Record<string, unknown>)[\"litNonce\"] as string) ?? null;\n}\n\n/**\n * Patch LitElementRenderer.renderShadow() to inject CSP nonces into\n * DSD <style> tags. Call this ONCE at server startup from instrumentation.ts.\n *\n * This must run before any SSR request is handled. Next.js's\n * instrumentation.ts `register()` hook guarantees this.\n */\nexport async function registerSSRNonce(): Promise<void> {\n if (typeof window !== \"undefined\") return;\n\n try {\n const { LitElementRenderer } = await import(\"@lit-labs/ssr/lib/lit-element-renderer.js\");\n\n // Guard against double-patching\n if ((LitElementRenderer as unknown as Record<string, unknown>)._sgdsNoncePatched) {\n return;\n }\n (LitElementRenderer as unknown as Record<string, unknown>)._sgdsNoncePatched = true;\n\n const originalRenderShadow = LitElementRenderer.prototype.renderShadow;\n\n LitElementRenderer.prototype.renderShadow = function (renderInfo: unknown) {\n const result = originalRenderShadow.call(this, renderInfo);\n if (!result) return result;\n\n const litNonce = (globalThis as Record<string, unknown>)[\"litNonce\"];\n if (!litNonce) return result;\n\n return result.map((item: unknown) => {\n if (typeof item === \"string\" && item === \"<style>\") {\n return `<style nonce=\"${litNonce}\">`;\n }\n return item;\n });\n };\n } catch {\n // @lit-labs/ssr not available — nonce injection disabled\n }\n}\n\n/**\n * CSP nonce for Declarative Shadow DOM (DSD) styles.\n *\n * Two functions:\n * - `registerSSRNonce()` — call ONCE at server startup (instrumentation.ts).\n * Patches LitElementRenderer to respect globalThis.litNonce.\n * - `setCSPNonce()` — call per-request in layout.tsx.\n * Sets globalThis.litNonce for the current request.\n *\n * @example\n * ```ts\n * // instrumentation.ts\n * import { registerSSRNonce } from '@govtechsg/sgds-web-component/react/ssr';\n *\n * export async function register() {\n * await registerSSRNonce();\n * }\n * ```\n *\n * ```tsx\n * // app/layout.tsx (server component)\n * import { setCSPNonce } from '@govtechsg/sgds-web-component/react/ssr';\n * import { headers } from 'next/headers';\n *\n * export default async function Layout({ children }) {\n * const nonce = (await headers()).get('x-nonce');\n * if (nonce) setCSPNonce(nonce);\n * return <html><body>{children}</body></html>;\n * }\n * ```\n */\n/**\n * Set the CSP nonce for the current request. Call this in your server\n * component (e.g. layout.tsx) before SGDS components render.\n * This is synchronous — no await needed.\n */\nexport function setCSPNonce(nonce: string | null): void {\n (globalThis as Record<string, unknown>)[\"litNonce\"] = nonce ?? undefined;\n}\n"],"mappings":";AAAA,SAAgB,cAA6B;CAC3C,OAAS,WAAuC,eAA0B;AAC5E;;;;;;;;AASA,eAAsB,mBAAkC;CACtD,IAAI,OAAO,WAAW,aAAa;CAEnC,IAAI;EACF,MAAM,EAAE,uBAAuB,MAAM,OAAO;EAG5C,IAAK,mBAA0D,mBAC7D;EAEF,mBAA2D,oBAAoB;EAE/E,MAAM,uBAAuB,mBAAmB,UAAU;EAE1D,mBAAmB,UAAU,eAAe,SAAU,YAAqB;GACzE,MAAM,SAAS,qBAAqB,KAAK,MAAM,UAAU;GACzD,IAAI,CAAC,QAAQ,OAAO;GAEpB,MAAM,WAAY,WAAuC;GACzD,IAAI,CAAC,UAAU,OAAO;GAEtB,OAAO,OAAO,KAAK,SAAkB;IACnC,IAAI,OAAO,SAAS,YAAY,SAAS,WACvC,OAAO,iBAAiB,SAAS;IAEnC,OAAO;GACT,CAAC;EACH;CACF,QAAQ,CAER;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,YAAY,OAA4B;CACtD,WAAwC,cAAc,SAAS,KAAA;AACjE"}
1
+ {"version":3,"file":"ssr-nonce.js","names":[],"sources":["../../../../src/utils/ssr-nonce.ts"],"sourcesContent":["export function getCSPNonce(): string | null {\n return ((globalThis as Record<string, unknown>)[\"litNonce\"] as string) ?? null;\n}\n\n/**\n * CSP nonce for Declarative Shadow DOM (DSD) styles.\n *\n * Sets globalThis.litNonce — the standard Lit mechanism for CSP nonces.\n * The ssr-nonce-patch.raw.js file reads this value at render time and\n * injects it into DSD <style> tags.\n *\n * @example\n * ```tsx\n * // app/layout.tsx (server component)\n * import { setCSPNonce } from '@govtechsg/sgds-web-component/react/ssr';\n * import { headers } from 'next/headers';\n *\n * export default async function Layout({ children }) {\n * const nonce = (await headers()).get('x-nonce');\n * if (nonce) setCSPNonce(nonce);\n * return <html><body>{children}</body></html>;\n * }\n * ```\n */\n/**\n * Set the CSP nonce for the current request. Call this in your server\n * component (e.g. layout.tsx) before SGDS components render.\n * This is synchronous — no await needed.\n */\nexport function setCSPNonce(nonce: string | null): void {\n (globalThis as Record<string, unknown>)[\"litNonce\"] = nonce ?? undefined;\n}\n"],"mappings":";AAAA,SAAgB,cAA6B;CAC3C,OAAS,WAAuC,eAA0B;AAC5E;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,YAAY,OAA4B;CACtD,WAAwC,cAAc,SAAS,KAAA;AACjE"}
@@ -1,2 +1,3 @@
1
1
  "use client";
2
+ require("./utils/ssr-nonce-patch.cjs.js");
2
3
  require("@lit-labs/ssr-react/enable-lit-ssr.js");
@@ -1,2 +1,3 @@
1
1
  "use client";
2
+ import "./utils/ssr-nonce-patch.js";
2
3
  import "@lit-labs/ssr-react/enable-lit-ssr.js";
@@ -0,0 +1 @@
1
+ "use client";
@@ -2,4 +2,8 @@
2
2
  * Placeholder — the actual ssr-nonce-patch is in ssr-nonce-patch.raw.js
3
3
  * which is copied to lib/ by frankBuild.js, bypassing Rolldown.
4
4
  * This preserves bare require() for webpack's module system.
5
+ *
6
+ * The export below prevents Rolldown from tree-shaking this module
7
+ * when imported from _ssr-init.ts.
5
8
  */
9
+ export declare const _ssrNoncePatchLoaded = true;
@@ -1,31 +1,12 @@
1
1
  export declare function getCSPNonce(): string | null;
2
- /**
3
- * Patch LitElementRenderer.renderShadow() to inject CSP nonces into
4
- * DSD <style> tags. Call this ONCE at server startup from instrumentation.ts.
5
- *
6
- * This must run before any SSR request is handled. Next.js's
7
- * instrumentation.ts `register()` hook guarantees this.
8
- */
9
- export declare function registerSSRNonce(): Promise<void>;
10
2
  /**
11
3
  * CSP nonce for Declarative Shadow DOM (DSD) styles.
12
4
  *
13
- * Two functions:
14
- * - `registerSSRNonce()` — call ONCE at server startup (instrumentation.ts).
15
- * Patches LitElementRenderer to respect globalThis.litNonce.
16
- * - `setCSPNonce()` — call per-request in layout.tsx.
17
- * Sets globalThis.litNonce for the current request.
5
+ * Sets globalThis.litNonce — the standard Lit mechanism for CSP nonces.
6
+ * The ssr-nonce-patch.raw.js file reads this value at render time and
7
+ * injects it into DSD <style> tags.
18
8
  *
19
9
  * @example
20
- * ```ts
21
- * // instrumentation.ts
22
- * import { registerSSRNonce } from '@govtechsg/sgds-web-component/react/ssr';
23
- *
24
- * export async function register() {
25
- * await registerSSRNonce();
26
- * }
27
- * ```
28
- *
29
10
  * ```tsx
30
11
  * // app/layout.tsx (server component)
31
12
  * import { setCSPNonce } from '@govtechsg/sgds-web-component/react/ssr';