vike 0.4.178 → 0.4.179-commit-9384166
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/node/plugin/plugins/envVars.js +4 -0
- package/dist/cjs/node/runtime/html/injectAssets/inferHtmlTags.js +1 -0
- package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/injectAssets.js +1 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +14 -4
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -0
- package/dist/cjs/node/runtime/renderPage.js +14 -13
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/shared/route/index.js +4 -6
- package/dist/cjs/utils/assert.js +1 -1
- package/dist/cjs/utils/assertSingleInstance.js +7 -7
- package/dist/cjs/utils/augmentType.js +10 -0
- package/dist/cjs/utils/getPropAccessNotation.js +4 -1
- package/dist/cjs/utils/objectAssign.js +2 -0
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/createPageContext.js +2 -1
- package/dist/esm/client/client-routing-runtime/entry.js +5 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +5 -3
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +22 -27
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +6 -12
- package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/utils.js +1 -0
- package/dist/esm/client/server-routing-runtime/entry.js +5 -2
- package/dist/esm/client/shared/getPageContextProxyForUser.js +1 -1
- package/dist/esm/client/shared/removeFoucBuster.d.ts +2 -0
- package/dist/esm/client/shared/removeFoucBuster.js +44 -0
- package/dist/esm/client/shared/utils.d.ts +1 -0
- package/dist/esm/client/shared/utils.js +1 -0
- package/dist/esm/node/plugin/plugins/envVars.js +4 -0
- package/dist/esm/node/runtime/html/injectAssets/inferHtmlTags.js +1 -0
- package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/injectAssets.js +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +15 -5
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -0
- package/dist/esm/node/runtime/renderPage.js +14 -13
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/shared/route/index.d.ts +1 -1
- package/dist/esm/shared/route/index.js +4 -6
- package/dist/esm/shared/types.d.ts +1 -1
- package/dist/esm/utils/assert.js +2 -2
- package/dist/esm/utils/assertSingleInstance.d.ts +6 -6
- package/dist/esm/utils/assertSingleInstance.js +6 -6
- package/dist/esm/utils/augmentType.d.ts +3 -0
- package/dist/esm/utils/augmentType.js +7 -0
- package/dist/esm/utils/getPropAccessNotation.js +4 -1
- package/dist/esm/utils/objectAssign.d.ts +1 -1
- package/dist/esm/utils/objectAssign.js +2 -0
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +4 -4
|
@@ -5,6 +5,10 @@ const vite_1 = require("vite");
|
|
|
5
5
|
const utils_js_1 = require("../utils.js");
|
|
6
6
|
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
7
7
|
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
8
|
+
// TODO/enventually: (after we implemented vike.config.js)
|
|
9
|
+
// - Make import.meta.env work inside +config.js
|
|
10
|
+
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
11
|
+
// - Or stop using Vite's `mode` implemention and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
8
12
|
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
9
13
|
const PUBLIC_ENV_WHITELIST = [
|
|
10
14
|
// https://github.com/vikejs/vike/issues/1724
|
|
@@ -28,6 +28,7 @@ function inferAssetTag(pageAsset) {
|
|
|
28
28
|
return `<script src="${src}" ${scriptAttrs}></script>`;
|
|
29
29
|
}
|
|
30
30
|
if (assetType === 'style') {
|
|
31
|
+
// WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L29
|
|
31
32
|
return `<link rel="stylesheet" type="text/css" href="${src}">`;
|
|
32
33
|
}
|
|
33
34
|
(0, utils_js_1.assert)(false, { pageAsset });
|
|
@@ -11,12 +11,12 @@ function injectHtmlTags(htmlString, htmlTags, position) {
|
|
|
11
11
|
return htmlString;
|
|
12
12
|
}
|
|
13
13
|
exports.injectHtmlTags = injectHtmlTags;
|
|
14
|
-
|
|
14
|
+
function injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage) {
|
|
15
15
|
const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === 'STREAM'));
|
|
16
16
|
if (htmlFragment) {
|
|
17
17
|
(0, utils_js_1.assert)(streamFromReactStreamingPackage);
|
|
18
18
|
(0, utils_js_1.assert)(!streamFromReactStreamingPackage.hasStreamEnded());
|
|
19
|
-
|
|
19
|
+
streamFromReactStreamingPackage.injectToStream(htmlFragment, { flush: true });
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
exports.injectHtmlTagsUsingStream = injectHtmlTagsUsingStream;
|
|
@@ -29,7 +29,7 @@ function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, in
|
|
|
29
29
|
htmlTags = (0, getHtmlTags_js_1.getHtmlTags)(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript);
|
|
30
30
|
let htmlBegin = htmlPartsToString(htmlPartsBegin, pageAssets);
|
|
31
31
|
htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags);
|
|
32
|
-
|
|
32
|
+
(0, injectHtmlTags_js_1.injectHtmlTagsUsingStream)(htmlTags, streamFromReactStreamingPackage);
|
|
33
33
|
return htmlBegin;
|
|
34
34
|
}
|
|
35
35
|
async function injectAtStreamEnd(htmlPartsEnd) {
|
|
@@ -46,17 +46,27 @@ function serializePageContextClientSide(pageContext) {
|
|
|
46
46
|
let hasWarned = false;
|
|
47
47
|
const propsNonSerializable = [];
|
|
48
48
|
passToClient.forEach((prop) => {
|
|
49
|
-
const
|
|
50
|
-
const
|
|
49
|
+
const propName1 = (0, utils_js_1.getPropAccessNotation)(prop);
|
|
50
|
+
const propName2 = JSON.stringify(prop);
|
|
51
|
+
const varName = `pageContext${propName1}`;
|
|
51
52
|
try {
|
|
52
53
|
serialize(pageContext[prop], varName);
|
|
53
54
|
}
|
|
54
55
|
catch (err) {
|
|
55
56
|
hasWarned = true;
|
|
56
57
|
propsNonSerializable.push(prop);
|
|
58
|
+
// useConfig() wrong usage
|
|
59
|
+
if (prop === '_configFromHook') {
|
|
60
|
+
let pathString = '';
|
|
61
|
+
if ((0, stringify_1.isJsonSerializerError)(err)) {
|
|
62
|
+
pathString = err.pathString;
|
|
63
|
+
}
|
|
64
|
+
(0, utils_js_1.assertUsage)(false, `Cannot serialize config ${h(pathString)} set by useConfig(), see https://vike.dev/useConfig#serialization-error`);
|
|
65
|
+
}
|
|
66
|
+
// Non-serializable pageContext set by the user
|
|
57
67
|
let msg = [
|
|
58
|
-
`${varName}
|
|
59
|
-
`Make sure
|
|
68
|
+
`${h(varName)} can't be serialized and, therefore, can't be passed to the client side.`,
|
|
69
|
+
`Make sure ${h(varName)} is serializable, or remove ${h(propName2)} from ${h('passToClient')}.`
|
|
60
70
|
].join(' ');
|
|
61
71
|
if ((0, stringify_1.isJsonSerializerError)(err)) {
|
|
62
72
|
msg = `${msg} Serialization error: ${err.messageCore}.`;
|
|
@@ -28,7 +28,7 @@ async function executeOnRenderHtmlHook(pageContext) {
|
|
|
28
28
|
const onErrorWhileStreaming = (err) => {
|
|
29
29
|
// Should the stream inject the following?
|
|
30
30
|
// ```
|
|
31
|
-
// <script>console.error("An error occurred on the server while streaming the
|
|
31
|
+
// <script>console.error("An error occurred on the server side while streaming the page to HTML, see server logs.")</script>
|
|
32
32
|
// ```
|
|
33
33
|
(0, loggerRuntime_js_1.logRuntimeError)(err, pageContext._httpRequestId);
|
|
34
34
|
if (!pageContext.errorWhileRendering) {
|
|
@@ -35,6 +35,7 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
// https://github.com/vikejs/vike/issues/401
|
|
38
|
+
// WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L28
|
|
38
39
|
src = src + '?direct';
|
|
39
40
|
}
|
|
40
41
|
const isEntry = clientEntriesSrc.includes(src) ||
|
|
@@ -247,8 +247,7 @@ function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
|
247
247
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(msg, httpRequestId, isNominal ? 'info' : 'error');
|
|
248
248
|
}
|
|
249
249
|
function getPageContextHttpResponseNullWithError(err, pageContextInit) {
|
|
250
|
-
const pageContextHttpResponseNull =
|
|
251
|
-
(0, utils_js_1.objectAssign)(pageContextHttpResponseNull, pageContextInit);
|
|
250
|
+
const pageContextHttpResponseNull = createPageContext(pageContextInit);
|
|
252
251
|
(0, utils_js_1.objectAssign)(pageContextHttpResponseNull, {
|
|
253
252
|
httpResponse: null,
|
|
254
253
|
errorWhileRendering: err
|
|
@@ -256,14 +255,20 @@ function getPageContextHttpResponseNullWithError(err, pageContextInit) {
|
|
|
256
255
|
return pageContextHttpResponseNull;
|
|
257
256
|
}
|
|
258
257
|
function getPageContextHttpResponseNull(pageContextInit) {
|
|
259
|
-
const pageContextHttpResponseNull =
|
|
260
|
-
(0, utils_js_1.objectAssign)(pageContextHttpResponseNull, pageContextInit);
|
|
258
|
+
const pageContextHttpResponseNull = createPageContext(pageContextInit);
|
|
261
259
|
(0, utils_js_1.objectAssign)(pageContextHttpResponseNull, {
|
|
262
260
|
httpResponse: null,
|
|
263
261
|
errorWhileRendering: null
|
|
264
262
|
});
|
|
265
263
|
return pageContextHttpResponseNull;
|
|
266
264
|
}
|
|
265
|
+
function createPageContext(pageContextInit) {
|
|
266
|
+
const pageContext = {
|
|
267
|
+
_isPageContextObject: true
|
|
268
|
+
};
|
|
269
|
+
Object.assign(pageContext, pageContextInit);
|
|
270
|
+
return pageContext;
|
|
271
|
+
}
|
|
267
272
|
async function renderPageNominal(pageContext) {
|
|
268
273
|
(0, utils_js_1.objectAssign)(pageContext, { errorWhileRendering: null });
|
|
269
274
|
// Route
|
|
@@ -347,8 +352,7 @@ function normalizeUrl(pageContextInit, httpRequestId) {
|
|
|
347
352
|
return null;
|
|
348
353
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`URL normalized from ${picocolors_1.default.cyan(urlOriginal)} to ${picocolors_1.default.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
349
354
|
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)({ url: urlNormalized, statusCode: 301 }, pageContextInit.urlOriginal);
|
|
350
|
-
const pageContextHttpResponse =
|
|
351
|
-
(0, utils_js_1.objectAssign)(pageContextHttpResponse, pageContextInit);
|
|
355
|
+
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
352
356
|
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
353
357
|
return pageContextHttpResponse;
|
|
354
358
|
}
|
|
@@ -384,8 +388,7 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
|
384
388
|
}
|
|
385
389
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
386
390
|
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
|
|
387
|
-
const pageContextHttpResponse =
|
|
388
|
-
(0, utils_js_1.objectAssign)(pageContextHttpResponse, pageContextInit);
|
|
391
|
+
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
389
392
|
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
390
393
|
return pageContextHttpResponse;
|
|
391
394
|
}
|
|
@@ -401,9 +404,8 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
401
404
|
const abortCall = pageContextAbort._abortCall;
|
|
402
405
|
(0, utils_js_1.assert)(abortCall);
|
|
403
406
|
(0, utils_js_1.assertUsage)(errorPageId, `You called ${picocolors_1.default.cyan(abortCall)} but you didn't define an error page, make sure to define one https://vike.dev/error-page`);
|
|
404
|
-
const pageContext = {
|
|
405
|
-
|
|
406
|
-
};
|
|
407
|
+
const pageContext = createPageContext({});
|
|
408
|
+
(0, utils_js_1.objectAssign)(pageContext, { _pageId: errorPageId });
|
|
407
409
|
(0, utils_js_1.objectAssign)(pageContext, pageContextAbort);
|
|
408
410
|
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit);
|
|
409
411
|
(0, utils_js_1.objectAssign)(pageContext, renderContext);
|
|
@@ -427,8 +429,7 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
427
429
|
return { pageContextReturn };
|
|
428
430
|
}
|
|
429
431
|
if (pageContextAbort._urlRedirect) {
|
|
430
|
-
const pageContextReturn =
|
|
431
|
-
(0, utils_js_1.objectAssign)(pageContextReturn, pageContextInit);
|
|
432
|
+
const pageContextReturn = createPageContext(pageContextInit);
|
|
432
433
|
(0, utils_js_1.objectAssign)(pageContextReturn, pageContextAbort);
|
|
433
434
|
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)(pageContextAbort._urlRedirect, (() => {
|
|
434
435
|
const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
|
|
@@ -71,3 +71,4 @@ __exportStar(require("../../utils/isArrayOfStrings.js"), exports);
|
|
|
71
71
|
__exportStar(require("../../utils/escapeHtml.js"), exports);
|
|
72
72
|
__exportStar(require("../../utils/normalizeHeaders.js"), exports);
|
|
73
73
|
__exportStar(require("../../utils/isVikeReactApp.js"), exports);
|
|
74
|
+
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
@@ -18,12 +18,12 @@ const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
|
18
18
|
const executeOnBeforeRouteHook_js_1 = require("./executeOnBeforeRouteHook.js");
|
|
19
19
|
const debug_js_1 = require("./debug.js");
|
|
20
20
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
21
|
-
async function route(
|
|
22
|
-
(0, debug_js_1.debug)('Pages routes:',
|
|
23
|
-
(0, getPageContextUrlComputed_js_1.assertPageContextUrl)(
|
|
21
|
+
async function route(pageContext) {
|
|
22
|
+
(0, debug_js_1.debug)('Pages routes:', pageContext._pageRoutes);
|
|
23
|
+
(0, getPageContextUrlComputed_js_1.assertPageContextUrl)(pageContext);
|
|
24
24
|
const pageContextFromRoute = {};
|
|
25
25
|
// onBeforeRoute()
|
|
26
|
-
const pageContextFromOnBeforeRouteHook = await (0, executeOnBeforeRouteHook_js_1.executeOnBeforeRouteHook)(
|
|
26
|
+
const pageContextFromOnBeforeRouteHook = await (0, executeOnBeforeRouteHook_js_1.executeOnBeforeRouteHook)(pageContext);
|
|
27
27
|
if (pageContextFromOnBeforeRouteHook) {
|
|
28
28
|
if (pageContextFromOnBeforeRouteHook._routingProvidedByOnBeforeRouteHook) {
|
|
29
29
|
(0, utils_js_1.assert)(pageContextFromOnBeforeRouteHook._pageId);
|
|
@@ -34,8 +34,6 @@ async function route(pageContextForRoute) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
// We take into account pageContext.urlLogical set by onBeforeRoute()
|
|
37
|
-
const pageContext = {};
|
|
38
|
-
(0, utils_js_1.objectAssign)(pageContext, pageContextForRoute);
|
|
39
37
|
(0, utils_js_1.objectAssign)(pageContext, pageContextFromOnBeforeRouteHook);
|
|
40
38
|
// Vike's routing
|
|
41
39
|
const allPageIds = pageContext._allPageIds;
|
package/dist/cjs/utils/assert.js
CHANGED
|
@@ -23,7 +23,7 @@ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assert.ts'
|
|
|
23
23
|
},
|
|
24
24
|
showStackTraceList: new WeakSet()
|
|
25
25
|
});
|
|
26
|
-
(0, assertSingleInstance_js_1.
|
|
26
|
+
(0, assertSingleInstance_js_1.assertSingleInstance_onAssertModuleLoad)();
|
|
27
27
|
const projectTag = `[vike]`;
|
|
28
28
|
const projectTagWithVersion = `[vike@${projectInfo_js_1.projectInfo.projectVersion}]`;
|
|
29
29
|
const numberOfStackTraceLinesToRemove = 2;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.assertSingleInstance_onAssertModuleLoad = exports.assertSingleInstance_onClientEntryClientRouting = exports.assertSingleInstance_onClientEntryServerRouting = void 0;
|
|
7
7
|
// - Throw error if there are two different versions of vike loaded
|
|
8
8
|
// - Show warning if entry of Client Routing and entry of Server Routing are both loaded
|
|
9
9
|
// - Show warning if vike is loaded twice
|
|
@@ -35,7 +35,7 @@ function assertSingleInstance() {
|
|
|
35
35
|
//*/
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function assertSingleInstance_onClientEntryServerRouting(isProduction) {
|
|
39
39
|
assertWarning(globalObject.isClientRouting !== true, clientRuntimesClonflict, {
|
|
40
40
|
onlyOnce: true,
|
|
41
41
|
showStackTrace: true
|
|
@@ -49,8 +49,8 @@ function onClientEntry_ServerRouting(isProduction) {
|
|
|
49
49
|
globalObject.checkSingleInstance = true;
|
|
50
50
|
assertSingleInstance();
|
|
51
51
|
}
|
|
52
|
-
exports.
|
|
53
|
-
function
|
|
52
|
+
exports.assertSingleInstance_onClientEntryServerRouting = assertSingleInstance_onClientEntryServerRouting;
|
|
53
|
+
function assertSingleInstance_onClientEntryClientRouting(isProduction) {
|
|
54
54
|
assertWarning(globalObject.isClientRouting !== false, clientRuntimesClonflict, {
|
|
55
55
|
onlyOnce: true,
|
|
56
56
|
showStackTrace: true
|
|
@@ -64,13 +64,13 @@ function onClientEntry_ClientRouting(isProduction) {
|
|
|
64
64
|
globalObject.checkSingleInstance = true;
|
|
65
65
|
assertSingleInstance();
|
|
66
66
|
}
|
|
67
|
-
exports.
|
|
67
|
+
exports.assertSingleInstance_onClientEntryClientRouting = assertSingleInstance_onClientEntryClientRouting;
|
|
68
68
|
// Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
|
|
69
|
-
function
|
|
69
|
+
function assertSingleInstance_onAssertModuleLoad() {
|
|
70
70
|
globalObject.instances.push(projectInfo_js_1.projectInfo.projectVersion);
|
|
71
71
|
assertSingleInstance();
|
|
72
72
|
}
|
|
73
|
-
exports.
|
|
73
|
+
exports.assertSingleInstance_onAssertModuleLoad = assertSingleInstance_onAssertModuleLoad;
|
|
74
74
|
function assertUsage(condition, errorMessage) {
|
|
75
75
|
if (condition) {
|
|
76
76
|
return;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.augmentType = void 0;
|
|
4
|
+
const assert_js_1 = require("./assert.js");
|
|
5
|
+
/** Help TypeScript augment the type of objects. */
|
|
6
|
+
function augmentType(thing, clone) {
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
(0, assert_js_1.assert)(thing === clone);
|
|
9
|
+
}
|
|
10
|
+
exports.augmentType = augmentType;
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPropAccessNotation = void 0;
|
|
4
4
|
function getPropAccessNotation(key) {
|
|
5
|
-
return typeof key === 'string' &&
|
|
5
|
+
return typeof key === 'string' && isKeyDotNotationCompatible(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
6
6
|
}
|
|
7
7
|
exports.getPropAccessNotation = getPropAccessNotation;
|
|
8
|
+
function isKeyDotNotationCompatible(key) {
|
|
9
|
+
return /^[a-z0-9\$_]+$/i.test(key);
|
|
10
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.objectAssign = void 0;
|
|
4
|
+
const assert_js_1 = require("./assert.js");
|
|
4
5
|
// Same as Object.assign() but:
|
|
5
6
|
// - With type inference
|
|
6
7
|
// - Preserves property descriptors, which we need for preserving the getters added by getPageContextUrlComputed()
|
|
7
8
|
function objectAssign(obj, objAddendum) {
|
|
8
9
|
if (objAddendum) {
|
|
10
|
+
(0, assert_js_1.assert)(!('_isPageContextObject' in objAddendum));
|
|
9
11
|
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
10
12
|
}
|
|
11
13
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
|
-
const PROJECT_VERSION = '0.4.
|
|
4
|
+
const PROJECT_VERSION = '0.4.179-commit-9384166';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
|
@@ -11,6 +11,7 @@ declare function createPageContext(urlOriginal: string): Promise<{
|
|
|
11
11
|
_allPageIds: string[];
|
|
12
12
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
13
13
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
14
|
+
_isPageContextObject: boolean;
|
|
14
15
|
} & {
|
|
15
16
|
urlParsed: import("../../shared/getPageContextUrlComputed.js").Url;
|
|
16
17
|
urlPathname: string;
|
|
@@ -24,7 +24,8 @@ async function createPageContext(urlOriginal) {
|
|
|
24
24
|
_pageConfigGlobal: pageConfigGlobal,
|
|
25
25
|
_allPageIds: allPageIds,
|
|
26
26
|
_pageRoutes: pageRoutes,
|
|
27
|
-
_onBeforeRouteHook: onBeforeRouteHook
|
|
27
|
+
_onBeforeRouteHook: onBeforeRouteHook,
|
|
28
|
+
_isPageContextObject: true
|
|
28
29
|
};
|
|
29
30
|
const pageContextUrlComputed = getPageContextUrlComputed(pageContext);
|
|
30
31
|
objectAssign(pageContext, pageContextUrlComputed);
|
|
@@ -2,8 +2,11 @@ import { assertClientRouting } from '../../utils/assertRoutingType.js';
|
|
|
2
2
|
assertClientRouting();
|
|
3
3
|
import './pageFiles';
|
|
4
4
|
import { installClientRouter } from './installClientRouter.js';
|
|
5
|
-
import {
|
|
5
|
+
import { assertSingleInstance_onClientEntryClientRouting } from './utils.js';
|
|
6
|
+
import { removeFoucBuster } from '../shared/removeFoucBuster.js';
|
|
6
7
|
// @ts-ignore Since dist/cjs/client/ is never used, we can ignore this error.
|
|
7
8
|
const isProd = import.meta.env.PROD;
|
|
8
|
-
|
|
9
|
+
assertSingleInstance_onClientEntryClientRouting(isProd);
|
|
10
|
+
if (import.meta.env.DEV)
|
|
11
|
+
removeFoucBuster();
|
|
9
12
|
installClientRouter();
|
|
@@ -16,7 +16,7 @@ type PageContextSerialized = {
|
|
|
16
16
|
declare function getPageContextFromHooks_serialized(): PageContextSerialized & {
|
|
17
17
|
routeParams: Record<string, string>;
|
|
18
18
|
};
|
|
19
|
-
declare function getPageContextFromHooks_isHydration(pageContext: PageContextSerialized & PageContext & PageContextExports): Promise<{
|
|
19
|
+
declare function getPageContextFromHooks_isHydration(pageContext: PageContextSerialized & PageContext & PageContextExports): Promise<PageContextSerialized & PageContext & PageContextExports & {
|
|
20
20
|
isHydration: true;
|
|
21
21
|
_hasPageContextFromClient: false;
|
|
22
22
|
_hasPageContextFromServer: true;
|
|
@@ -25,9 +25,11 @@ declare function getPageContextFromHooks_isNotHydration(pageContext: {
|
|
|
25
25
|
_pageId: string;
|
|
26
26
|
} & PageContext & PageContextExports, isErrorPage: boolean): Promise<{
|
|
27
27
|
is404ServerSideRouted: boolean;
|
|
28
|
-
|
|
28
|
+
pageContextAugmented?: undefined;
|
|
29
29
|
} | {
|
|
30
|
-
|
|
30
|
+
pageContextAugmented: {
|
|
31
|
+
_pageId: string;
|
|
32
|
+
} & PageContext & PageContextExports & {
|
|
31
33
|
isHydration: false;
|
|
32
34
|
_hasPageContextFromClient: boolean;
|
|
33
35
|
} & {
|
|
@@ -27,30 +27,26 @@ function getPageContextFromHooks_serialized() {
|
|
|
27
27
|
return pageContextSerialized;
|
|
28
28
|
}
|
|
29
29
|
async function getPageContextFromHooks_isHydration(pageContext) {
|
|
30
|
-
|
|
30
|
+
objectAssign(pageContext, {
|
|
31
31
|
isHydration: true,
|
|
32
32
|
_hasPageContextFromClient: false,
|
|
33
33
|
_hasPageContextFromServer: true
|
|
34
|
-
};
|
|
34
|
+
});
|
|
35
35
|
for (const hookName of ['data', 'onBeforeRender']) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Object.assign(pageContextFromHooks, pageContextFromHook);
|
|
36
|
+
if (hookClientOnlyExists(hookName, pageContext)) {
|
|
37
|
+
const pageContextFromHook = await executeHookClientSide(hookName, pageContext);
|
|
38
|
+
if (pageContextFromHook)
|
|
39
|
+
assert(!('urlOriginal' in pageContextFromHook));
|
|
40
|
+
Object.assign(pageContext, pageContextFromHook);
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
|
-
return
|
|
43
|
+
return pageContext;
|
|
45
44
|
}
|
|
46
45
|
async function getPageContextFromHooks_isNotHydration(pageContext, isErrorPage) {
|
|
47
|
-
|
|
46
|
+
objectAssign(pageContext, {
|
|
48
47
|
isHydration: false,
|
|
49
48
|
_hasPageContextFromClient: false
|
|
50
|
-
};
|
|
51
|
-
const pageContextForCondition = {};
|
|
52
|
-
objectAssign(pageContextForCondition, pageContext);
|
|
53
|
-
objectAssign(pageContextForCondition, pageContextFromHooks);
|
|
49
|
+
});
|
|
54
50
|
let hasPageContextFromServer = false;
|
|
55
51
|
// If pageContextInit has some client data or if one of the hooks guard(), data() or onBeforeRender() is server-side
|
|
56
52
|
// only, then we need to fetch pageContext from the server.
|
|
@@ -59,7 +55,7 @@ async function getPageContextFromHooks_isNotHydration(pageContext, isErrorPage)
|
|
|
59
55
|
// For the error page, we cannot fetch pageContext from the server because the pageContext JSON request is based on the URL
|
|
60
56
|
!isErrorPage &&
|
|
61
57
|
// true if pageContextInit has some client data or at least one of the data() and onBeforeRender() hooks is server-side only:
|
|
62
|
-
(await hasPageContextServer(
|
|
58
|
+
(await hasPageContextServer(pageContext))) {
|
|
63
59
|
const res = await fetchPageContextFromServer(pageContext);
|
|
64
60
|
if ('is404ServerSideRouted' in res)
|
|
65
61
|
return { is404ServerSideRouted: true };
|
|
@@ -68,43 +64,42 @@ async function getPageContextFromHooks_isNotHydration(pageContext, isErrorPage)
|
|
|
68
64
|
// Already handled
|
|
69
65
|
assert(!(isServerSideError in pageContextFromServer));
|
|
70
66
|
assert(!('serverSideError' in pageContextFromServer));
|
|
71
|
-
objectAssign(
|
|
67
|
+
objectAssign(pageContext, pageContextFromServer);
|
|
72
68
|
}
|
|
69
|
+
objectAssign(pageContext, { _hasPageContextFromServer: hasPageContextFromServer });
|
|
73
70
|
// At this point, we need to call the client-side guard(), data() and onBeforeRender() hooks, if they exist on client
|
|
74
71
|
// env. However if we have fetched pageContext from the server, some of them might have run already on the
|
|
75
72
|
// server-side, so we run only the client-only ones in this case.
|
|
76
73
|
// Note: for the error page, we also execute the client-side data() and onBeforeRender() hooks, but maybe we
|
|
77
74
|
// shouldn't? The server-side does it as well (but maybe it shouldn't).
|
|
78
75
|
for (const hookName of ['guard', 'data', 'onBeforeRender']) {
|
|
79
|
-
const pageContextForHook = {};
|
|
80
|
-
objectAssign(pageContextForHook, { _hasPageContextFromServer: hasPageContextFromServer });
|
|
81
|
-
objectAssign(pageContextForHook, pageContext);
|
|
82
|
-
objectAssign(pageContextForHook, pageContextFromHooks);
|
|
83
76
|
if (hookName === 'guard') {
|
|
84
77
|
if (!isErrorPage &&
|
|
85
78
|
// We don't need to call guard() on the client-side if we fetch pageContext from the server side. (Because the `${url}.pageContext.json` HTTP request will already trigger the routing and guard() hook on the server-side.)
|
|
86
79
|
!hasPageContextFromServer) {
|
|
87
80
|
// Should we really call the guard() hook on the client-side? Shouldn't we make the guard() hook a server-side
|
|
88
81
|
// only hook? Or maybe make its env configurable like data() and onBeforeRender()?
|
|
89
|
-
await executeGuardHook(
|
|
82
|
+
await executeGuardHook(pageContext, (pageContext) => preparePageContextForUserConsumptionClientSide(pageContext, true));
|
|
90
83
|
}
|
|
91
84
|
}
|
|
92
85
|
else {
|
|
93
86
|
assert(hookName === 'data' || hookName === 'onBeforeRender');
|
|
94
|
-
if (hookClientOnlyExists(hookName,
|
|
87
|
+
if (hookClientOnlyExists(hookName, pageContext) || !hasPageContextFromServer) {
|
|
95
88
|
// This won't do anything if no hook has been defined or if the hook's env.client is false.
|
|
96
|
-
const pageContextFromHook = await executeHookClientSide(hookName,
|
|
97
|
-
|
|
89
|
+
const pageContextFromHook = await executeHookClientSide(hookName, pageContext);
|
|
90
|
+
if (pageContextFromHook)
|
|
91
|
+
assert(!('urlOriginal' in pageContextFromHook));
|
|
92
|
+
Object.assign(pageContext, pageContextFromHook);
|
|
98
93
|
}
|
|
99
94
|
else {
|
|
100
95
|
assert(hasPageContextFromServer);
|
|
101
96
|
}
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
|
-
objectAssign(
|
|
99
|
+
objectAssign(pageContext, {
|
|
105
100
|
_hasPageContextFromServer: hasPageContextFromServer
|
|
106
101
|
});
|
|
107
|
-
return {
|
|
102
|
+
return { pageContextAugmented: pageContext };
|
|
108
103
|
}
|
|
109
104
|
async function executeHookClientSide(hookName, pageContext) {
|
|
110
105
|
const hook = getHook(pageContext, hookName);
|
|
@@ -226,7 +221,7 @@ async function fetchPageContextFromServer(pageContext) {
|
|
|
226
221
|
}
|
|
227
222
|
// Is there a reason for having two different properties? Can't we use only one property? I guess/think the isServerSideError property was an attempt (a bad idea really) for rendering the error page even though an error occured on the server-side (which is a bad idea because the added complexity is non-negligible while the added value is minuscule since the error page usually doesn't have any (meaningful / server-side) hooks).
|
|
228
223
|
if ('serverSideError' in pageContextFromServer || isServerSideError in pageContextFromServer) {
|
|
229
|
-
throw getProjectError(`pageContext couldn't be fetched
|
|
224
|
+
throw getProjectError(`pageContext couldn't be fetched because an error occurred on the server-side`);
|
|
230
225
|
}
|
|
231
226
|
assert(hasProp(pageContextFromServer, '_pageId', 'string'));
|
|
232
227
|
processPageContextFromServer(pageContextFromServer);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { renderPageClientSide };
|
|
2
2
|
export { getRenderCount };
|
|
3
3
|
export { disableClientRouting };
|
|
4
|
-
import { assert, getCurrentUrl, isSameErrorMessage, objectAssign, serverSideRouteTo, getGlobalObject, executeHook, hasProp } from './utils.js';
|
|
4
|
+
import { assert, getCurrentUrl, isSameErrorMessage, objectAssign, serverSideRouteTo, getGlobalObject, executeHook, hasProp, augmentType } from './utils.js';
|
|
5
5
|
import { getPageContextFromHooks_isHydration, getPageContextFromHooks_isNotHydration, getPageContextFromHooks_serialized } from './getPageContextFromHooks.js';
|
|
6
6
|
import { createPageContext } from './createPageContext.js';
|
|
7
7
|
import { addLinkPrefetchHandlers } from './prefetch.js';
|
|
@@ -132,9 +132,9 @@ async function renderPageClientSide(renderArgs) {
|
|
|
132
132
|
// Get pageContext from hooks (fetched from server, and/or directly called on the client-side)
|
|
133
133
|
if (isHydrationRender) {
|
|
134
134
|
assert(hasProp(pageContext, '_hasPageContextFromServer', 'true'));
|
|
135
|
-
let
|
|
135
|
+
let pageContextAugmented;
|
|
136
136
|
try {
|
|
137
|
-
|
|
137
|
+
pageContextAugmented = await getPageContextFromHooks_isHydration(pageContext);
|
|
138
138
|
}
|
|
139
139
|
catch (err) {
|
|
140
140
|
await onError(err);
|
|
@@ -142,8 +142,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
142
142
|
}
|
|
143
143
|
if (isRenderOutdated())
|
|
144
144
|
return;
|
|
145
|
-
|
|
146
|
-
objectAssign(pageContext, pageContextFromHooks);
|
|
145
|
+
augmentType(pageContext, pageContextAugmented);
|
|
147
146
|
// Render page view
|
|
148
147
|
await renderPageView(pageContext);
|
|
149
148
|
}
|
|
@@ -160,9 +159,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
160
159
|
return;
|
|
161
160
|
if ('is404ServerSideRouted' in res)
|
|
162
161
|
return;
|
|
163
|
-
|
|
164
|
-
assert(!('urlOriginal' in pageContextFromHooks));
|
|
165
|
-
objectAssign(pageContext, pageContextFromHooks);
|
|
162
|
+
augmentType(pageContext, res.pageContextAugmented);
|
|
166
163
|
// Render page view
|
|
167
164
|
await renderPageView(pageContext);
|
|
168
165
|
}
|
|
@@ -295,10 +292,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
295
292
|
return;
|
|
296
293
|
if ('is404ServerSideRouted' in res)
|
|
297
294
|
return;
|
|
298
|
-
|
|
299
|
-
assert(pageContextFromHooks);
|
|
300
|
-
assert(!('urlOriginal' in pageContextFromHooks));
|
|
301
|
-
objectAssign(pageContext, pageContextFromHooks);
|
|
295
|
+
augmentType(pageContext, res.pageContextAugmented);
|
|
302
296
|
await renderPageView(pageContext, args);
|
|
303
297
|
}
|
|
304
298
|
async function renderPageView(pageContext, isErrorPage) {
|
|
@@ -4,10 +4,13 @@ import './pageFiles';
|
|
|
4
4
|
import { getPageContext } from './getPageContext.js';
|
|
5
5
|
import { executeOnRenderClientHook } from '../shared/executeOnRenderClientHook.js';
|
|
6
6
|
import { assertHook } from '../../shared/hooks/getHook.js';
|
|
7
|
-
import {
|
|
7
|
+
import { assertSingleInstance_onClientEntryServerRouting } from './utils.js';
|
|
8
|
+
import { removeFoucBuster } from '../shared/removeFoucBuster.js';
|
|
8
9
|
// @ts-ignore Since dist/cjs/client/ is never used, we can ignore this error.
|
|
9
10
|
const isProd = import.meta.env.PROD;
|
|
10
|
-
|
|
11
|
+
assertSingleInstance_onClientEntryServerRouting(isProd);
|
|
12
|
+
if (import.meta.env.DEV)
|
|
13
|
+
removeFoucBuster();
|
|
11
14
|
hydrate();
|
|
12
15
|
async function hydrate() {
|
|
13
16
|
const pageContext = await getPageContext();
|
|
@@ -14,7 +14,7 @@ function getPageContextProxyForUser(pageContext) {
|
|
|
14
14
|
get(_, prop) {
|
|
15
15
|
const val = pageContext[prop];
|
|
16
16
|
const propName = getPropAccessNotation(prop);
|
|
17
|
-
assertUsage(val !== notSerializable, `pageContext${propName}
|
|
17
|
+
assertUsage(val !== notSerializable, `Can't access pageContext${propName} on the client side. Because it can't be serialized, see server logs.`);
|
|
18
18
|
passToClientHint(pageContext, prop, propName);
|
|
19
19
|
return val;
|
|
20
20
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export { removeFoucBuster };
|
|
2
|
+
import { assert } from './utils.js';
|
|
3
|
+
// See also:
|
|
4
|
+
// - Alternative approach of exactly injecting what Vite injects:
|
|
5
|
+
// - https://github.com/remix-run/remix/issues/8830#issuecomment-1968368351
|
|
6
|
+
// - https://github.com/rakkasjs/rakkasjs/blob/7d75ccc915e93bca04e6bab37dc6abdb68a85e4a/packages/rakkasjs/src/features/pages/middleware.tsx#L701
|
|
7
|
+
// - https://github.com/remix-run/remix/issues/8830
|
|
8
|
+
function removeFoucBuster() {
|
|
9
|
+
assert(import.meta.env.DEV);
|
|
10
|
+
let sleep = 2;
|
|
11
|
+
const runClean = () => {
|
|
12
|
+
const isClean = clean();
|
|
13
|
+
if (!isClean) {
|
|
14
|
+
if (sleep < 1000)
|
|
15
|
+
sleep = 2 * sleep;
|
|
16
|
+
setTimeout(runClean, sleep);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
setTimeout(runClean, sleep);
|
|
20
|
+
}
|
|
21
|
+
function clean() {
|
|
22
|
+
const VITE_ID = 'data-vite-dev-id';
|
|
23
|
+
const injectedByVite = [...document.querySelectorAll(`style[${VITE_ID}]`)].map((style) => style.getAttribute(VITE_ID));
|
|
24
|
+
// ```
|
|
25
|
+
// <link rel="stylesheet" type="text/css" href="/renderer/css/index.css?direct">
|
|
26
|
+
// <link rel="stylesheet" type="text/css" href="/renderer/Layout.css?direct">
|
|
27
|
+
// ```
|
|
28
|
+
const suffix = '?direct';
|
|
29
|
+
// <link> defined by:
|
|
30
|
+
// - https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/node/runtime/html/injectAssets/inferHtmlTags.ts#L35
|
|
31
|
+
// - https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/node/runtime/renderPage/getPageAssets.ts#L68
|
|
32
|
+
const injectedByVike = [...document.querySelectorAll(`link[rel="stylesheet"][type="text/css"][href$="${suffix}"]`)];
|
|
33
|
+
let isClean = true;
|
|
34
|
+
injectedByVike.forEach((link) => {
|
|
35
|
+
const filePathAbsoluteUserRootDir = link.getAttribute('href').slice(0, -suffix.length);
|
|
36
|
+
if (injectedByVite.some((filePathAbsoluteFilesystem) => filePathAbsoluteFilesystem.endsWith(filePathAbsoluteUserRootDir))) {
|
|
37
|
+
link.remove();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
isClean = false;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return isClean;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../utils/assert.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../utils/assert.js';
|
|
@@ -5,6 +5,10 @@ import { loadEnv } from 'vite';
|
|
|
5
5
|
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, lowerFirst } from '../utils.js';
|
|
6
6
|
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
7
7
|
import { getModuleFilePath } from '../shared/getFilePath.js';
|
|
8
|
+
// TODO/enventually: (after we implemented vike.config.js)
|
|
9
|
+
// - Make import.meta.env work inside +config.js
|
|
10
|
+
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
11
|
+
// - Or stop using Vite's `mode` implemention and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
8
12
|
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
9
13
|
const PUBLIC_ENV_WHITELIST = [
|
|
10
14
|
// https://github.com/vikejs/vike/issues/1724
|
|
@@ -27,6 +27,7 @@ function inferAssetTag(pageAsset) {
|
|
|
27
27
|
return `<script src="${src}" ${scriptAttrs}></script>`;
|
|
28
28
|
}
|
|
29
29
|
if (assetType === 'style') {
|
|
30
|
+
// WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L29
|
|
30
31
|
return `<link rel="stylesheet" type="text/css" href="${src}">`;
|
|
31
32
|
}
|
|
32
33
|
assert(false, { pageAsset });
|
|
@@ -7,7 +7,7 @@ import type { StreamFromReactStreamingPackage } from '../stream/react-streaming.
|
|
|
7
7
|
import type { HtmlTag } from './getHtmlTags.js';
|
|
8
8
|
type Position = 'HTML_BEGIN' | 'HTML_END';
|
|
9
9
|
declare function injectHtmlTags(htmlString: string, htmlTags: HtmlTag[], position: Position): string;
|
|
10
|
-
declare function injectHtmlTagsUsingStream(htmlTags: HtmlTag[], streamFromReactStreamingPackage: null | StreamFromReactStreamingPackage):
|
|
10
|
+
declare function injectHtmlTagsUsingStream(htmlTags: HtmlTag[], streamFromReactStreamingPackage: null | StreamFromReactStreamingPackage): void;
|
|
11
11
|
declare function injectAtOpeningTag(tag: 'head' | 'html' | '!doctype', htmlString: string, htmlFragment: string): string;
|
|
12
12
|
declare function injectAtClosingTag(tag: 'body' | 'html', htmlString: string, htmlFragment: string): string;
|
|
13
13
|
declare function createHtmlHeadIfMissing(htmlString: string): string;
|
|
@@ -13,12 +13,12 @@ function injectHtmlTags(htmlString, htmlTags, position) {
|
|
|
13
13
|
}
|
|
14
14
|
return htmlString;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
function injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage) {
|
|
17
17
|
const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === 'STREAM'));
|
|
18
18
|
if (htmlFragment) {
|
|
19
19
|
assert(streamFromReactStreamingPackage);
|
|
20
20
|
assert(!streamFromReactStreamingPackage.hasStreamEnded());
|
|
21
|
-
|
|
21
|
+
streamFromReactStreamingPackage.injectToStream(htmlFragment, { flush: true });
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
function joinHtmlTags(htmlTags) {
|
|
@@ -27,7 +27,7 @@ function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, in
|
|
|
27
27
|
htmlTags = getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript);
|
|
28
28
|
let htmlBegin = htmlPartsToString(htmlPartsBegin, pageAssets);
|
|
29
29
|
htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags);
|
|
30
|
-
|
|
30
|
+
injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage);
|
|
31
31
|
return htmlBegin;
|
|
32
32
|
}
|
|
33
33
|
async function injectAtStreamEnd(htmlPartsEnd) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { serializePageContextClientSide };
|
|
2
2
|
export { serializePageContextAbort };
|
|
3
3
|
import { stringify, isJsonSerializerError } from '@brillout/json-serializer/stringify';
|
|
4
|
-
import { assert, assertWarning, hasProp, unique } from '../utils.js';
|
|
4
|
+
import { assert, assertUsage, assertWarning, getPropAccessNotation, hasProp, unique } from '../utils.js';
|
|
5
5
|
import { isErrorPage } from '../../../shared/error-page.js';
|
|
6
6
|
import { addIs404ToPageProps } from '../../../shared/addIs404ToPageProps.js';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
@@ -42,17 +42,27 @@ function serializePageContextClientSide(pageContext) {
|
|
|
42
42
|
let hasWarned = false;
|
|
43
43
|
const propsNonSerializable = [];
|
|
44
44
|
passToClient.forEach((prop) => {
|
|
45
|
-
const
|
|
46
|
-
const
|
|
45
|
+
const propName1 = getPropAccessNotation(prop);
|
|
46
|
+
const propName2 = JSON.stringify(prop);
|
|
47
|
+
const varName = `pageContext${propName1}`;
|
|
47
48
|
try {
|
|
48
49
|
serialize(pageContext[prop], varName);
|
|
49
50
|
}
|
|
50
51
|
catch (err) {
|
|
51
52
|
hasWarned = true;
|
|
52
53
|
propsNonSerializable.push(prop);
|
|
54
|
+
// useConfig() wrong usage
|
|
55
|
+
if (prop === '_configFromHook') {
|
|
56
|
+
let pathString = '';
|
|
57
|
+
if (isJsonSerializerError(err)) {
|
|
58
|
+
pathString = err.pathString;
|
|
59
|
+
}
|
|
60
|
+
assertUsage(false, `Cannot serialize config ${h(pathString)} set by useConfig(), see https://vike.dev/useConfig#serialization-error`);
|
|
61
|
+
}
|
|
62
|
+
// Non-serializable pageContext set by the user
|
|
53
63
|
let msg = [
|
|
54
|
-
`${varName}
|
|
55
|
-
`Make sure
|
|
64
|
+
`${h(varName)} can't be serialized and, therefore, can't be passed to the client side.`,
|
|
65
|
+
`Make sure ${h(varName)} is serializable, or remove ${h(propName2)} from ${h('passToClient')}.`
|
|
56
66
|
].join(' ');
|
|
57
67
|
if (isJsonSerializerError(err)) {
|
|
58
68
|
msg = `${msg} Serialization error: ${err.messageCore}.`;
|
|
@@ -23,7 +23,7 @@ async function executeOnRenderHtmlHook(pageContext) {
|
|
|
23
23
|
const onErrorWhileStreaming = (err) => {
|
|
24
24
|
// Should the stream inject the following?
|
|
25
25
|
// ```
|
|
26
|
-
// <script>console.error("An error occurred on the server while streaming the
|
|
26
|
+
// <script>console.error("An error occurred on the server side while streaming the page to HTML, see server logs.")</script>
|
|
27
27
|
// ```
|
|
28
28
|
logRuntimeError(err, pageContext._httpRequestId);
|
|
29
29
|
if (!pageContext.errorWhileRendering) {
|
|
@@ -34,6 +34,7 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
// https://github.com/vikejs/vike/issues/401
|
|
37
|
+
// WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L28
|
|
37
38
|
src = src + '?direct';
|
|
38
39
|
}
|
|
39
40
|
const isEntry = clientEntriesSrc.includes(src) ||
|
|
@@ -241,8 +241,7 @@ function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
|
241
241
|
logRuntimeInfo?.(msg, httpRequestId, isNominal ? 'info' : 'error');
|
|
242
242
|
}
|
|
243
243
|
function getPageContextHttpResponseNullWithError(err, pageContextInit) {
|
|
244
|
-
const pageContextHttpResponseNull =
|
|
245
|
-
objectAssign(pageContextHttpResponseNull, pageContextInit);
|
|
244
|
+
const pageContextHttpResponseNull = createPageContext(pageContextInit);
|
|
246
245
|
objectAssign(pageContextHttpResponseNull, {
|
|
247
246
|
httpResponse: null,
|
|
248
247
|
errorWhileRendering: err
|
|
@@ -250,14 +249,20 @@ function getPageContextHttpResponseNullWithError(err, pageContextInit) {
|
|
|
250
249
|
return pageContextHttpResponseNull;
|
|
251
250
|
}
|
|
252
251
|
function getPageContextHttpResponseNull(pageContextInit) {
|
|
253
|
-
const pageContextHttpResponseNull =
|
|
254
|
-
objectAssign(pageContextHttpResponseNull, pageContextInit);
|
|
252
|
+
const pageContextHttpResponseNull = createPageContext(pageContextInit);
|
|
255
253
|
objectAssign(pageContextHttpResponseNull, {
|
|
256
254
|
httpResponse: null,
|
|
257
255
|
errorWhileRendering: null
|
|
258
256
|
});
|
|
259
257
|
return pageContextHttpResponseNull;
|
|
260
258
|
}
|
|
259
|
+
function createPageContext(pageContextInit) {
|
|
260
|
+
const pageContext = {
|
|
261
|
+
_isPageContextObject: true
|
|
262
|
+
};
|
|
263
|
+
Object.assign(pageContext, pageContextInit);
|
|
264
|
+
return pageContext;
|
|
265
|
+
}
|
|
261
266
|
async function renderPageNominal(pageContext) {
|
|
262
267
|
objectAssign(pageContext, { errorWhileRendering: null });
|
|
263
268
|
// Route
|
|
@@ -341,8 +346,7 @@ function normalizeUrl(pageContextInit, httpRequestId) {
|
|
|
341
346
|
return null;
|
|
342
347
|
logRuntimeInfo?.(`URL normalized from ${pc.cyan(urlOriginal)} to ${pc.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
343
348
|
const httpResponse = createHttpResponseObjectRedirect({ url: urlNormalized, statusCode: 301 }, pageContextInit.urlOriginal);
|
|
344
|
-
const pageContextHttpResponse =
|
|
345
|
-
objectAssign(pageContextHttpResponse, pageContextInit);
|
|
349
|
+
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
346
350
|
objectAssign(pageContextHttpResponse, { httpResponse });
|
|
347
351
|
return pageContextHttpResponse;
|
|
348
352
|
}
|
|
@@ -378,8 +382,7 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
|
378
382
|
}
|
|
379
383
|
logRuntimeInfo?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
380
384
|
const httpResponse = createHttpResponseObjectRedirect({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
|
|
381
|
-
const pageContextHttpResponse =
|
|
382
|
-
objectAssign(pageContextHttpResponse, pageContextInit);
|
|
385
|
+
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
383
386
|
objectAssign(pageContextHttpResponse, { httpResponse });
|
|
384
387
|
return pageContextHttpResponse;
|
|
385
388
|
}
|
|
@@ -395,9 +398,8 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
395
398
|
const abortCall = pageContextAbort._abortCall;
|
|
396
399
|
assert(abortCall);
|
|
397
400
|
assertUsage(errorPageId, `You called ${pc.cyan(abortCall)} but you didn't define an error page, make sure to define one https://vike.dev/error-page`);
|
|
398
|
-
const pageContext = {
|
|
399
|
-
|
|
400
|
-
};
|
|
401
|
+
const pageContext = createPageContext({});
|
|
402
|
+
objectAssign(pageContext, { _pageId: errorPageId });
|
|
401
403
|
objectAssign(pageContext, pageContextAbort);
|
|
402
404
|
objectAssign(pageContext, pageContextErrorPageInit);
|
|
403
405
|
objectAssign(pageContext, renderContext);
|
|
@@ -421,8 +423,7 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
421
423
|
return { pageContextReturn };
|
|
422
424
|
}
|
|
423
425
|
if (pageContextAbort._urlRedirect) {
|
|
424
|
-
const pageContextReturn =
|
|
425
|
-
objectAssign(pageContextReturn, pageContextInit);
|
|
426
|
+
const pageContextReturn = createPageContext(pageContextInit);
|
|
426
427
|
objectAssign(pageContextReturn, pageContextAbort);
|
|
427
428
|
const httpResponse = createHttpResponseObjectRedirect(pageContextAbort._urlRedirect, (() => {
|
|
428
429
|
const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
|
|
@@ -30,4 +30,4 @@ type RouteMatch = {
|
|
|
30
30
|
routeParams: Record<string, string>;
|
|
31
31
|
};
|
|
32
32
|
type RouteMatches = 'CUSTOM_ROUTING' | RouteMatch[];
|
|
33
|
-
declare function route(
|
|
33
|
+
declare function route(pageContext: PageContextForRoute): Promise<PageContextFromRoute>;
|
|
@@ -13,12 +13,12 @@ import { resolveRouteFunction } from './resolveRouteFunction.js';
|
|
|
13
13
|
import { executeOnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
|
|
14
14
|
import { debug } from './debug.js';
|
|
15
15
|
import pc from '@brillout/picocolors';
|
|
16
|
-
async function route(
|
|
17
|
-
debug('Pages routes:',
|
|
18
|
-
assertPageContextUrl(
|
|
16
|
+
async function route(pageContext) {
|
|
17
|
+
debug('Pages routes:', pageContext._pageRoutes);
|
|
18
|
+
assertPageContextUrl(pageContext);
|
|
19
19
|
const pageContextFromRoute = {};
|
|
20
20
|
// onBeforeRoute()
|
|
21
|
-
const pageContextFromOnBeforeRouteHook = await executeOnBeforeRouteHook(
|
|
21
|
+
const pageContextFromOnBeforeRouteHook = await executeOnBeforeRouteHook(pageContext);
|
|
22
22
|
if (pageContextFromOnBeforeRouteHook) {
|
|
23
23
|
if (pageContextFromOnBeforeRouteHook._routingProvidedByOnBeforeRouteHook) {
|
|
24
24
|
assert(pageContextFromOnBeforeRouteHook._pageId);
|
|
@@ -29,8 +29,6 @@ async function route(pageContextForRoute) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
// We take into account pageContext.urlLogical set by onBeforeRoute()
|
|
32
|
-
const pageContext = {};
|
|
33
|
-
objectAssign(pageContext, pageContextForRoute);
|
|
34
32
|
objectAssign(pageContext, pageContextFromOnBeforeRouteHook);
|
|
35
33
|
// Vike's routing
|
|
36
34
|
const allPageIds = pageContext._allPageIds;
|
|
@@ -120,7 +120,7 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
120
120
|
pageExports: Record<string, unknown>;
|
|
121
121
|
};
|
|
122
122
|
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlServer;
|
|
123
|
-
type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data' | 'source' | 'sources' | 'from'> & {
|
|
123
|
+
type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'routeParams' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data' | 'source' | 'sources' | 'from'> & {
|
|
124
124
|
/** Whether the current page is already rendered to HTML */
|
|
125
125
|
isHydration: boolean;
|
|
126
126
|
/**
|
package/dist/esm/utils/assert.js
CHANGED
|
@@ -8,7 +8,7 @@ export { getAssertErrMsg };
|
|
|
8
8
|
export { overwriteAssertProductionLogger };
|
|
9
9
|
export { isBug };
|
|
10
10
|
export { setAlwaysShowStackTrace };
|
|
11
|
-
import {
|
|
11
|
+
import { assertSingleInstance_onAssertModuleLoad } from './assertSingleInstance.js';
|
|
12
12
|
import { createErrorWithCleanStackTrace } from './createErrorWithCleanStackTrace.js';
|
|
13
13
|
import { getGlobalObject } from './getGlobalObject.js';
|
|
14
14
|
import { isObject } from './isObject.js';
|
|
@@ -27,7 +27,7 @@ const globalObject = getGlobalObject('utils/assert.ts', {
|
|
|
27
27
|
},
|
|
28
28
|
showStackTraceList: new WeakSet()
|
|
29
29
|
});
|
|
30
|
-
|
|
30
|
+
assertSingleInstance_onAssertModuleLoad();
|
|
31
31
|
const projectTag = `[vike]`;
|
|
32
32
|
const projectTagWithVersion = `[vike@${projectInfo.projectVersion}]`;
|
|
33
33
|
const numberOfStackTraceLinesToRemove = 2;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
1
|
+
export { assertSingleInstance_onClientEntryServerRouting };
|
|
2
|
+
export { assertSingleInstance_onClientEntryClientRouting };
|
|
3
|
+
export { assertSingleInstance_onAssertModuleLoad };
|
|
4
|
+
declare function assertSingleInstance_onClientEntryServerRouting(isProduction: boolean): void;
|
|
5
|
+
declare function assertSingleInstance_onClientEntryClientRouting(isProduction: boolean): void;
|
|
6
|
+
declare function assertSingleInstance_onAssertModuleLoad(): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { assertSingleInstance_onClientEntryServerRouting };
|
|
2
|
+
export { assertSingleInstance_onClientEntryClientRouting };
|
|
3
|
+
export { assertSingleInstance_onAssertModuleLoad };
|
|
4
4
|
// - Throw error if there are two different versions of vike loaded
|
|
5
5
|
// - Show warning if entry of Client Routing and entry of Server Routing are both loaded
|
|
6
6
|
// - Show warning if vike is loaded twice
|
|
@@ -32,7 +32,7 @@ function assertSingleInstance() {
|
|
|
32
32
|
//*/
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function assertSingleInstance_onClientEntryServerRouting(isProduction) {
|
|
36
36
|
assertWarning(globalObject.isClientRouting !== true, clientRuntimesClonflict, {
|
|
37
37
|
onlyOnce: true,
|
|
38
38
|
showStackTrace: true
|
|
@@ -46,7 +46,7 @@ function onClientEntry_ServerRouting(isProduction) {
|
|
|
46
46
|
globalObject.checkSingleInstance = true;
|
|
47
47
|
assertSingleInstance();
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function assertSingleInstance_onClientEntryClientRouting(isProduction) {
|
|
50
50
|
assertWarning(globalObject.isClientRouting !== false, clientRuntimesClonflict, {
|
|
51
51
|
onlyOnce: true,
|
|
52
52
|
showStackTrace: true
|
|
@@ -61,7 +61,7 @@ function onClientEntry_ClientRouting(isProduction) {
|
|
|
61
61
|
assertSingleInstance();
|
|
62
62
|
}
|
|
63
63
|
// Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
|
|
64
|
-
function
|
|
64
|
+
function assertSingleInstance_onAssertModuleLoad() {
|
|
65
65
|
globalObject.instances.push(projectInfo.projectVersion);
|
|
66
66
|
assertSingleInstance();
|
|
67
67
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export function getPropAccessNotation(key) {
|
|
2
|
-
return typeof key === 'string' &&
|
|
2
|
+
return typeof key === 'string' && isKeyDotNotationCompatible(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
3
|
+
}
|
|
4
|
+
function isKeyDotNotationCompatible(key) {
|
|
5
|
+
return /^[a-z0-9\$_]+$/i.test(key);
|
|
3
6
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { objectAssign };
|
|
2
|
-
declare function objectAssign<Obj extends object, ObjAddendum>(obj: Obj, objAddendum: ObjAddendum): asserts obj is Obj & ObjAddendum;
|
|
2
|
+
declare function objectAssign<Obj extends object, ObjAddendum extends object | null>(obj: Obj, objAddendum: ObjAddendum): asserts obj is Obj & ObjAddendum;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { objectAssign };
|
|
2
|
+
import { assert } from './assert.js';
|
|
2
3
|
// Same as Object.assign() but:
|
|
3
4
|
// - With type inference
|
|
4
5
|
// - Preserves property descriptors, which we need for preserving the getters added by getPageContextUrlComputed()
|
|
5
6
|
function objectAssign(obj, objAddendum) {
|
|
6
7
|
if (objAddendum) {
|
|
8
|
+
assert(!('_isPageContextObject' in objAddendum));
|
|
7
9
|
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
8
10
|
}
|
|
9
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.179-commit-9384166";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.
|
|
6
|
+
projectVersion: "0.4.179-commit-9384166";
|
|
7
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.179-commit-9384166",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@brillout/import": "^0.2.3",
|
|
17
|
-
"@brillout/json-serializer": "^0.5.
|
|
17
|
+
"@brillout/json-serializer": "^0.5.13",
|
|
18
18
|
"@brillout/picocolors": "^1.0.13",
|
|
19
19
|
"@brillout/require-shim": "^0.1.2",
|
|
20
20
|
"@brillout/vite-plugin-server-entry": "^0.4.5",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
"peerDependencies": {
|
|
141
|
-
"react-streaming": ">=0.3.
|
|
141
|
+
"react-streaming": ">=0.3.42",
|
|
142
142
|
"vite": ">=4.4.0"
|
|
143
143
|
},
|
|
144
144
|
"peerDependenciesMeta": {
|
|
@@ -209,7 +209,7 @@
|
|
|
209
209
|
"es-module-lexer": "^1.4.1",
|
|
210
210
|
"esbuild": "^0.19.10",
|
|
211
211
|
"fast-glob": "^3.3.2",
|
|
212
|
-
"react-streaming": "^0.3.
|
|
212
|
+
"react-streaming": "^0.3.42",
|
|
213
213
|
"rimraf": "^5.0.5",
|
|
214
214
|
"sirv": "^2.0.4",
|
|
215
215
|
"source-map-support": "^0.5.21",
|