@cedarjs/prerender 5.0.7-next.239 → 5.0.7-next.310
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/apolloState.d.ts +13 -0
- package/dist/apolloState.d.ts.map +1 -0
- package/dist/apolloState.js +6 -0
- package/dist/cjs/apolloState.d.ts +13 -0
- package/dist/cjs/apolloState.d.ts.map +1 -0
- package/dist/cjs/apolloState.js +30 -0
- package/dist/cjs/runPrerender.d.ts.map +1 -1
- package/dist/cjs/runPrerender.js +9 -5
- package/dist/cjs/runPrerenderEsm.js +9 -5
- package/dist/runPrerenderEsm.d.ts.map +1 -1
- package/dist/runPrerenderEsm.js +9 -5
- package/package.json +11 -11
|
@@ -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,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":"AAmBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"runPrerender.d.ts","sourceRoot":"","sources":["../../src/runPrerender.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AA2O7C,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"}
|
package/dist/cjs/runPrerender.js
CHANGED
|
@@ -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");
|
|
@@ -279,11 +280,14 @@ const runPrerender = async ({
|
|
|
279
280
|
}
|
|
280
281
|
}
|
|
281
282
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
283
|
+
const apolloState = prerenderApolloClient.extract();
|
|
284
|
+
if ((0, import_apolloState.hasApolloState)(apolloState)) {
|
|
285
|
+
indexHtmlTree("head").append(
|
|
286
|
+
`<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
|
|
287
|
+
apolloState
|
|
288
|
+
)}</script>`
|
|
289
|
+
);
|
|
290
|
+
}
|
|
287
291
|
prerenderApolloClient.resetStore();
|
|
288
292
|
insertChunkLoadingScript(indexHtmlTree, renderPath);
|
|
289
293
|
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");
|
|
@@ -276,11 +277,14 @@ const runPrerender = async ({
|
|
|
276
277
|
}
|
|
277
278
|
}
|
|
278
279
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
280
|
+
const apolloState = prerenderApolloClient.extract();
|
|
281
|
+
if ((0, import_apolloState.hasApolloState)(apolloState)) {
|
|
282
|
+
indexHtmlTree("head").append(
|
|
283
|
+
`<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
|
|
284
|
+
apolloState
|
|
285
|
+
)}</script>`
|
|
286
|
+
);
|
|
287
|
+
}
|
|
284
288
|
prerenderApolloClient.resetStore();
|
|
285
289
|
insertChunkLoadingScript(indexHtmlTree, renderPath);
|
|
286
290
|
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;
|
|
1
|
+
{"version":3,"file":"runPrerenderEsm.d.ts","sourceRoot":"","sources":["../src/runPrerenderEsm.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAqQ7C,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"}
|
package/dist/runPrerenderEsm.js
CHANGED
|
@@ -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 {
|
|
@@ -250,11 +251,14 @@ const runPrerender = async ({
|
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
254
|
+
const apolloState = prerenderApolloClient.extract();
|
|
255
|
+
if (hasApolloState(apolloState)) {
|
|
256
|
+
indexHtmlTree("head").append(
|
|
257
|
+
`<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
|
|
258
|
+
apolloState
|
|
259
|
+
)}</script>`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
258
262
|
prerenderApolloClient.resetStore();
|
|
259
263
|
insertChunkLoadingScript(indexHtmlTree, renderPath);
|
|
260
264
|
indexHtmlTree("#cedar-app, #redwood-app").append(componentAsHtml);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/prerender",
|
|
3
|
-
"version": "5.0.7-next.
|
|
3
|
+
"version": "5.0.7-next.310",
|
|
4
4
|
"description": "CedarJS prerender",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -70,15 +70,15 @@
|
|
|
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": "5.0.7-next.
|
|
74
|
-
"@cedarjs/project-config": "5.0.7-next.
|
|
75
|
-
"@cedarjs/structure": "5.0.7-next.
|
|
76
|
-
"@cedarjs/vite": "5.0.7-next.
|
|
73
|
+
"@cedarjs/babel-config": "5.0.7-next.310",
|
|
74
|
+
"@cedarjs/project-config": "5.0.7-next.310",
|
|
75
|
+
"@cedarjs/structure": "5.0.7-next.310",
|
|
76
|
+
"@cedarjs/vite": "5.0.7-next.310",
|
|
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",
|
|
80
80
|
"@rollup/plugin-replace": "6.0.3",
|
|
81
|
-
"@swc/core": "1.15.
|
|
81
|
+
"@swc/core": "1.15.47",
|
|
82
82
|
"@whatwg-node/fetch": "0.10.13",
|
|
83
83
|
"babel-plugin-ignore-html-and-css-imports": "0.1.0",
|
|
84
84
|
"cheerio": "1.2.0",
|
|
@@ -91,9 +91,9 @@
|
|
|
91
91
|
"vite": "7.3.6"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@cedarjs/framework-tools": "5.0.7-next.
|
|
95
|
-
"@cedarjs/router": "5.0.7-next.
|
|
96
|
-
"@cedarjs/web": "5.0.7-next.
|
|
94
|
+
"@cedarjs/framework-tools": "5.0.7-next.310",
|
|
95
|
+
"@cedarjs/router": "5.0.7-next.310",
|
|
96
|
+
"@cedarjs/web": "5.0.7-next.310",
|
|
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": "5.0.7-next.
|
|
107
|
-
"@cedarjs/web": "5.0.7-next.
|
|
106
|
+
"@cedarjs/router": "5.0.7-next.310",
|
|
107
|
+
"@cedarjs/web": "5.0.7-next.310",
|
|
108
108
|
"react": "18.3.1",
|
|
109
109
|
"react-dom": "18.3.1"
|
|
110
110
|
},
|