vike 0.4.236-commit-79f1ef0 → 0.4.236-commit-3c05c99
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/cjs/client/shared/getJsonSerializedInHtml.js +10 -1
- package/dist/cjs/node/runtime/globalContext.js +7 -6
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/serializeContext.js +20 -20
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/cjs/node/runtime/renderPage.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +2 -2
- package/dist/esm/client/shared/getJsonSerializedInHtml.js +10 -1
- package/dist/esm/node/runtime/globalContext.d.ts +2 -2
- package/dist/esm/node/runtime/globalContext.js +7 -6
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/serializeContext.d.ts +3 -3
- package/dist/esm/node/runtime/html/serializeContext.js +20 -20
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/esm/node/runtime/renderPage.js +2 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/package.json +2 -2
|
@@ -26,6 +26,15 @@ function findAndParseJson(id) {
|
|
|
26
26
|
`Couldn't find #${id} (which Vike automatically injects in the HTML): make sure it exists (i.e. don't remove it and make sure your HTML isn't malformed)`);
|
|
27
27
|
const jsonStr = elem.textContent;
|
|
28
28
|
(0, utils_js_1.assert)(jsonStr);
|
|
29
|
-
const json = (0, parse_1.parse)(jsonStr
|
|
29
|
+
const json = (0, parse_1.parse)(jsonStr, {
|
|
30
|
+
// Prevent Google from crawling URLs in JSON:
|
|
31
|
+
// - https://github.com/vikejs/vike/pull/2603
|
|
32
|
+
// - https://github.com/brillout/json-serializer/blob/38edbb9945de4938da1e65d6285ce1dd123a45ef/test/main.spec.ts#L44-L95
|
|
33
|
+
reviver(_key, value) {
|
|
34
|
+
if (typeof value === 'string') {
|
|
35
|
+
return { replacement: value.replaceAll('\\/', '/'), resolved: false };
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
});
|
|
30
39
|
return json;
|
|
31
40
|
}
|
|
@@ -278,7 +278,7 @@ async function loadBuildEntry(outDir) {
|
|
|
278
278
|
assertBuildEntry(buildEntry);
|
|
279
279
|
globalObject.assetsManifest = buildEntry.assetsManifest;
|
|
280
280
|
globalObject.buildInfo = buildEntry.buildInfo;
|
|
281
|
-
await
|
|
281
|
+
await createGlobalContext(buildEntry.virtualFileExports);
|
|
282
282
|
}
|
|
283
283
|
// This is the production entry, see:
|
|
284
284
|
// https://github.com/vikejs/vike/blob/798e5465dc3e3e6723b38b601a50350c0a006fb8/packages/vike/node/vite/plugins/pluginBuild/pluginBuildEntry.ts#L47
|
|
@@ -323,6 +323,7 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
|
|
|
323
323
|
(0, utils_js_1.assertUsage)(versionAtBuildTime === versionAtRuntime, `Re-build your app (you're using ${pretty(versionAtRuntime)} but your app was built with ${pretty(versionAtBuildTime)})`);
|
|
324
324
|
}
|
|
325
325
|
async function updateUserFiles() {
|
|
326
|
+
debug('updateUserFiles()');
|
|
326
327
|
(0, utils_js_1.assert)(!globalObject.isProduction);
|
|
327
328
|
const { promise, resolve } = (0, utils_js_1.genPromise)();
|
|
328
329
|
globalObject.waitForUserFilesUpdate = promise;
|
|
@@ -405,7 +406,7 @@ async function updateUserFiles() {
|
|
|
405
406
|
return { success: false };
|
|
406
407
|
}
|
|
407
408
|
try {
|
|
408
|
-
await
|
|
409
|
+
await createGlobalContext(virtualFileExports);
|
|
409
410
|
}
|
|
410
411
|
catch (err_) {
|
|
411
412
|
hasError = true;
|
|
@@ -417,8 +418,8 @@ async function updateUserFiles() {
|
|
|
417
418
|
return onError(err);
|
|
418
419
|
return onSuccess();
|
|
419
420
|
}
|
|
420
|
-
async function
|
|
421
|
-
debug('
|
|
421
|
+
async function createGlobalContext(virtualFileExports) {
|
|
422
|
+
debug('createGlobalContext()');
|
|
422
423
|
(0, utils_js_1.assert)(!(0, getVikeConfigError_js_1.getVikeConfigErrorBuild)());
|
|
423
424
|
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
|
|
424
425
|
(0, assertV1Design_js_1.assertV1Design)(
|
|
@@ -426,8 +427,8 @@ async function setGlobalContext(virtualFileExports) {
|
|
|
426
427
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
427
428
|
assertGlobalContextIsDefined();
|
|
428
429
|
(0, utils_js_1.onSetupRuntime)();
|
|
429
|
-
debug('
|
|
430
|
-
// Never actually used, only used for TypeScript `ReturnType<typeof
|
|
430
|
+
debug('createGlobalContext() - done');
|
|
431
|
+
// Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
|
|
431
432
|
return globalContext;
|
|
432
433
|
}
|
|
433
434
|
async function addGlobalContextTmp(globalContext) {
|
|
@@ -187,7 +187,7 @@ function mergeScriptEntries(pageAssets, viteDevScript) {
|
|
|
187
187
|
return scriptEntry;
|
|
188
188
|
}
|
|
189
189
|
function getPageContextJsonScriptTag(pageContext) {
|
|
190
|
-
const pageContextClientSerialized = (0, sanitizeJson_js_1.sanitizeJson)((0, serializeContext_js_1.getPageContextClientSerialized)(pageContext));
|
|
190
|
+
const pageContextClientSerialized = (0, sanitizeJson_js_1.sanitizeJson)((0, serializeContext_js_1.getPageContextClientSerialized)(pageContext, true));
|
|
191
191
|
const htmlTag = `<script id="${htmlElementIds_js_1.htmlElementId_pageContext}" type="application/json">${pageContextClientSerialized}</script>`;
|
|
192
192
|
// Used by contra.com https://github.com/gajus
|
|
193
193
|
// @ts-expect-error
|
|
@@ -195,7 +195,7 @@ function getPageContextJsonScriptTag(pageContext) {
|
|
|
195
195
|
return htmlTag;
|
|
196
196
|
}
|
|
197
197
|
function getGlobalContextJsonScriptTag(pageContext) {
|
|
198
|
-
const globalContextClientSerialized = (0, sanitizeJson_js_1.sanitizeJson)((0, serializeContext_js_1.getGlobalContextClientSerialized)(pageContext));
|
|
198
|
+
const globalContextClientSerialized = (0, sanitizeJson_js_1.sanitizeJson)((0, serializeContext_js_1.getGlobalContextClientSerialized)(pageContext, true));
|
|
199
199
|
const htmlTag = `<script id="${htmlElementIds_js_1.htmlElementId_globalContext}" type="application/json">${globalContextClientSerialized}</script>`;
|
|
200
200
|
return htmlTag;
|
|
201
201
|
}
|
|
@@ -30,7 +30,7 @@ const passToClientBuiltInPageContext = [
|
|
|
30
30
|
'data', // for data() hook
|
|
31
31
|
];
|
|
32
32
|
const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError_js_1.isServerSideError];
|
|
33
|
-
function getPageContextClientSerialized(pageContext) {
|
|
33
|
+
function getPageContextClientSerialized(pageContext, isHtmlJsonScript) {
|
|
34
34
|
const passToClientPageContext = getPassToClientPageContext(pageContext);
|
|
35
35
|
const getObj = (passToClientEntry) => {
|
|
36
36
|
if (passToClientEntry.once)
|
|
@@ -43,10 +43,10 @@ function getPageContextClientSerialized(pageContext) {
|
|
|
43
43
|
if (pageContextClientProps.some((prop) => (0, propKeys_js_1.getPropVal)(pageContext._pageContextInit, prop))) {
|
|
44
44
|
pageContextClient[pageContextInitIsPassedToClient_js_1.pageContextInitIsPassedToClient] = true;
|
|
45
45
|
}
|
|
46
|
-
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, getObj);
|
|
46
|
+
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, getObj, isHtmlJsonScript);
|
|
47
47
|
return pageContextClientSerialized;
|
|
48
48
|
}
|
|
49
|
-
function getGlobalContextClientSerialized(pageContext) {
|
|
49
|
+
function getGlobalContextClientSerialized(pageContext, isHtmlJsonScript) {
|
|
50
50
|
const passToClient = pageContext._passToClient;
|
|
51
51
|
const globalContext = pageContext._globalContext;
|
|
52
52
|
const getObj = ({ prop, once }) => {
|
|
@@ -63,13 +63,13 @@ function getGlobalContextClientSerialized(pageContext) {
|
|
|
63
63
|
};
|
|
64
64
|
const res = applyPassToClient(passToClient, getObj);
|
|
65
65
|
const globalContextClient = res.objClient;
|
|
66
|
-
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, getObj);
|
|
66
|
+
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, getObj, isHtmlJsonScript);
|
|
67
67
|
return globalContextClientSerialized;
|
|
68
68
|
}
|
|
69
|
-
function serializeObject(obj, passToClient, getObj) {
|
|
69
|
+
function serializeObject(obj, passToClient, getObj, isHtmlJsonScript) {
|
|
70
70
|
let serialized;
|
|
71
71
|
try {
|
|
72
|
-
serialized = serializeValue(obj);
|
|
72
|
+
serialized = serializeValue(obj, isHtmlJsonScript);
|
|
73
73
|
}
|
|
74
74
|
catch (err) {
|
|
75
75
|
const h = (s) => picocolors_1.default.cyan(s);
|
|
@@ -86,7 +86,7 @@ function serializeObject(obj, passToClient, getObj) {
|
|
|
86
86
|
(0, utils_js_1.assert)(objName);
|
|
87
87
|
const varName = `${objName}${(0, propKeys_js_1.getPropKeys)(prop).map(utils_js_1.getPropAccessNotation).join('')}`;
|
|
88
88
|
try {
|
|
89
|
-
serializeValue(value, varName);
|
|
89
|
+
serializeValue(value, isHtmlJsonScript, varName);
|
|
90
90
|
}
|
|
91
91
|
catch (err) {
|
|
92
92
|
propsNonSerializable.push(prop);
|
|
@@ -124,7 +124,7 @@ function serializeObject(obj, passToClient, getObj) {
|
|
|
124
124
|
obj[(0, propKeys_js_1.getPropKeys)(prop)[0]] = NOT_SERIALIZABLE_js_1.NOT_SERIALIZABLE;
|
|
125
125
|
});
|
|
126
126
|
try {
|
|
127
|
-
serialized = serializeValue(obj);
|
|
127
|
+
serialized = serializeValue(obj, isHtmlJsonScript);
|
|
128
128
|
}
|
|
129
129
|
catch (err) {
|
|
130
130
|
(0, utils_js_1.assert)(false);
|
|
@@ -132,20 +132,20 @@ function serializeObject(obj, passToClient, getObj) {
|
|
|
132
132
|
}
|
|
133
133
|
return serialized;
|
|
134
134
|
}
|
|
135
|
-
function serializeValue(value, varName) {
|
|
135
|
+
function serializeValue(value, isHtmlJsonScript, varName) {
|
|
136
136
|
return (0, stringify_1.stringify)(value, {
|
|
137
137
|
forbidReactElements: true,
|
|
138
138
|
valueName: varName,
|
|
139
139
|
// Prevent Google from crawling URLs in JSON:
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
140
|
+
// - https://github.com/vikejs/vike/pull/2603
|
|
141
|
+
// - https://github.com/brillout/json-serializer/blob/38edbb9945de4938da1e65d6285ce1dd123a45ef/test/main.spec.ts#L44-L95
|
|
142
|
+
replacer: !isHtmlJsonScript
|
|
143
|
+
? undefined
|
|
144
|
+
: (_key, value) => {
|
|
145
|
+
if (typeof value === 'string') {
|
|
146
|
+
return { replacement: value.replaceAll('/', '\\/'), resolved: false };
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
function getPassToClientPageContext(pageContext) {
|
|
@@ -158,7 +158,7 @@ function getPassToClientPageContext(pageContext) {
|
|
|
158
158
|
passToClient = (0, utils_js_1.unique)(passToClient);
|
|
159
159
|
return passToClient;
|
|
160
160
|
}
|
|
161
|
-
function getPageContextClientSerializedAbort(pageContext) {
|
|
161
|
+
function getPageContextClientSerializedAbort(pageContext, isHtmlJsonScript) {
|
|
162
162
|
(0, utils_js_1.assert)(pageContext._urlRedirect || pageContext._urlRewrite || pageContext.abortStatusCode);
|
|
163
163
|
(0, utils_js_1.assert)(pageContext._abortCall);
|
|
164
164
|
(0, utils_js_1.assert)(pageContext._abortCaller);
|
|
@@ -191,7 +191,7 @@ function getPageContextClientSerializedAbort(pageContext) {
|
|
|
191
191
|
onlyOnce: false,
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
|
-
return serializeValue(pageContext);
|
|
194
|
+
return serializeValue(pageContext, isHtmlJsonScript);
|
|
195
195
|
}
|
|
196
196
|
function applyPassToClient(passToClient, getObj) {
|
|
197
197
|
const objClient = {};
|
|
@@ -50,7 +50,7 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
50
50
|
if (isError) {
|
|
51
51
|
(0, utils_js_1.objectAssign)(pageContext, { [isServerSideError_js_1.isServerSideError]: true });
|
|
52
52
|
}
|
|
53
|
-
const pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext);
|
|
53
|
+
const pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext, false);
|
|
54
54
|
const httpResponse = await (0, createHttpResponse_js_1.createHttpResponsePageContextJson)(pageContextSerialized);
|
|
55
55
|
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
56
56
|
return pageContext;
|
|
@@ -80,7 +80,7 @@ async function prerenderPage(pageContext) {
|
|
|
80
80
|
return { documentHtml, pageContextSerialized: null, pageContext };
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
const pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext);
|
|
83
|
+
const pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext, false);
|
|
84
84
|
return { documentHtml, pageContextSerialized, pageContext };
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -424,10 +424,10 @@ pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalCont
|
|
|
424
424
|
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit, true);
|
|
425
425
|
(0, utils_js_1.augmentType)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSideAndExecHook)(pageContext));
|
|
426
426
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
427
|
-
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext);
|
|
427
|
+
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext, false);
|
|
428
428
|
}
|
|
429
429
|
else {
|
|
430
|
-
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerializedAbort)(pageContextAbort);
|
|
430
|
+
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerializedAbort)(pageContextAbort, false);
|
|
431
431
|
}
|
|
432
432
|
const httpResponse = await (0, createHttpResponse_js_1.createHttpResponsePageContextJson)(pageContextSerialized);
|
|
433
433
|
const pageContextReturn = { httpResponse };
|
|
@@ -111,8 +111,8 @@ async function renderPageClientSide(renderArgs) {
|
|
|
111
111
|
if (isFirstRender) {
|
|
112
112
|
// Set pageContext properties set by onBeforeRoute()
|
|
113
113
|
// - But we skip pageId and routeParams because routing may have been aborted by a server-side `throw render()`
|
|
114
|
-
const { pageId, routeParams, ...
|
|
115
|
-
objectAssign(pageContext,
|
|
114
|
+
const { pageId, routeParams, ...rest } = pageContextFromRoute;
|
|
115
|
+
objectAssign(pageContext, rest);
|
|
116
116
|
assert(hasProp(pageContext, 'routeParams', 'string{}')); // Help TS
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
@@ -24,6 +24,15 @@ function findAndParseJson(id) {
|
|
|
24
24
|
`Couldn't find #${id} (which Vike automatically injects in the HTML): make sure it exists (i.e. don't remove it and make sure your HTML isn't malformed)`);
|
|
25
25
|
const jsonStr = elem.textContent;
|
|
26
26
|
assert(jsonStr);
|
|
27
|
-
const json = parse(jsonStr
|
|
27
|
+
const json = parse(jsonStr, {
|
|
28
|
+
// Prevent Google from crawling URLs in JSON:
|
|
29
|
+
// - https://github.com/vikejs/vike/pull/2603
|
|
30
|
+
// - https://github.com/brillout/json-serializer/blob/38edbb9945de4938da1e65d6285ce1dd123a45ef/test/main.spec.ts#L44-L95
|
|
31
|
+
reviver(_key, value) {
|
|
32
|
+
if (typeof value === 'string') {
|
|
33
|
+
return { replacement: value.replaceAll('\\/', '/'), resolved: false };
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
});
|
|
28
37
|
return json;
|
|
29
38
|
}
|
|
@@ -27,7 +27,7 @@ import type { GlobalContext } from '../../types/PageContext.js';
|
|
|
27
27
|
import type { Hook } from '../../shared/hooks/getHook.js';
|
|
28
28
|
declare const vikeConfigErrorRecoverMsg: "Vike config loaded";
|
|
29
29
|
type GlobalContextServer = Pick<GlobalContextServerInternal, 'assetsManifest' | 'config' | 'viteConfig' | 'viteConfigRuntime' | 'pages' | 'baseServer' | 'baseAssets' | 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextServer;
|
|
30
|
-
type GlobalContextServerInternal = Awaited<ReturnType<typeof
|
|
30
|
+
type GlobalContextServerInternal = Awaited<ReturnType<typeof createGlobalContext>>;
|
|
31
31
|
declare function getGlobalContextServerInternal(): Promise<{
|
|
32
32
|
globalContext: (Record<string, unknown> & {
|
|
33
33
|
isGlobalContext: true;
|
|
@@ -190,7 +190,7 @@ declare function assertBuildInfo(buildInfo: unknown): asserts buildInfo is Build
|
|
|
190
190
|
declare function updateUserFiles(): Promise<{
|
|
191
191
|
success: boolean;
|
|
192
192
|
}>;
|
|
193
|
-
declare function
|
|
193
|
+
declare function createGlobalContext(virtualFileExports: unknown): Promise<{
|
|
194
194
|
isGlobalContext: true;
|
|
195
195
|
_isOriginalObject: true;
|
|
196
196
|
_virtualFileExports: unknown;
|
|
@@ -274,7 +274,7 @@ async function loadBuildEntry(outDir) {
|
|
|
274
274
|
assertBuildEntry(buildEntry);
|
|
275
275
|
globalObject.assetsManifest = buildEntry.assetsManifest;
|
|
276
276
|
globalObject.buildInfo = buildEntry.buildInfo;
|
|
277
|
-
await
|
|
277
|
+
await createGlobalContext(buildEntry.virtualFileExports);
|
|
278
278
|
}
|
|
279
279
|
// This is the production entry, see:
|
|
280
280
|
// https://github.com/vikejs/vike/blob/798e5465dc3e3e6723b38b601a50350c0a006fb8/packages/vike/node/vite/plugins/pluginBuild/pluginBuildEntry.ts#L47
|
|
@@ -319,6 +319,7 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
|
|
|
319
319
|
assertUsage(versionAtBuildTime === versionAtRuntime, `Re-build your app (you're using ${pretty(versionAtRuntime)} but your app was built with ${pretty(versionAtBuildTime)})`);
|
|
320
320
|
}
|
|
321
321
|
async function updateUserFiles() {
|
|
322
|
+
debug('updateUserFiles()');
|
|
322
323
|
assert(!globalObject.isProduction);
|
|
323
324
|
const { promise, resolve } = genPromise();
|
|
324
325
|
globalObject.waitForUserFilesUpdate = promise;
|
|
@@ -401,7 +402,7 @@ async function updateUserFiles() {
|
|
|
401
402
|
return { success: false };
|
|
402
403
|
}
|
|
403
404
|
try {
|
|
404
|
-
await
|
|
405
|
+
await createGlobalContext(virtualFileExports);
|
|
405
406
|
}
|
|
406
407
|
catch (err_) {
|
|
407
408
|
hasError = true;
|
|
@@ -413,8 +414,8 @@ async function updateUserFiles() {
|
|
|
413
414
|
return onError(err);
|
|
414
415
|
return onSuccess();
|
|
415
416
|
}
|
|
416
|
-
async function
|
|
417
|
-
debug('
|
|
417
|
+
async function createGlobalContext(virtualFileExports) {
|
|
418
|
+
debug('createGlobalContext()');
|
|
418
419
|
assert(!getVikeConfigErrorBuild());
|
|
419
420
|
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
|
|
420
421
|
assertV1Design(
|
|
@@ -422,8 +423,8 @@ async function setGlobalContext(virtualFileExports) {
|
|
|
422
423
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
423
424
|
assertGlobalContextIsDefined();
|
|
424
425
|
onSetupRuntime();
|
|
425
|
-
debug('
|
|
426
|
-
// Never actually used, only used for TypeScript `ReturnType<typeof
|
|
426
|
+
debug('createGlobalContext() - done');
|
|
427
|
+
// Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
|
|
427
428
|
return globalContext;
|
|
428
429
|
}
|
|
429
430
|
async function addGlobalContextTmp(globalContext) {
|
|
@@ -182,7 +182,7 @@ function mergeScriptEntries(pageAssets, viteDevScript) {
|
|
|
182
182
|
return scriptEntry;
|
|
183
183
|
}
|
|
184
184
|
function getPageContextJsonScriptTag(pageContext) {
|
|
185
|
-
const pageContextClientSerialized = sanitizeJson(getPageContextClientSerialized(pageContext));
|
|
185
|
+
const pageContextClientSerialized = sanitizeJson(getPageContextClientSerialized(pageContext, true));
|
|
186
186
|
const htmlTag = `<script id="${htmlElementId_pageContext}" type="application/json">${pageContextClientSerialized}</script>`;
|
|
187
187
|
// Used by contra.com https://github.com/gajus
|
|
188
188
|
// @ts-expect-error
|
|
@@ -190,7 +190,7 @@ function getPageContextJsonScriptTag(pageContext) {
|
|
|
190
190
|
return htmlTag;
|
|
191
191
|
}
|
|
192
192
|
function getGlobalContextJsonScriptTag(pageContext) {
|
|
193
|
-
const globalContextClientSerialized = sanitizeJson(getGlobalContextClientSerialized(pageContext));
|
|
193
|
+
const globalContextClientSerialized = sanitizeJson(getGlobalContextClientSerialized(pageContext, true));
|
|
194
194
|
const htmlTag = `<script id="${htmlElementId_globalContext}" type="application/json">${globalContextClientSerialized}</script>`;
|
|
195
195
|
return htmlTag;
|
|
196
196
|
}
|
|
@@ -15,8 +15,8 @@ type PageContextSerialization = {
|
|
|
15
15
|
_globalContext: GlobalContextServerInternal;
|
|
16
16
|
isClientSideNavigation: boolean;
|
|
17
17
|
};
|
|
18
|
-
declare function getPageContextClientSerialized(pageContext: PageContextSerialization): string;
|
|
19
|
-
declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization): string;
|
|
18
|
+
declare function getPageContextClientSerialized(pageContext: PageContextSerialization, isHtmlJsonScript: boolean): string;
|
|
19
|
+
declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization, isHtmlJsonScript: boolean): string;
|
|
20
20
|
type PassToClient = (string | {
|
|
21
21
|
prop: string;
|
|
22
22
|
once?: boolean;
|
|
@@ -27,4 +27,4 @@ declare function getPageContextClientSerializedAbort(pageContext: Record<string,
|
|
|
27
27
|
_urlRewrite: string;
|
|
28
28
|
} | {
|
|
29
29
|
abortStatusCode: number;
|
|
30
|
-
})): string;
|
|
30
|
+
}), isHtmlJsonScript: false): string;
|
|
@@ -25,7 +25,7 @@ const passToClientBuiltInPageContext = [
|
|
|
25
25
|
'data', // for data() hook
|
|
26
26
|
];
|
|
27
27
|
const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError];
|
|
28
|
-
function getPageContextClientSerialized(pageContext) {
|
|
28
|
+
function getPageContextClientSerialized(pageContext, isHtmlJsonScript) {
|
|
29
29
|
const passToClientPageContext = getPassToClientPageContext(pageContext);
|
|
30
30
|
const getObj = (passToClientEntry) => {
|
|
31
31
|
if (passToClientEntry.once)
|
|
@@ -38,10 +38,10 @@ function getPageContextClientSerialized(pageContext) {
|
|
|
38
38
|
if (pageContextClientProps.some((prop) => getPropVal(pageContext._pageContextInit, prop))) {
|
|
39
39
|
pageContextClient[pageContextInitIsPassedToClient] = true;
|
|
40
40
|
}
|
|
41
|
-
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, getObj);
|
|
41
|
+
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, getObj, isHtmlJsonScript);
|
|
42
42
|
return pageContextClientSerialized;
|
|
43
43
|
}
|
|
44
|
-
function getGlobalContextClientSerialized(pageContext) {
|
|
44
|
+
function getGlobalContextClientSerialized(pageContext, isHtmlJsonScript) {
|
|
45
45
|
const passToClient = pageContext._passToClient;
|
|
46
46
|
const globalContext = pageContext._globalContext;
|
|
47
47
|
const getObj = ({ prop, once }) => {
|
|
@@ -58,13 +58,13 @@ function getGlobalContextClientSerialized(pageContext) {
|
|
|
58
58
|
};
|
|
59
59
|
const res = applyPassToClient(passToClient, getObj);
|
|
60
60
|
const globalContextClient = res.objClient;
|
|
61
|
-
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, getObj);
|
|
61
|
+
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, getObj, isHtmlJsonScript);
|
|
62
62
|
return globalContextClientSerialized;
|
|
63
63
|
}
|
|
64
|
-
function serializeObject(obj, passToClient, getObj) {
|
|
64
|
+
function serializeObject(obj, passToClient, getObj, isHtmlJsonScript) {
|
|
65
65
|
let serialized;
|
|
66
66
|
try {
|
|
67
|
-
serialized = serializeValue(obj);
|
|
67
|
+
serialized = serializeValue(obj, isHtmlJsonScript);
|
|
68
68
|
}
|
|
69
69
|
catch (err) {
|
|
70
70
|
const h = (s) => pc.cyan(s);
|
|
@@ -81,7 +81,7 @@ function serializeObject(obj, passToClient, getObj) {
|
|
|
81
81
|
assert(objName);
|
|
82
82
|
const varName = `${objName}${getPropKeys(prop).map(getPropAccessNotation).join('')}`;
|
|
83
83
|
try {
|
|
84
|
-
serializeValue(value, varName);
|
|
84
|
+
serializeValue(value, isHtmlJsonScript, varName);
|
|
85
85
|
}
|
|
86
86
|
catch (err) {
|
|
87
87
|
propsNonSerializable.push(prop);
|
|
@@ -119,7 +119,7 @@ function serializeObject(obj, passToClient, getObj) {
|
|
|
119
119
|
obj[getPropKeys(prop)[0]] = NOT_SERIALIZABLE;
|
|
120
120
|
});
|
|
121
121
|
try {
|
|
122
|
-
serialized = serializeValue(obj);
|
|
122
|
+
serialized = serializeValue(obj, isHtmlJsonScript);
|
|
123
123
|
}
|
|
124
124
|
catch (err) {
|
|
125
125
|
assert(false);
|
|
@@ -127,20 +127,20 @@ function serializeObject(obj, passToClient, getObj) {
|
|
|
127
127
|
}
|
|
128
128
|
return serialized;
|
|
129
129
|
}
|
|
130
|
-
function serializeValue(value, varName) {
|
|
130
|
+
function serializeValue(value, isHtmlJsonScript, varName) {
|
|
131
131
|
return stringify(value, {
|
|
132
132
|
forbidReactElements: true,
|
|
133
133
|
valueName: varName,
|
|
134
134
|
// Prevent Google from crawling URLs in JSON:
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
135
|
+
// - https://github.com/vikejs/vike/pull/2603
|
|
136
|
+
// - https://github.com/brillout/json-serializer/blob/38edbb9945de4938da1e65d6285ce1dd123a45ef/test/main.spec.ts#L44-L95
|
|
137
|
+
replacer: !isHtmlJsonScript
|
|
138
|
+
? undefined
|
|
139
|
+
: (_key, value) => {
|
|
140
|
+
if (typeof value === 'string') {
|
|
141
|
+
return { replacement: value.replaceAll('/', '\\/'), resolved: false };
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
function getPassToClientPageContext(pageContext) {
|
|
@@ -153,7 +153,7 @@ function getPassToClientPageContext(pageContext) {
|
|
|
153
153
|
passToClient = unique(passToClient);
|
|
154
154
|
return passToClient;
|
|
155
155
|
}
|
|
156
|
-
function getPageContextClientSerializedAbort(pageContext) {
|
|
156
|
+
function getPageContextClientSerializedAbort(pageContext, isHtmlJsonScript) {
|
|
157
157
|
assert(pageContext._urlRedirect || pageContext._urlRewrite || pageContext.abortStatusCode);
|
|
158
158
|
assert(pageContext._abortCall);
|
|
159
159
|
assert(pageContext._abortCaller);
|
|
@@ -186,7 +186,7 @@ function getPageContextClientSerializedAbort(pageContext) {
|
|
|
186
186
|
onlyOnce: false,
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
|
-
return serializeValue(pageContext);
|
|
189
|
+
return serializeValue(pageContext, isHtmlJsonScript);
|
|
190
190
|
}
|
|
191
191
|
function applyPassToClient(passToClient, getObj) {
|
|
192
192
|
const objClient = {};
|
|
@@ -45,7 +45,7 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
45
45
|
if (isError) {
|
|
46
46
|
objectAssign(pageContext, { [isServerSideError]: true });
|
|
47
47
|
}
|
|
48
|
-
const pageContextSerialized = getPageContextClientSerialized(pageContext);
|
|
48
|
+
const pageContextSerialized = getPageContextClientSerialized(pageContext, false);
|
|
49
49
|
const httpResponse = await createHttpResponsePageContextJson(pageContextSerialized);
|
|
50
50
|
objectAssign(pageContext, { httpResponse });
|
|
51
51
|
return pageContext;
|
|
@@ -75,7 +75,7 @@ async function prerenderPage(pageContext) {
|
|
|
75
75
|
return { documentHtml, pageContextSerialized: null, pageContext };
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
78
|
-
const pageContextSerialized = getPageContextClientSerialized(pageContext);
|
|
78
|
+
const pageContextSerialized = getPageContextClientSerialized(pageContext, false);
|
|
79
79
|
return { documentHtml, pageContextSerialized, pageContext };
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -419,10 +419,10 @@ pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalCont
|
|
|
419
419
|
objectAssign(pageContext, pageContextErrorPageInit, true);
|
|
420
420
|
augmentType(pageContext, await loadPageConfigsLazyServerSideAndExecHook(pageContext));
|
|
421
421
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
422
|
-
pageContextSerialized = getPageContextClientSerialized(pageContext);
|
|
422
|
+
pageContextSerialized = getPageContextClientSerialized(pageContext, false);
|
|
423
423
|
}
|
|
424
424
|
else {
|
|
425
|
-
pageContextSerialized = getPageContextClientSerializedAbort(pageContextAbort);
|
|
425
|
+
pageContextSerialized = getPageContextClientSerializedAbort(pageContextAbort, false);
|
|
426
426
|
}
|
|
427
427
|
const httpResponse = await createHttpResponsePageContextJson(pageContextSerialized);
|
|
428
428
|
const pageContextReturn = { httpResponse };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.236-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.236-commit-3c05c99";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.236-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.236-commit-3c05c99';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.236-commit-
|
|
3
|
+
"version": "0.4.236-commit-3c05c99",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
},
|
|
130
130
|
"dependencies": {
|
|
131
131
|
"@brillout/import": "^0.2.6",
|
|
132
|
-
"@brillout/json-serializer": "^0.5.
|
|
132
|
+
"@brillout/json-serializer": "^0.5.17",
|
|
133
133
|
"@brillout/picocolors": "^1.0.26",
|
|
134
134
|
"@brillout/require-shim": "^0.1.2",
|
|
135
135
|
"@brillout/vite-plugin-server-entry": "^0.7.12",
|