vike 0.4.193 → 0.4.195
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/RenderErrorPage.js +1 -0
- package/__internal/setup.js +1 -0
- package/__internal.js +1 -0
- package/abort.js +1 -0
- package/cli.js +1 -0
- package/client/router.js +1 -0
- package/client.js +1 -0
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +2 -2
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +4 -9
- package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +1 -13
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -24
- package/dist/cjs/node/plugin/shared/loggerVite.js +0 -3
- package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +2 -2
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +17 -12
- package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/html/injectAssets.js +2 -2
- package/dist/cjs/node/runtime/renderPage/assertArguments.js +3 -3
- package/dist/cjs/node/runtime/renderPage/{createHttpResponseObject.js → createHttpResponse.js} +22 -15
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -5
- package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +4 -3
- package/dist/cjs/node/runtime/renderPage/inferMediaType.js +3 -0
- package/dist/cjs/node/runtime/renderPage/isConfigInvalid.js +4 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -12
- package/dist/cjs/node/runtime/renderPage.js +62 -66
- package/dist/cjs/shared/page-configs/assertPlusFileExport.js +1 -2
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isArray.js +1 -1
- package/dist/cjs/utils/parseUrl-extras.js +6 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +5 -5
- package/dist/esm/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +2 -2
- package/dist/esm/node/plugin/shared/addSsrMiddleware.js +4 -9
- package/dist/esm/node/plugin/shared/loggerNotProd/log.d.ts +0 -7
- package/dist/esm/node/plugin/shared/loggerNotProd/log.js +0 -12
- package/dist/esm/node/plugin/shared/loggerNotProd.d.ts +1 -7
- package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -24
- package/dist/esm/node/plugin/shared/loggerVite.js +1 -4
- package/dist/esm/node/runtime/globalContext/loadImportBuild.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +17 -12
- package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets.js +2 -2
- package/dist/esm/node/runtime/renderPage/assertArguments.js +3 -3
- package/dist/esm/node/runtime/renderPage/{createHttpResponseObject.d.ts → createHttpResponse.d.ts} +9 -5
- package/dist/esm/node/runtime/renderPage/{createHttpResponseObject.js → createHttpResponse.js} +21 -14
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -5
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +4 -3
- package/dist/esm/node/runtime/renderPage/inferMediaType.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/inferMediaType.js +3 -0
- package/dist/esm/node/runtime/renderPage/isConfigInvalid.d.ts +6 -2
- package/dist/esm/node/runtime/renderPage/isConfigInvalid.js +6 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -11
- package/dist/esm/node/runtime/renderPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage.js +62 -66
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/assertPlusFileExport.js +1 -2
- package/dist/esm/shared/route/abort.d.ts +3 -3
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isArray.js +1 -1
- package/dist/esm/utils/parseUrl-extras.d.ts +2 -0
- package/dist/esm/utils/parseUrl-extras.js +5 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +66 -66
- package/plugin.js +1 -0
- package/prerender.js +1 -0
- package/routing.js +1 -0
- package/server.js +1 -0
- /package/dist/cjs/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/assertNoInfiniteHttpRedirect.js +0 -0
- /package/dist/cjs/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/getCacheControl.js +0 -0
- /package/dist/esm/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/assertNoInfiniteHttpRedirect.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/assertNoInfiniteHttpRedirect.js +0 -0
- /package/dist/esm/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/getCacheControl.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/getCacheControl.js +0 -0
package/RenderErrorPage.js
CHANGED
package/__internal/setup.js
CHANGED
package/__internal.js
CHANGED
package/abort.js
CHANGED
package/cli.js
CHANGED
package/client/router.js
CHANGED
package/client.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.set_ASSETS_MAP = exports.importBuild = void 0;
|
|
7
|
-
const
|
|
7
|
+
const plugin_1 = require("@brillout/vite-plugin-server-entry/plugin");
|
|
8
8
|
const utils_js_1 = require("../../utils.js");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const module_1 = require("module");
|
|
@@ -28,7 +28,7 @@ function importBuild() {
|
|
|
28
28
|
configVike = await (0, getConfigVike_js_1.getConfigVike)(config);
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
-
...(0,
|
|
31
|
+
...(0, plugin_1.serverEntryPlugin)({
|
|
32
32
|
getImporterCode: () => {
|
|
33
33
|
return getEntryCode(config, configVike);
|
|
34
34
|
},
|
|
@@ -99,17 +99,13 @@ function handleHotUpdate(ctx, config) {
|
|
|
99
99
|
`${msg} — ${pc.cyan('no HMR')}, see https://vike.dev/on-demand-compiler`,
|
|
100
100
|
'info',
|
|
101
101
|
null,
|
|
102
|
-
true
|
|
103
|
-
clear,
|
|
104
|
-
config
|
|
102
|
+
true
|
|
105
103
|
)
|
|
106
104
|
return
|
|
107
105
|
}
|
|
108
106
|
//*/
|
|
109
|
-
// HMR can resolve errors => we clear previously shown errors.
|
|
110
107
|
// It can hide an error it shouldn't hide (because the error isn't shown again), but it's ok since users can reload the page and the error will be shown again (Vite transpilation errors are shown again upon a page reload).
|
|
111
108
|
if (!isVikeConfig && isViteModule) {
|
|
112
|
-
(0, loggerNotProd_js_1.clearLogs)({ clearErrors: true });
|
|
113
109
|
return;
|
|
114
110
|
}
|
|
115
111
|
if (isVikeConfig) {
|
|
@@ -37,7 +37,7 @@ function reloadVikeConfig(userRootDir, outDirRoot) {
|
|
|
37
37
|
}
|
|
38
38
|
exports.reloadVikeConfig = reloadVikeConfig;
|
|
39
39
|
async function handleReloadSideEffects() {
|
|
40
|
-
wasConfigInvalid = isConfigInvalid_js_1.isConfigInvalid;
|
|
40
|
+
wasConfigInvalid = !!isConfigInvalid_js_1.isConfigInvalid;
|
|
41
41
|
const vikeConfigPromisePrevious = vikeConfigPromise;
|
|
42
42
|
try {
|
|
43
43
|
await vikeConfigPromise;
|
|
@@ -214,7 +214,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
|
|
|
214
214
|
else {
|
|
215
215
|
(0, utils_js_1.assert)(ret === undefined);
|
|
216
216
|
(0, utils_js_1.assert)(err);
|
|
217
|
-
(0, isConfigInvalid_js_1.isConfigInvalid_set)(
|
|
217
|
+
(0, isConfigInvalid_js_1.isConfigInvalid_set)({ err });
|
|
218
218
|
if (!isDev) {
|
|
219
219
|
(0, utils_js_1.assert)((0, globalContext_js_1.getViteDevServer)() === null);
|
|
220
220
|
throw err;
|
|
@@ -48,15 +48,10 @@ function addSsrMiddleware(middlewares, config, isPreview) {
|
|
|
48
48
|
if (value)
|
|
49
49
|
res.setHeader(name, value);
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const { statusCode, headers } = pageContext.httpResponse;
|
|
56
|
-
headers.forEach(([name, value]) => res.setHeader(name, value));
|
|
57
|
-
res.statusCode = statusCode;
|
|
58
|
-
pageContext.httpResponse.pipe(res);
|
|
59
|
-
}
|
|
51
|
+
const { httpResponse } = pageContext;
|
|
52
|
+
httpResponse.headers.forEach(([name, value]) => res.setHeader(name, value));
|
|
53
|
+
res.statusCode = httpResponse.statusCode;
|
|
54
|
+
httpResponse.pipe(res);
|
|
60
55
|
});
|
|
61
56
|
}
|
|
62
57
|
exports.addSsrMiddleware = addSsrMiddleware;
|
|
@@ -3,16 +3,12 @@ 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.applyViteSourceMapToStackTrace = exports.
|
|
6
|
+
exports.applyViteSourceMapToStackTrace = exports.logDirectly = exports.logWithVikeTag = exports.logWithViteTag = void 0;
|
|
7
7
|
const utils_js_1 = require("../../utils.js");
|
|
8
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
9
|
const isErrorDebug_js_1 = require("../../../shared/isErrorDebug.js");
|
|
10
10
|
const globalContext_js_1 = require("../../../runtime/globalContext.js");
|
|
11
11
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
12
|
-
let isFirstLog = true;
|
|
13
|
-
exports.isFirstLog = isFirstLog;
|
|
14
|
-
let screenHasErrors = false;
|
|
15
|
-
exports.screenHasErrors = screenHasErrors;
|
|
16
12
|
function logWithVikeTag(msg, logType, category, showVikeVersion = false) {
|
|
17
13
|
const projectTag = getProjectTag(showVikeVersion);
|
|
18
14
|
msg = prependTags(msg, projectTag, category, logType);
|
|
@@ -39,7 +35,6 @@ exports.logWithViteTag = logWithViteTag;
|
|
|
39
35
|
// - Production => logs aren't managed by loggerNotProd.ts => logDirectly() is never called (not even loaded as asserted by assertIsVitePluginCode())
|
|
40
36
|
function logDirectly(thing, logType) {
|
|
41
37
|
applyViteSourceMapToStackTrace(thing);
|
|
42
|
-
exports.isFirstLog = isFirstLog = false;
|
|
43
38
|
if (logType === 'info') {
|
|
44
39
|
console.log(thing);
|
|
45
40
|
return;
|
|
@@ -49,7 +44,6 @@ function logDirectly(thing, logType) {
|
|
|
49
44
|
return;
|
|
50
45
|
}
|
|
51
46
|
if (logType === 'error') {
|
|
52
|
-
exports.screenHasErrors = screenHasErrors = true;
|
|
53
47
|
console.error(thing);
|
|
54
48
|
return;
|
|
55
49
|
}
|
|
@@ -61,12 +55,6 @@ function logDirectly(thing, logType) {
|
|
|
61
55
|
(0, utils_js_1.assert)(false);
|
|
62
56
|
}
|
|
63
57
|
exports.logDirectly = logDirectly;
|
|
64
|
-
function clearScreen(viteConfig) {
|
|
65
|
-
// We use Vite's logger in order to respect the user's `clearScreen: false` setting
|
|
66
|
-
viteConfig.logger.clearScreen('error');
|
|
67
|
-
exports.screenHasErrors = screenHasErrors = false;
|
|
68
|
-
}
|
|
69
|
-
exports.clearScreen = clearScreen;
|
|
70
58
|
function applyViteSourceMapToStackTrace(thing) {
|
|
71
59
|
if ((0, isErrorDebug_js_1.isErrorDebug)())
|
|
72
60
|
return;
|
|
@@ -9,7 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.logErrorDebugNote = exports.logConfigErrorRecover = exports.logConfigError = exports.logConfigInfo = exports.logViteError = exports.logViteAny = void 0;
|
|
13
13
|
const abort_js_1 = require("../../../shared/route/abort.js");
|
|
14
14
|
const globalContext_js_1 = require("../../runtime/globalContext.js");
|
|
15
15
|
const loggerRuntime_js_1 = require("../../runtime/renderPage/loggerRuntime.js");
|
|
@@ -21,15 +21,12 @@ const transpileAndExecuteFile_js_1 = require("../plugins/importUserCode/v1-desig
|
|
|
21
21
|
const log_js_1 = require("./loggerNotProd/log.js");
|
|
22
22
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
23
23
|
const isNewError_js_1 = require("../../runtime/renderPage/isNewError.js");
|
|
24
|
-
const isConfigInvalid_js_1 = require("../../runtime/renderPage/isConfigInvalid.js");
|
|
25
24
|
const loggerProd_js_1 = require("../../runtime/renderPage/loggerProd.js");
|
|
26
25
|
const executeHook_js_1 = require("../../../shared/hooks/executeHook.js");
|
|
27
26
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
28
27
|
(0, loggerRuntime_js_1.overwriteRuntimeProductionLogger)(logRuntimeError, logRuntimeInfo);
|
|
29
28
|
(0, utils_js_1.overwriteAssertProductionLogger)(assertLogger);
|
|
30
|
-
function logRuntimeInfo(msg, httpRequestId, logType
|
|
31
|
-
if (clearErrors)
|
|
32
|
-
clearLogs({ clearErrors: true });
|
|
29
|
+
function logRuntimeInfo(msg, httpRequestId, logType) {
|
|
33
30
|
const category = getCategory(httpRequestId);
|
|
34
31
|
(0, utils_js_1.assert)(category);
|
|
35
32
|
(0, log_js_1.logWithVikeTag)(msg, logType, category);
|
|
@@ -51,7 +48,6 @@ function logConfigInfo(msg, logType) {
|
|
|
51
48
|
exports.logConfigInfo = logConfigInfo;
|
|
52
49
|
function logConfigErrorRecover() {
|
|
53
50
|
const msg = picocolors_1.default.bold(picocolors_1.default.green('Configuration successfully loaded'));
|
|
54
|
-
clearLogs({ clearAlsoIfConfigIsInvalid: true });
|
|
55
51
|
const category = getConfigCategory();
|
|
56
52
|
(0, log_js_1.logWithVikeTag)(msg, 'error-recover', category);
|
|
57
53
|
}
|
|
@@ -113,7 +109,6 @@ function logErr(err, httpRequestId = null, errorComesFromVite) {
|
|
|
113
109
|
(0, loggerProd_js_1.onRuntimeError)(err);
|
|
114
110
|
}
|
|
115
111
|
function logConfigError(err) {
|
|
116
|
-
clearLogs({ clearAlsoIfConfigIsInvalid: true });
|
|
117
112
|
(0, utils_js_1.warnIfErrorIsNotObject)(err);
|
|
118
113
|
const category = getConfigCategory();
|
|
119
114
|
{
|
|
@@ -177,23 +172,6 @@ function assertLogger(thing, logType) {
|
|
|
177
172
|
const { assertMsg, showVikeVersion } = res;
|
|
178
173
|
(0, log_js_1.logWithVikeTag)(assertMsg, logType, category, showVikeVersion);
|
|
179
174
|
}
|
|
180
|
-
function clearLogs(conditions = {}) {
|
|
181
|
-
if (!conditions.clearAlsoIfConfigIsInvalid && isConfigInvalid_js_1.isConfigInvalid) {
|
|
182
|
-
// Avoid hiding the config error: the config error is printed only once
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (conditions.clearErrors && !log_js_1.screenHasErrors) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (conditions.clearIfFirstLog && !log_js_1.isFirstLog) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
const viteConfig = (0, globalContext_js_1.getViteConfig)();
|
|
192
|
-
if (viteConfig) {
|
|
193
|
-
(0, log_js_1.clearScreen)(viteConfig);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
exports.clearLogs = clearLogs;
|
|
197
175
|
/** Note shown to user when vike does something risky:
|
|
198
176
|
* - When vike dedupes (i.e. swallows) an error with getHttpRequestAsyncStore().shouldErrorBeSwallowed(err)
|
|
199
177
|
* - When vike modifies the error with getPrettyErrorWithCodeSnippet(err)
|
|
@@ -39,9 +39,6 @@ function intercept(logType, config) {
|
|
|
39
39
|
(0, utils_js_1.assert)(!(0, isErrorDebug_js_1.isErrorDebug)());
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
// Only allow Vite to clear for its first log. All other clearing is controlled by vike.
|
|
43
|
-
if (options.clear)
|
|
44
|
-
(0, loggerNotProd_js_1.clearLogs)({ clearIfFirstLog: true });
|
|
45
42
|
// Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
|
|
46
43
|
const prependViteTag = options.timestamp || !!store?.httpRequestId;
|
|
47
44
|
(0, loggerNotProd_js_1.logViteAny)(msg, logType, store?.httpRequestId ?? null, prependViteTag);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setImportBuildGetters = exports.loadImportBuild = void 0;
|
|
4
|
-
const
|
|
4
|
+
const runtime_1 = require("@brillout/vite-plugin-server-entry/runtime");
|
|
5
5
|
const utils_js_1 = require("../utils.js");
|
|
6
6
|
const buildGetters = (globalThis.__vike_buildGetters = globalThis.__vike_buildGetters || {
|
|
7
7
|
getters: null
|
|
@@ -12,7 +12,7 @@ function setImportBuildGetters(getters) {
|
|
|
12
12
|
exports.setImportBuildGetters = setImportBuildGetters;
|
|
13
13
|
async function loadImportBuild(outDir) {
|
|
14
14
|
if (!buildGetters.getters) {
|
|
15
|
-
await (0,
|
|
15
|
+
await (0, runtime_1.importServerEntry)(outDir);
|
|
16
16
|
(0, utils_js_1.assert)(buildGetters.getters);
|
|
17
17
|
}
|
|
18
18
|
const [pageFiles, assetsManifest, pluginManifest] = await Promise.all([
|
|
@@ -25,7 +25,7 @@ function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter,
|
|
|
25
25
|
if (asset.isEntry && asset.assetType === 'script') {
|
|
26
26
|
// We could allow the user to change the position of <script> but we currently don't:
|
|
27
27
|
// - Because of mergeScriptEntries()
|
|
28
|
-
// - We would need to add
|
|
28
|
+
// - We would need to add HTML_STREAM to to PreloadFilterInject
|
|
29
29
|
// To suppor this, we should add the JavaScript entry to injectFilterEntries (with an `src` value of `null`)
|
|
30
30
|
return false;
|
|
31
31
|
}
|
|
@@ -82,31 +82,36 @@ function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter,
|
|
|
82
82
|
// ==========
|
|
83
83
|
// JavaScript
|
|
84
84
|
// ==========
|
|
85
|
-
// -
|
|
85
|
+
// - By default, we place the entry <script> towards the end of the HTML for better performance.
|
|
86
|
+
// - Performance-wise, it's more interesting to start showing the page (parse HTML and load CSS) before starting loading scripts.
|
|
87
|
+
// - But with HTML streaming, in order to support [Progressive Rendering](https://vike.dev/streaming#progressive-rendering), the entry <script> should be injected earlier instead.
|
|
88
|
+
// - The entry <script> shouldn't be `<script defer>` upon HTML streaming, otherwise progressive hydration while SSR streaming won't work.
|
|
89
|
+
// - `<script id="vike_pageContext" type="application/json">` (the `pageContext` JSON) should be fully sent before Vike's client runtime starts executing.
|
|
86
90
|
// - Otherwise, race condition "SyntaxError: Unterminated string in JSON": https://github.com/vikejs/vike/issues/567
|
|
87
|
-
// -
|
|
88
|
-
// -
|
|
89
|
-
|
|
90
|
-
// - The entry <script> should be towards the end of the HTML as performance-wise it's more interesting to parse <div id="page-view"> before running the entry <script> which initiates the hydration.
|
|
91
|
-
// - But with HTML streaming, in order to support [Progressive Rendering](https://vike.dev/streaming#progressive-rendering), the entry <script> should be injected early instead.
|
|
91
|
+
// - `<script id="vike_pageContext" type="application/json">` must appear before the entry <script> (which loads Vike's client runtime).
|
|
92
|
+
// - `<script id="vike_pageContext" type="application/json">` can't be async nor defer.
|
|
93
|
+
const positionJavaScriptDefault = 'HTML_END';
|
|
92
94
|
const positionJavaScriptEntry = (() => {
|
|
93
95
|
if (injectScriptsAt !== null) {
|
|
94
96
|
if (pageContext._pageContextPromise) {
|
|
95
97
|
(0, utils_js_1.assertWarning)(injectScriptsAt === 'HTML_END' || !isStream, `You're setting injectScriptsAt to ${picocolors_1.default.code(JSON.stringify(injectScriptsAt))} while using HTML streaming with a pageContext promise (https://vike.dev/streaming#initial-data-after-stream-end) which is contradictory: the pageContext promise is skipped.`, { onlyOnce: true });
|
|
96
98
|
}
|
|
99
|
+
if (injectScriptsAt === 'HTML_STREAM' && !isStream) {
|
|
100
|
+
return positionJavaScriptDefault;
|
|
101
|
+
}
|
|
97
102
|
return injectScriptsAt;
|
|
98
103
|
}
|
|
99
104
|
if (pageContext._pageContextPromise) {
|
|
100
105
|
// - If there is a pageContext._pageContextPromise then <script id="vike_pageContext" type="application/json"> needs to await for it.
|
|
101
106
|
// - pageContext._pageContextPromise is typically resolved only after the page's components are rendered and the stream ended.
|
|
102
107
|
// - https://vike.dev/streaming#initial-data-after-stream-end
|
|
103
|
-
return
|
|
108
|
+
return positionJavaScriptDefault;
|
|
104
109
|
}
|
|
105
110
|
if (streamFromReactStreamingPackage && !streamFromReactStreamingPackage.hasStreamEnded()) {
|
|
106
111
|
// If there is a stream then, in order to support progressive hydration, inject the JavaScript during the stream after React(/Vue/Solid/...) resolved the first suspense boundary.
|
|
107
|
-
return '
|
|
112
|
+
return 'HTML_STREAM';
|
|
108
113
|
}
|
|
109
|
-
return
|
|
114
|
+
return positionJavaScriptDefault;
|
|
110
115
|
})();
|
|
111
116
|
if (pageContext._pageContextPromise && streamFromReactStreamingPackage) {
|
|
112
117
|
// - Should we show this warning for Solid as well? Solid seems to also support progressive rendering.
|
|
@@ -140,7 +145,7 @@ function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter,
|
|
|
140
145
|
const htmlTag = (0, inferHtmlTags_js_1.inferPreloadTag)(asset);
|
|
141
146
|
if (!asset.inject)
|
|
142
147
|
return;
|
|
143
|
-
// Ideally, instead of this conditional ternary operator, we should add
|
|
148
|
+
// Ideally, instead of this conditional ternary operator, we should add HTML_STREAM to PreloadFilterInject
|
|
144
149
|
const position = asset.inject === 'HTML_END' ? positionJavaScriptEntry : asset.inject;
|
|
145
150
|
htmlTags.push({ htmlTag, position });
|
|
146
151
|
});
|
|
@@ -223,6 +228,6 @@ function getInjectScriptsAt(pageId, pageConfigs) {
|
|
|
223
228
|
(0, utils_js_1.assertUsage)(injectScriptsAt === null ||
|
|
224
229
|
injectScriptsAt === 'HTML_BEGIN' ||
|
|
225
230
|
injectScriptsAt === 'HTML_END' ||
|
|
226
|
-
injectScriptsAt === '
|
|
231
|
+
injectScriptsAt === 'HTML_STREAM', `${configDefinedAt} has an invalid value`);
|
|
227
232
|
return injectScriptsAt;
|
|
228
233
|
}
|
|
@@ -13,7 +13,7 @@ function injectHtmlTags(htmlString, htmlTags, position) {
|
|
|
13
13
|
exports.injectHtmlTags = injectHtmlTags;
|
|
14
14
|
// Is it worth it? Should we remove this? https://github.com/vikejs/vike/pull/1740#issuecomment-2230540892
|
|
15
15
|
function injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage) {
|
|
16
|
-
const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === '
|
|
16
|
+
const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === 'HTML_STREAM'));
|
|
17
17
|
if (htmlFragment) {
|
|
18
18
|
(0, utils_js_1.assert)(!streamFromReactStreamingPackage.hasStreamEnded());
|
|
19
19
|
streamFromReactStreamingPackage.injectToStream(htmlFragment, { flush: true });
|
|
@@ -13,7 +13,7 @@ async function injectHtmlTagsToString(htmlParts, pageContext, injectFilter) {
|
|
|
13
13
|
let htmlString = htmlPartsToString(htmlParts, pageAssets);
|
|
14
14
|
htmlString = injectToHtmlBegin(htmlString, htmlTags);
|
|
15
15
|
htmlString = injectToHtmlEnd(htmlString, htmlTags);
|
|
16
|
-
(0, utils_js_1.assert)(htmlTags.filter((snippet) => snippet.position === '
|
|
16
|
+
(0, utils_js_1.assert)(htmlTags.filter((snippet) => snippet.position === 'HTML_STREAM').length === 0);
|
|
17
17
|
return htmlString;
|
|
18
18
|
}
|
|
19
19
|
exports.injectHtmlTagsToString = injectHtmlTagsToString;
|
|
@@ -41,7 +41,7 @@ function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, in
|
|
|
41
41
|
if (streamFromReactStreamingPackage)
|
|
42
42
|
return null;
|
|
43
43
|
(0, utils_js_1.assert)(htmlTags);
|
|
44
|
-
const tags = htmlTags.filter((h) => h.position === '
|
|
44
|
+
const tags = htmlTags.filter((h) => h.position === 'HTML_STREAM');
|
|
45
45
|
if (tags.length === 0)
|
|
46
46
|
return null;
|
|
47
47
|
const htmlFragment = (0, injectHtmlTags_js_1.joinHtmlTags)(tags);
|
|
@@ -7,14 +7,14 @@ exports.assertArguments = void 0;
|
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
9
|
function assertArguments(...args) {
|
|
10
|
-
const prefix =
|
|
10
|
+
const prefix = `${picocolors_1.default.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage)`;
|
|
11
11
|
const pageContextInit = args[0];
|
|
12
12
|
(0, utils_js_1.assertUsage)(pageContextInit !== undefined && pageContextInit !== null, prefix + ` argument ${picocolors_1.default.cyan('pageContextInit')} is missing`, { showStackTrace: true });
|
|
13
13
|
const len = args.length;
|
|
14
|
-
(0, utils_js_1.assertUsage)(len === 1, `${prefix}
|
|
14
|
+
(0, utils_js_1.assertUsage)(len === 1, `${prefix} called with ${len} arguments but renderPage() accepts only one argument.'`, {
|
|
15
15
|
showStackTrace: true
|
|
16
16
|
});
|
|
17
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(pageContextInit), `${prefix}
|
|
17
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(pageContextInit), `${prefix} called with ${picocolors_1.default.code(`typeof pageContextInit === ${JSON.stringify(typeof pageContextInit)}`)} but ${picocolors_1.default.code('pageContextInit')} should be an object.`, { showStackTrace: true });
|
|
18
18
|
// TODO/v1-release: remove
|
|
19
19
|
if ('url' in pageContextInit) {
|
|
20
20
|
(0, utils_js_1.assertWarning)(false, '`pageContextInit.url` has been renamed to `pageContextInit.urlOriginal`: replace `renderPage({ url })` with `renderPage({ urlOriginal })`. (See https://vike.dev/migration/0.4.23 for more information.)', { showStackTrace: true, onlyOnce: true });
|
package/dist/cjs/node/runtime/renderPage/{createHttpResponseObject.js → createHttpResponse.js}
RENAMED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createHttpResponseFavicon404 = exports.createHttpResponseRedirect = exports.createHttpResponseError = exports.createHttpResponsePageContextJson = exports.createHttpResponsePage = void 0;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
5
|
const error_page_js_1 = require("../../../shared/error-page.js");
|
|
6
6
|
const getHttpResponseBody_js_1 = require("./getHttpResponseBody.js");
|
|
7
7
|
const getEarlyHints_js_1 = require("./getEarlyHints.js");
|
|
8
|
-
const getCacheControl_js_1 = require("./
|
|
9
|
-
const assertNoInfiniteHttpRedirect_js_1 = require("./
|
|
10
|
-
async function
|
|
11
|
-
if (htmlRender === null) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
8
|
+
const getCacheControl_js_1 = require("./createHttpResponse/getCacheControl.js");
|
|
9
|
+
const assertNoInfiniteHttpRedirect_js_1 = require("./createHttpResponse/assertNoInfiniteHttpRedirect.js");
|
|
10
|
+
async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
|
|
14
11
|
let statusCode = pageContext.abortStatusCode;
|
|
15
12
|
if (!statusCode) {
|
|
16
13
|
const isError = !pageContext._pageId || (0, error_page_js_1.isErrorPage)(pageContext._pageId, pageContext._pageConfigs);
|
|
@@ -33,15 +30,25 @@ async function createHttpResponseObject(htmlRender, renderHook, pageContext) {
|
|
|
33
30
|
if (cacheControl) {
|
|
34
31
|
headers.push(['Cache-Control', cacheControl]);
|
|
35
32
|
}
|
|
36
|
-
return
|
|
33
|
+
return createHttpResponse(statusCode, 'text/html;charset=utf-8', headers, htmlRender, earlyHints, renderHook);
|
|
34
|
+
}
|
|
35
|
+
exports.createHttpResponsePage = createHttpResponsePage;
|
|
36
|
+
function createHttpResponseFavicon404() {
|
|
37
|
+
const httpResponse = createHttpResponse(404, 'text/html;charset=utf-8', [], "<p>No favicon.ico found.</p><script>console.log('This HTTP response was generated by Vike.')</script>");
|
|
38
|
+
return httpResponse;
|
|
39
|
+
}
|
|
40
|
+
exports.createHttpResponseFavicon404 = createHttpResponseFavicon404;
|
|
41
|
+
function createHttpResponseError() {
|
|
42
|
+
const httpResponse = createHttpResponse(500, 'text/html;charset=utf-8', [], "<p>An error occurred.</p><script>console.log('This HTTP response was generated by Vike. This response is used instead of rendering the error page (https://vike.dev/error-page), either because there isn't error page or because an error occurred while rendering the error page.')</script>");
|
|
43
|
+
return httpResponse;
|
|
37
44
|
}
|
|
38
|
-
exports.
|
|
45
|
+
exports.createHttpResponseError = createHttpResponseError;
|
|
39
46
|
async function createHttpResponsePageContextJson(pageContextSerialized) {
|
|
40
|
-
const httpResponse =
|
|
47
|
+
const httpResponse = createHttpResponse(200, 'application/json', [], pageContextSerialized, [], null);
|
|
41
48
|
return httpResponse;
|
|
42
49
|
}
|
|
43
50
|
exports.createHttpResponsePageContextJson = createHttpResponsePageContextJson;
|
|
44
|
-
function
|
|
51
|
+
function createHttpResponseRedirect({ url, statusCode },
|
|
45
52
|
// The URL we assume the redirect to be logically based on
|
|
46
53
|
urlLogical) {
|
|
47
54
|
(0, assertNoInfiniteHttpRedirect_js_1.assertNoInfiniteHttpRedirect)(url, urlLogical);
|
|
@@ -49,13 +56,13 @@ urlLogical) {
|
|
|
49
56
|
(0, utils_js_1.assert)(statusCode);
|
|
50
57
|
(0, utils_js_1.assert)(300 <= statusCode && statusCode <= 399);
|
|
51
58
|
const headers = [['Location', url]];
|
|
52
|
-
return
|
|
59
|
+
return createHttpResponse(statusCode, 'text/html;charset=utf-8', headers,
|
|
53
60
|
// For bots / programmatic crawlig: show what's going on.
|
|
54
61
|
// For users: showing a blank page is probably better than a flickering text.
|
|
55
|
-
`<p style="display: none">Redirecting to ${url}</p>`);
|
|
62
|
+
`<p style="display: none">Redirecting to ${url}</p><script>console.log('This HTTP response was generated by Vike.')</script>`);
|
|
56
63
|
}
|
|
57
|
-
exports.
|
|
58
|
-
function
|
|
64
|
+
exports.createHttpResponseRedirect = createHttpResponseRedirect;
|
|
65
|
+
function createHttpResponse(statusCode, contentType, headers, htmlRender, earlyHints = [], renderHook = null) {
|
|
59
66
|
headers.push(['Content-Type', contentType]);
|
|
60
67
|
(0, utils_js_1.assert)(renderHook || typeof htmlRender === 'string');
|
|
61
68
|
return {
|
|
@@ -22,9 +22,6 @@ async function executeOnRenderHtmlHook(pageContext) {
|
|
|
22
22
|
const { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter } = processHookReturnValue(hookReturnValue, renderHook);
|
|
23
23
|
Object.assign(pageContext, pageContextProvidedByRenderHook);
|
|
24
24
|
(0, utils_js_1.objectAssign)(pageContext, { _pageContextPromise: pageContextPromise });
|
|
25
|
-
if (documentHtml === null || documentHtml === undefined) {
|
|
26
|
-
return { htmlRender: null, renderHook };
|
|
27
|
-
}
|
|
28
25
|
const onErrorWhileStreaming = (err) => {
|
|
29
26
|
// Should the stream inject the following?
|
|
30
27
|
// ```
|
|
@@ -81,7 +78,7 @@ function getRenderHook(pageContext) {
|
|
|
81
78
|
return hookFound;
|
|
82
79
|
}
|
|
83
80
|
function processHookReturnValue(hookReturnValue, renderHook) {
|
|
84
|
-
let documentHtml
|
|
81
|
+
let documentHtml;
|
|
85
82
|
let pageContextPromise = null;
|
|
86
83
|
let pageContextProvidedByRenderHook = null;
|
|
87
84
|
let injectFilter = null;
|
|
@@ -108,7 +105,8 @@ function processHookReturnValue(hookReturnValue, renderHook) {
|
|
|
108
105
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isCallable)(hookReturnValue.injectFilter), 'injectFilter should be a function');
|
|
109
106
|
injectFilter = hookReturnValue.injectFilter;
|
|
110
107
|
}
|
|
111
|
-
|
|
108
|
+
(0, utils_js_1.assertUsage)(hookReturnValue.documentHtml, `${errPrefix} returned an object that is missing the ${picocolors_1.default.code('documentHtml')} property.`);
|
|
109
|
+
{
|
|
112
110
|
let val = hookReturnValue.documentHtml;
|
|
113
111
|
const errBegin = `${errPrefix} returned ${picocolors_1.default.cyan('{ documentHtml }')}, but ${picocolors_1.default.cyan('documentHtml')}`;
|
|
114
112
|
if (typeof val === 'string') {
|
|
@@ -7,7 +7,7 @@ exports.handleErrorWithoutErrorPage = void 0;
|
|
|
7
7
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
8
8
|
const globalContext_js_1 = require("../globalContext.js");
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
10
|
-
const
|
|
10
|
+
const createHttpResponse_js_1 = require("./createHttpResponse.js");
|
|
11
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
12
|
// When the user hasn't defined _error.page.js
|
|
13
13
|
async function handleErrorWithoutErrorPage(pageContext) {
|
|
@@ -18,13 +18,14 @@ async function handleErrorWithoutErrorPage(pageContext) {
|
|
|
18
18
|
warnMissingErrorPage(isV1);
|
|
19
19
|
}
|
|
20
20
|
if (!pageContext.isClientSideNavigation) {
|
|
21
|
-
(0,
|
|
21
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseError)();
|
|
22
|
+
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
22
23
|
return pageContext;
|
|
23
24
|
}
|
|
24
25
|
else {
|
|
25
26
|
const __getPageAssets = async () => [];
|
|
26
27
|
(0, utils_js_1.objectAssign)(pageContext, { __getPageAssets });
|
|
27
|
-
const httpResponse = await (0,
|
|
28
|
+
const httpResponse = await (0, createHttpResponse_js_1.createHttpResponsePage)((0, stringify_1.stringify)({ serverSideError: true }), null, pageContext);
|
|
28
29
|
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
29
30
|
return pageContext;
|
|
30
31
|
}
|
|
@@ -26,6 +26,9 @@ function inferMediaType(href) {
|
|
|
26
26
|
if (href.endsWith('.svg')) {
|
|
27
27
|
return { assetType: 'image', mediaType: 'image/svg+xml' };
|
|
28
28
|
}
|
|
29
|
+
if (href.endsWith('.avif')) {
|
|
30
|
+
return { assetType: 'image', mediaType: 'image/avif' };
|
|
31
|
+
}
|
|
29
32
|
// Fonts
|
|
30
33
|
if (href.endsWith('.ttf')) {
|
|
31
34
|
return { assetType: 'font', mediaType: 'font/ttf' };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isConfigInvalid_set = exports.isConfigInvalid = void 0;
|
|
4
|
-
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
let isConfigInvalid;
|
|
5
6
|
const isConfigInvalid_set = (val) => {
|
|
6
|
-
|
|
7
|
+
(0, utils_js_1.assert)(val === false || val.err);
|
|
8
|
+
exports.isConfigInvalid = isConfigInvalid = val;
|
|
7
9
|
};
|
|
8
10
|
exports.isConfigInvalid_set = isConfigInvalid_set;
|
|
@@ -11,7 +11,7 @@ const utils_js_1 = require("../utils.js");
|
|
|
11
11
|
const serializePageContextClientSide_js_1 = require("../html/serializePageContextClientSide.js");
|
|
12
12
|
const getPageContextUrlComputed_js_1 = require("../../../shared/getPageContextUrlComputed.js");
|
|
13
13
|
const globalContext_js_1 = require("../globalContext.js");
|
|
14
|
-
const
|
|
14
|
+
const createHttpResponse_js_1 = require("./createHttpResponse.js");
|
|
15
15
|
const loadUserFilesServerSide_js_1 = require("./loadUserFilesServerSide.js");
|
|
16
16
|
const executeOnRenderHtmlHook_js_1 = require("./executeOnRenderHtmlHook.js");
|
|
17
17
|
const executeOnBeforeRenderAndDataHooks_js_1 = require("./executeOnBeforeRenderAndDataHooks.js");
|
|
@@ -52,21 +52,15 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
52
52
|
(0, utils_js_1.objectAssign)(pageContext, { [isServerSideError_js_1.isServerSideError]: true });
|
|
53
53
|
}
|
|
54
54
|
const pageContextSerialized = (0, serializePageContextClientSide_js_1.serializePageContextClientSide)(pageContext);
|
|
55
|
-
const httpResponse = await (0,
|
|
55
|
+
const httpResponse = await (0, createHttpResponse_js_1.createHttpResponsePageContextJson)(pageContextSerialized);
|
|
56
56
|
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
57
57
|
return pageContext;
|
|
58
58
|
}
|
|
59
59
|
const renderHookResult = await (0, executeOnRenderHtmlHook_js_1.executeOnRenderHtmlHook)(pageContext);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
else {
|
|
65
|
-
const { htmlRender, renderHook } = renderHookResult;
|
|
66
|
-
const httpResponse = await (0, createHttpResponseObject_js_1.createHttpResponseObject)(htmlRender, renderHook, pageContext);
|
|
67
|
-
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
68
|
-
return pageContext;
|
|
69
|
-
}
|
|
60
|
+
const { htmlRender, renderHook } = renderHookResult;
|
|
61
|
+
const httpResponse = await (0, createHttpResponse_js_1.createHttpResponsePage)(htmlRender, renderHook, pageContext);
|
|
62
|
+
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
63
|
+
return pageContext;
|
|
70
64
|
}
|
|
71
65
|
exports.renderPageAlreadyRouted = renderPageAlreadyRouted;
|
|
72
66
|
async function prerenderPage(pageContext) {
|