@cedarjs/prerender 6.0.0-canary.2936 → 6.0.0-canary.2939

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.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Whether an extracted Apollo cache state is non-empty and worth inlining
3
+ * into the prerendered HTML as a bootstrap `<script>`.
4
+ *
5
+ * Only emit the Apollo state bootstrap when there is state to restore. Both
6
+ * consumers (`CedarApolloProvider` and the suspense provider) already do
7
+ * `.restore(globalThis?.__CEDAR__APOLLO_STATE ?? {})`, so an empty payload is
8
+ * a no-op. It is still an inline `<script>` though, which every strict-CSP app
9
+ * has to allow-list with a hash that goes stale whenever the payload changes.
10
+ * A page that prerenders no Cells emits nothing.
11
+ */
12
+ export declare function hasApolloState(state: unknown): state is Record<string, unknown>;
13
+ //# sourceMappingURL=apolloState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apolloState.d.ts","sourceRoot":"","sources":["../src/apolloState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIlC"}
@@ -0,0 +1,6 @@
1
+ function hasApolloState(state) {
2
+ return typeof state === "object" && state !== null && Object.keys(state).length > 0;
3
+ }
4
+ export {
5
+ hasApolloState
6
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Whether an extracted Apollo cache state is non-empty and worth inlining
3
+ * into the prerendered HTML as a bootstrap `<script>`.
4
+ *
5
+ * Only emit the Apollo state bootstrap when there is state to restore. Both
6
+ * consumers (`CedarApolloProvider` and the suspense provider) already do
7
+ * `.restore(globalThis?.__CEDAR__APOLLO_STATE ?? {})`, so an empty payload is
8
+ * a no-op. It is still an inline `<script>` though, which every strict-CSP app
9
+ * has to allow-list with a hash that goes stale whenever the payload changes.
10
+ * A page that prerenders no Cells emits nothing.
11
+ */
12
+ export declare function hasApolloState(state: unknown): state is Record<string, unknown>;
13
+ //# sourceMappingURL=apolloState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apolloState.d.ts","sourceRoot":"","sources":["../../src/apolloState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIlC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var apolloState_exports = {};
20
+ __export(apolloState_exports, {
21
+ hasApolloState: () => hasApolloState
22
+ });
23
+ module.exports = __toCommonJS(apolloState_exports);
24
+ function hasApolloState(state) {
25
+ return typeof state === "object" && state !== null && Object.keys(state).length > 0;
26
+ }
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ hasApolloState
30
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"runPrerender.d.ts","sourceRoot":"","sources":["../../src/runPrerender.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AA4O7C,UAAU,eAAe;IACvB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IACrC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,eAAO,MAAM,YAAY,GAAU,6BAGhC,eAAe,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAmIzC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,MAAM,EACtB,SAAS,MAAM,SAchB,CAAA"}
1
+ {"version":3,"file":"runPrerender.d.ts","sourceRoot":"","sources":["../../src/runPrerender.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AA6O7C,UAAU,eAAe;IACvB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IACrC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,eAAO,MAAM,YAAY,GAAU,6BAGhC,eAAe,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAuIzC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,MAAM,EACtB,SAAS,MAAM,SAchB,CAAA"}
@@ -40,6 +40,7 @@ var import_cheerio = require("cheerio");
40
40
  var import_server = __toESM(require("react-dom/server"), 1);
41
41
  var import_babel_config = require("@cedarjs/babel-config");
42
42
  var import_project_config = require("@cedarjs/project-config");
43
+ var import_apolloState = require("./apolloState.js");
43
44
  var import_babel_plugin_redwood_cell = require("./babelPlugins/babel-plugin-redwood-cell.js");
44
45
  var import_babel_plugin_redwood_prerender_media_imports = require("./babelPlugins/babel-plugin-redwood-prerender-media-imports.js");
45
46
  var import_detection = require("./detection/detection.js");
@@ -281,11 +282,14 @@ const runPrerender = async ({
281
282
  }
282
283
  }
283
284
  }
284
- indexHtmlTree("head").append(
285
- `<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
286
- prerenderApolloClient.extract()
287
- )}</script>`
288
- );
285
+ const apolloState = prerenderApolloClient.extract();
286
+ if ((0, import_apolloState.hasApolloState)(apolloState)) {
287
+ indexHtmlTree("head").append(
288
+ `<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
289
+ apolloState
290
+ )}</script>`
291
+ );
292
+ }
289
293
  prerenderApolloClient.resetStore();
290
294
  insertChunkLoadingScript(indexHtmlTree, renderPath);
291
295
  indexHtmlTree("#cedar-app, #redwood-app").append(componentAsHtml);
@@ -40,6 +40,7 @@ var import_cheerio = require("cheerio");
40
40
  var import_server = __toESM(require("react-dom/server"), 1);
41
41
  var import_project_config = require("@cedarjs/project-config");
42
42
  var import_util = require("@cedarjs/router/dist/util");
43
+ var import_apolloState = require("./apolloState.js");
43
44
  var import_buildAndImport = require("./build-and-import/buildAndImport.js");
44
45
  var import_detection = require("./detection/detection.js");
45
46
  var import_errors = require("./errors.js");
@@ -278,11 +279,14 @@ const runPrerender = async ({
278
279
  }
279
280
  }
280
281
  }
281
- indexHtmlTree("head").append(
282
- `<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
283
- prerenderApolloClient.extract()
284
- )}</script>`
285
- );
282
+ const apolloState = prerenderApolloClient.extract();
283
+ if ((0, import_apolloState.hasApolloState)(apolloState)) {
284
+ indexHtmlTree("head").append(
285
+ `<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
286
+ apolloState
287
+ )}</script>`
288
+ );
289
+ }
286
290
  prerenderApolloClient.resetStore();
287
291
  insertChunkLoadingScript(indexHtmlTree, renderPath);
288
292
  indexHtmlTree("#cedar-app, #redwood-app").append(componentAsHtml);
@@ -1 +1 @@
1
- {"version":3,"file":"runPrerenderEsm.d.ts","sourceRoot":"","sources":["../src/runPrerenderEsm.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAsQ7C,UAAU,eAAe;IACvB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IACrC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,eAAO,MAAM,YAAY,GAAU,6BAGhC,eAAe,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAwHzC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,MAAM,EACtB,SAAS,MAAM,SAchB,CAAA"}
1
+ {"version":3,"file":"runPrerenderEsm.d.ts","sourceRoot":"","sources":["../src/runPrerenderEsm.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAuQ7C,UAAU,eAAe;IACvB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IACrC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,eAAO,MAAM,YAAY,GAAU,6BAGhC,eAAe,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CA4HzC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,MAAM,EACtB,SAAS,MAAM,SAchB,CAAA"}
@@ -10,6 +10,7 @@ import {
10
10
  importStatementPath
11
11
  } from "@cedarjs/project-config";
12
12
  import { matchPath } from "@cedarjs/router/dist/util";
13
+ import { hasApolloState } from "./apolloState.js";
13
14
  import { buildAndImport } from "./build-and-import/buildAndImport.js";
14
15
  import { detectPrerenderRoutes } from "./detection/detection.js";
15
16
  import {
@@ -252,11 +253,14 @@ const runPrerender = async ({
252
253
  }
253
254
  }
254
255
  }
255
- indexHtmlTree("head").append(
256
- `<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
257
- prerenderApolloClient.extract()
258
- )}</script>`
259
- );
256
+ const apolloState = prerenderApolloClient.extract();
257
+ if (hasApolloState(apolloState)) {
258
+ indexHtmlTree("head").append(
259
+ `<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
260
+ apolloState
261
+ )}</script>`
262
+ );
263
+ }
260
264
  prerenderApolloClient.resetStore();
261
265
  insertChunkLoadingScript(indexHtmlTree, renderPath);
262
266
  indexHtmlTree("#cedar-app, #redwood-app").append(componentAsHtml);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/prerender",
3
- "version": "6.0.0-canary.2936",
3
+ "version": "6.0.0-canary.2939",
4
4
  "description": "CedarJS prerender",
5
5
  "repository": {
6
6
  "type": "git",
@@ -70,10 +70,10 @@
70
70
  "@babel/generator": "7.29.7",
71
71
  "@babel/parser": "7.29.7",
72
72
  "@babel/traverse": "7.29.7",
73
- "@cedarjs/babel-config": "6.0.0-canary.2936",
74
- "@cedarjs/project-config": "6.0.0-canary.2936",
75
- "@cedarjs/structure": "6.0.0-canary.2936",
76
- "@cedarjs/vite": "6.0.0-canary.2936",
73
+ "@cedarjs/babel-config": "6.0.0-canary.2939",
74
+ "@cedarjs/project-config": "6.0.0-canary.2939",
75
+ "@cedarjs/structure": "6.0.0-canary.2939",
76
+ "@cedarjs/vite": "6.0.0-canary.2939",
77
77
  "@rollup/plugin-alias": "5.1.1",
78
78
  "@rollup/plugin-commonjs": "28.0.9",
79
79
  "@rollup/plugin-node-resolve": "16.0.3",
@@ -91,9 +91,9 @@
91
91
  "vite": "7.3.6"
92
92
  },
93
93
  "devDependencies": {
94
- "@cedarjs/framework-tools": "6.0.0-canary.2936",
95
- "@cedarjs/router": "6.0.0-canary.2936",
96
- "@cedarjs/web": "6.0.0-canary.2936",
94
+ "@cedarjs/framework-tools": "6.0.0-canary.2939",
95
+ "@cedarjs/router": "6.0.0-canary.2939",
96
+ "@cedarjs/web": "6.0.0-canary.2939",
97
97
  "@types/mime-types": "2.1.4",
98
98
  "@types/react": "^18.2.55",
99
99
  "babel-plugin-tester": "11.0.4",
@@ -103,8 +103,8 @@
103
103
  "vitest": "4.1.10"
104
104
  },
105
105
  "peerDependencies": {
106
- "@cedarjs/router": "6.0.0-canary.2936",
107
- "@cedarjs/web": "6.0.0-canary.2936",
106
+ "@cedarjs/router": "6.0.0-canary.2939",
107
+ "@cedarjs/web": "6.0.0-canary.2939",
108
108
  "react": "19.2.3",
109
109
  "react-dom": "19.2.3"
110
110
  },