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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { loadImportBuild };
|
|
2
2
|
export { setImportBuildGetters };
|
|
3
|
-
import { importServerEntry } from '@brillout/vite-plugin-server-entry/
|
|
3
|
+
import { importServerEntry } from '@brillout/vite-plugin-server-entry/runtime';
|
|
4
4
|
import { assert } from '../utils.js';
|
|
5
5
|
const buildGetters = (globalThis.__vike_buildGetters = globalThis.__vike_buildGetters || {
|
|
6
6
|
getters: null
|
|
@@ -22,7 +22,7 @@ type InjectFilterEntry = {
|
|
|
22
22
|
isEntry: boolean;
|
|
23
23
|
inject: PreloadFilterInject;
|
|
24
24
|
};
|
|
25
|
-
type Position = 'HTML_BEGIN' | 'HTML_END' | '
|
|
25
|
+
type Position = 'HTML_BEGIN' | 'HTML_END' | 'HTML_STREAM';
|
|
26
26
|
type HtmlTag = {
|
|
27
27
|
htmlTag: string | (() => string);
|
|
28
28
|
position: Position;
|
|
@@ -20,7 +20,7 @@ function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter,
|
|
|
20
20
|
if (asset.isEntry && asset.assetType === 'script') {
|
|
21
21
|
// We could allow the user to change the position of <script> but we currently don't:
|
|
22
22
|
// - Because of mergeScriptEntries()
|
|
23
|
-
// - We would need to add
|
|
23
|
+
// - We would need to add HTML_STREAM to to PreloadFilterInject
|
|
24
24
|
// To suppor this, we should add the JavaScript entry to injectFilterEntries (with an `src` value of `null`)
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
@@ -77,31 +77,36 @@ function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter,
|
|
|
77
77
|
// ==========
|
|
78
78
|
// JavaScript
|
|
79
79
|
// ==========
|
|
80
|
-
// -
|
|
80
|
+
// - By default, we place the entry <script> towards the end of the HTML for better performance.
|
|
81
|
+
// - Performance-wise, it's more interesting to start showing the page (parse HTML and load CSS) before starting loading scripts.
|
|
82
|
+
// - But with HTML streaming, in order to support [Progressive Rendering](https://vike.dev/streaming#progressive-rendering), the entry <script> should be injected earlier instead.
|
|
83
|
+
// - The entry <script> shouldn't be `<script defer>` upon HTML streaming, otherwise progressive hydration while SSR streaming won't work.
|
|
84
|
+
// - `<script id="vike_pageContext" type="application/json">` (the `pageContext` JSON) should be fully sent before Vike's client runtime starts executing.
|
|
81
85
|
// - Otherwise, race condition "SyntaxError: Unterminated string in JSON": https://github.com/vikejs/vike/issues/567
|
|
82
|
-
// -
|
|
83
|
-
// -
|
|
84
|
-
|
|
85
|
-
// - 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.
|
|
86
|
-
// - But with HTML streaming, in order to support [Progressive Rendering](https://vike.dev/streaming#progressive-rendering), the entry <script> should be injected early instead.
|
|
86
|
+
// - `<script id="vike_pageContext" type="application/json">` must appear before the entry <script> (which loads Vike's client runtime).
|
|
87
|
+
// - `<script id="vike_pageContext" type="application/json">` can't be async nor defer.
|
|
88
|
+
const positionJavaScriptDefault = 'HTML_END';
|
|
87
89
|
const positionJavaScriptEntry = (() => {
|
|
88
90
|
if (injectScriptsAt !== null) {
|
|
89
91
|
if (pageContext._pageContextPromise) {
|
|
90
92
|
assertWarning(injectScriptsAt === 'HTML_END' || !isStream, `You're setting injectScriptsAt to ${pc.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 });
|
|
91
93
|
}
|
|
94
|
+
if (injectScriptsAt === 'HTML_STREAM' && !isStream) {
|
|
95
|
+
return positionJavaScriptDefault;
|
|
96
|
+
}
|
|
92
97
|
return injectScriptsAt;
|
|
93
98
|
}
|
|
94
99
|
if (pageContext._pageContextPromise) {
|
|
95
100
|
// - If there is a pageContext._pageContextPromise then <script id="vike_pageContext" type="application/json"> needs to await for it.
|
|
96
101
|
// - pageContext._pageContextPromise is typically resolved only after the page's components are rendered and the stream ended.
|
|
97
102
|
// - https://vike.dev/streaming#initial-data-after-stream-end
|
|
98
|
-
return
|
|
103
|
+
return positionJavaScriptDefault;
|
|
99
104
|
}
|
|
100
105
|
if (streamFromReactStreamingPackage && !streamFromReactStreamingPackage.hasStreamEnded()) {
|
|
101
106
|
// 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.
|
|
102
|
-
return '
|
|
107
|
+
return 'HTML_STREAM';
|
|
103
108
|
}
|
|
104
|
-
return
|
|
109
|
+
return positionJavaScriptDefault;
|
|
105
110
|
})();
|
|
106
111
|
if (pageContext._pageContextPromise && streamFromReactStreamingPackage) {
|
|
107
112
|
// - Should we show this warning for Solid as well? Solid seems to also support progressive rendering.
|
|
@@ -135,7 +140,7 @@ function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter,
|
|
|
135
140
|
const htmlTag = inferPreloadTag(asset);
|
|
136
141
|
if (!asset.inject)
|
|
137
142
|
return;
|
|
138
|
-
// Ideally, instead of this conditional ternary operator, we should add
|
|
143
|
+
// Ideally, instead of this conditional ternary operator, we should add HTML_STREAM to PreloadFilterInject
|
|
139
144
|
const position = asset.inject === 'HTML_END' ? positionJavaScriptEntry : asset.inject;
|
|
140
145
|
htmlTags.push({ htmlTag, position });
|
|
141
146
|
});
|
|
@@ -217,6 +222,6 @@ function getInjectScriptsAt(pageId, pageConfigs) {
|
|
|
217
222
|
assertUsage(injectScriptsAt === null ||
|
|
218
223
|
injectScriptsAt === 'HTML_BEGIN' ||
|
|
219
224
|
injectScriptsAt === 'HTML_END' ||
|
|
220
|
-
injectScriptsAt === '
|
|
225
|
+
injectScriptsAt === 'HTML_STREAM', `${configDefinedAt} has an invalid value`);
|
|
221
226
|
return injectScriptsAt;
|
|
222
227
|
}
|
|
@@ -16,7 +16,7 @@ function injectHtmlTags(htmlString, htmlTags, position) {
|
|
|
16
16
|
}
|
|
17
17
|
// Is it worth it? Should we remove this? https://github.com/vikejs/vike/pull/1740#issuecomment-2230540892
|
|
18
18
|
function injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage) {
|
|
19
|
-
const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === '
|
|
19
|
+
const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === 'HTML_STREAM'));
|
|
20
20
|
if (htmlFragment) {
|
|
21
21
|
assert(!streamFromReactStreamingPackage.hasStreamEnded());
|
|
22
22
|
streamFromReactStreamingPackage.injectToStream(htmlFragment, { flush: true });
|
|
@@ -12,7 +12,7 @@ async function injectHtmlTagsToString(htmlParts, pageContext, injectFilter) {
|
|
|
12
12
|
let htmlString = htmlPartsToString(htmlParts, pageAssets);
|
|
13
13
|
htmlString = injectToHtmlBegin(htmlString, htmlTags);
|
|
14
14
|
htmlString = injectToHtmlEnd(htmlString, htmlTags);
|
|
15
|
-
assert(htmlTags.filter((snippet) => snippet.position === '
|
|
15
|
+
assert(htmlTags.filter((snippet) => snippet.position === 'HTML_STREAM').length === 0);
|
|
16
16
|
return htmlString;
|
|
17
17
|
}
|
|
18
18
|
function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, injectFilter) {
|
|
@@ -39,7 +39,7 @@ function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, in
|
|
|
39
39
|
if (streamFromReactStreamingPackage)
|
|
40
40
|
return null;
|
|
41
41
|
assert(htmlTags);
|
|
42
|
-
const tags = htmlTags.filter((h) => h.position === '
|
|
42
|
+
const tags = htmlTags.filter((h) => h.position === 'HTML_STREAM');
|
|
43
43
|
if (tags.length === 0)
|
|
44
44
|
return null;
|
|
45
45
|
const htmlFragment = joinHtmlTags(tags);
|
|
@@ -2,14 +2,14 @@ export { assertArguments };
|
|
|
2
2
|
import { assert, assertUsage, assertWarning, hasProp, isObject } from '../utils.js';
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
4
|
function assertArguments(...args) {
|
|
5
|
-
const prefix =
|
|
5
|
+
const prefix = `${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage)`;
|
|
6
6
|
const pageContextInit = args[0];
|
|
7
7
|
assertUsage(pageContextInit !== undefined && pageContextInit !== null, prefix + ` argument ${pc.cyan('pageContextInit')} is missing`, { showStackTrace: true });
|
|
8
8
|
const len = args.length;
|
|
9
|
-
assertUsage(len === 1, `${prefix}
|
|
9
|
+
assertUsage(len === 1, `${prefix} called with ${len} arguments but renderPage() accepts only one argument.'`, {
|
|
10
10
|
showStackTrace: true
|
|
11
11
|
});
|
|
12
|
-
assertUsage(isObject(pageContextInit), `${prefix}
|
|
12
|
+
assertUsage(isObject(pageContextInit), `${prefix} called with ${pc.code(`typeof pageContextInit === ${JSON.stringify(typeof pageContextInit)}`)} but ${pc.code('pageContextInit')} should be an object.`, { showStackTrace: true });
|
|
13
13
|
// TODO/v1-release: remove
|
|
14
14
|
if ('url' in pageContextInit) {
|
|
15
15
|
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/esm/node/runtime/renderPage/{createHttpResponseObject.d.ts → createHttpResponse.d.ts}
RENAMED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createHttpResponsePage };
|
|
2
2
|
export { createHttpResponsePageContextJson };
|
|
3
|
-
export {
|
|
3
|
+
export { createHttpResponseError };
|
|
4
|
+
export { createHttpResponseRedirect };
|
|
5
|
+
export { createHttpResponseFavicon404 };
|
|
4
6
|
export type { HttpResponse };
|
|
5
7
|
import type { GetPageAssets } from './getPageAssets.js';
|
|
6
8
|
import type { HtmlRender } from '../html/renderHtml.js';
|
|
@@ -16,13 +18,15 @@ type HttpResponse = {
|
|
|
16
18
|
/** **Deprecated**: use `headers` instead, see https://vike.dev/migration/0.4.134 */
|
|
17
19
|
contentType: 'application/json' | 'text/html;charset=utf-8';
|
|
18
20
|
} & HttpResponseBody;
|
|
19
|
-
declare function
|
|
21
|
+
declare function createHttpResponsePage(htmlRender: HtmlRender, renderHook: null | RenderHook, pageContext: {
|
|
20
22
|
_pageId: null | string;
|
|
21
23
|
is404: null | boolean;
|
|
22
24
|
errorWhileRendering: null | Error;
|
|
23
25
|
__getPageAssets: GetPageAssets;
|
|
24
26
|
_pageConfigs: PageConfigRuntime[];
|
|
25
27
|
abortStatusCode?: AbortStatusCode;
|
|
26
|
-
}): Promise<HttpResponse
|
|
28
|
+
}): Promise<HttpResponse>;
|
|
29
|
+
declare function createHttpResponseFavicon404(): HttpResponse;
|
|
30
|
+
declare function createHttpResponseError(): HttpResponse;
|
|
27
31
|
declare function createHttpResponsePageContextJson(pageContextSerialized: string): Promise<HttpResponse>;
|
|
28
|
-
declare function
|
|
32
|
+
declare function createHttpResponseRedirect({ url, statusCode }: UrlRedirect, urlLogical: string): HttpResponse;
|
package/dist/esm/node/runtime/renderPage/{createHttpResponseObject.js → createHttpResponse.js}
RENAMED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createHttpResponsePage };
|
|
2
2
|
export { createHttpResponsePageContextJson };
|
|
3
|
-
export {
|
|
3
|
+
export { createHttpResponseError };
|
|
4
|
+
export { createHttpResponseRedirect };
|
|
5
|
+
export { createHttpResponseFavicon404 };
|
|
4
6
|
import { assert, assertWarning } from '../utils.js';
|
|
5
7
|
import { isErrorPage } from '../../../shared/error-page.js';
|
|
6
8
|
import { getHttpResponseBody, getHttpResponseBodyStreamHandlers } from './getHttpResponseBody.js';
|
|
7
9
|
import { getEarlyHints } from './getEarlyHints.js';
|
|
8
|
-
import { getCacheControl } from './
|
|
9
|
-
import { assertNoInfiniteHttpRedirect } from './
|
|
10
|
-
async function
|
|
11
|
-
if (htmlRender === null) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
10
|
+
import { getCacheControl } from './createHttpResponse/getCacheControl.js';
|
|
11
|
+
import { assertNoInfiniteHttpRedirect } from './createHttpResponse/assertNoInfiniteHttpRedirect.js';
|
|
12
|
+
async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
|
|
14
13
|
let statusCode = pageContext.abortStatusCode;
|
|
15
14
|
if (!statusCode) {
|
|
16
15
|
const isError = !pageContext._pageId || isErrorPage(pageContext._pageId, pageContext._pageConfigs);
|
|
@@ -33,13 +32,21 @@ async function createHttpResponseObject(htmlRender, renderHook, pageContext) {
|
|
|
33
32
|
if (cacheControl) {
|
|
34
33
|
headers.push(['Cache-Control', cacheControl]);
|
|
35
34
|
}
|
|
36
|
-
return
|
|
35
|
+
return createHttpResponse(statusCode, 'text/html;charset=utf-8', headers, htmlRender, earlyHints, renderHook);
|
|
36
|
+
}
|
|
37
|
+
function createHttpResponseFavicon404() {
|
|
38
|
+
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>");
|
|
39
|
+
return httpResponse;
|
|
40
|
+
}
|
|
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
45
|
async function createHttpResponsePageContextJson(pageContextSerialized) {
|
|
39
|
-
const httpResponse =
|
|
46
|
+
const httpResponse = createHttpResponse(200, 'application/json', [], pageContextSerialized, [], null);
|
|
40
47
|
return httpResponse;
|
|
41
48
|
}
|
|
42
|
-
function
|
|
49
|
+
function createHttpResponseRedirect({ url, statusCode },
|
|
43
50
|
// The URL we assume the redirect to be logically based on
|
|
44
51
|
urlLogical) {
|
|
45
52
|
assertNoInfiniteHttpRedirect(url, urlLogical);
|
|
@@ -47,12 +54,12 @@ urlLogical) {
|
|
|
47
54
|
assert(statusCode);
|
|
48
55
|
assert(300 <= statusCode && statusCode <= 399);
|
|
49
56
|
const headers = [['Location', url]];
|
|
50
|
-
return
|
|
57
|
+
return createHttpResponse(statusCode, 'text/html;charset=utf-8', headers,
|
|
51
58
|
// For bots / programmatic crawlig: show what's going on.
|
|
52
59
|
// For users: showing a blank page is probably better than a flickering text.
|
|
53
|
-
`<p style="display: none">Redirecting to ${url}</p>`);
|
|
60
|
+
`<p style="display: none">Redirecting to ${url}</p><script>console.log('This HTTP response was generated by Vike.')</script>`);
|
|
54
61
|
}
|
|
55
|
-
function
|
|
62
|
+
function createHttpResponse(statusCode, contentType, headers, htmlRender, earlyHints = [], renderHook = null) {
|
|
56
63
|
headers.push(['Content-Type', contentType]);
|
|
57
64
|
assert(renderHook || typeof htmlRender === 'string');
|
|
58
65
|
return {
|
|
@@ -17,9 +17,6 @@ async function executeOnRenderHtmlHook(pageContext) {
|
|
|
17
17
|
const { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter } = processHookReturnValue(hookReturnValue, renderHook);
|
|
18
18
|
Object.assign(pageContext, pageContextProvidedByRenderHook);
|
|
19
19
|
objectAssign(pageContext, { _pageContextPromise: pageContextPromise });
|
|
20
|
-
if (documentHtml === null || documentHtml === undefined) {
|
|
21
|
-
return { htmlRender: null, renderHook };
|
|
22
|
-
}
|
|
23
20
|
const onErrorWhileStreaming = (err) => {
|
|
24
21
|
// Should the stream inject the following?
|
|
25
22
|
// ```
|
|
@@ -75,7 +72,7 @@ function getRenderHook(pageContext) {
|
|
|
75
72
|
return hookFound;
|
|
76
73
|
}
|
|
77
74
|
function processHookReturnValue(hookReturnValue, renderHook) {
|
|
78
|
-
let documentHtml
|
|
75
|
+
let documentHtml;
|
|
79
76
|
let pageContextPromise = null;
|
|
80
77
|
let pageContextProvidedByRenderHook = null;
|
|
81
78
|
let injectFilter = null;
|
|
@@ -102,7 +99,8 @@ function processHookReturnValue(hookReturnValue, renderHook) {
|
|
|
102
99
|
assertUsage(isCallable(hookReturnValue.injectFilter), 'injectFilter should be a function');
|
|
103
100
|
injectFilter = hookReturnValue.injectFilter;
|
|
104
101
|
}
|
|
105
|
-
|
|
102
|
+
assertUsage(hookReturnValue.documentHtml, `${errPrefix} returned an object that is missing the ${pc.code('documentHtml')} property.`);
|
|
103
|
+
{
|
|
106
104
|
let val = hookReturnValue.documentHtml;
|
|
107
105
|
const errBegin = `${errPrefix} returned ${pc.cyan('{ documentHtml }')}, but ${pc.cyan('documentHtml')}`;
|
|
108
106
|
if (typeof val === 'string') {
|
|
@@ -2,7 +2,7 @@ export { handleErrorWithoutErrorPage };
|
|
|
2
2
|
import { stringify } from '@brillout/json-serializer/stringify';
|
|
3
3
|
import { getGlobalContext } from '../globalContext.js';
|
|
4
4
|
import { assert, assertWarning, objectAssign } from '../utils.js';
|
|
5
|
-
import {
|
|
5
|
+
import { createHttpResponsePage, createHttpResponseError } from './createHttpResponse.js';
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
7
7
|
// When the user hasn't defined _error.page.js
|
|
8
8
|
async function handleErrorWithoutErrorPage(pageContext) {
|
|
@@ -13,13 +13,14 @@ async function handleErrorWithoutErrorPage(pageContext) {
|
|
|
13
13
|
warnMissingErrorPage(isV1);
|
|
14
14
|
}
|
|
15
15
|
if (!pageContext.isClientSideNavigation) {
|
|
16
|
-
|
|
16
|
+
const httpResponse = createHttpResponseError();
|
|
17
|
+
objectAssign(pageContext, { httpResponse });
|
|
17
18
|
return pageContext;
|
|
18
19
|
}
|
|
19
20
|
else {
|
|
20
21
|
const __getPageAssets = async () => [];
|
|
21
22
|
objectAssign(pageContext, { __getPageAssets });
|
|
22
|
-
const httpResponse = await
|
|
23
|
+
const httpResponse = await createHttpResponsePage(stringify({ serverSideError: true }), null, pageContext);
|
|
23
24
|
objectAssign(pageContext, { httpResponse });
|
|
24
25
|
return pageContext;
|
|
25
26
|
}
|
|
@@ -2,6 +2,6 @@ export { inferMediaType };
|
|
|
2
2
|
export type { MediaType };
|
|
3
3
|
type MediaType = null | {
|
|
4
4
|
assetType: 'image' | 'script' | 'font' | 'style' | 'audio' | 'video' | 'document' | 'fetch' | 'track' | 'worker' | 'embed' | 'object';
|
|
5
|
-
mediaType: 'text/javascript' | 'text/css' | 'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif' | 'image/svg+xml' | 'font/ttf' | 'font/woff' | 'font/woff2' | 'video/mp4' | 'video/webm' | 'video/ogg' | 'video/mpeg' | 'video/x-msvideo' | 'video/quicktime' | 'audio/mpeg' | 'audio/wav' | 'audio/ogg' | 'audio/aac' | 'audio/midi' | 'audio/flac';
|
|
5
|
+
mediaType: 'text/javascript' | 'text/css' | 'image/avif' | 'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif' | 'image/svg+xml' | 'font/ttf' | 'font/woff' | 'font/woff2' | 'video/mp4' | 'video/webm' | 'video/ogg' | 'video/mpeg' | 'video/x-msvideo' | 'video/quicktime' | 'audio/mpeg' | 'audio/wav' | 'audio/ogg' | 'audio/aac' | 'audio/midi' | 'audio/flac';
|
|
6
6
|
};
|
|
7
7
|
declare function inferMediaType(href: string): MediaType;
|
|
@@ -24,6 +24,9 @@ function inferMediaType(href) {
|
|
|
24
24
|
if (href.endsWith('.svg')) {
|
|
25
25
|
return { assetType: 'image', mediaType: 'image/svg+xml' };
|
|
26
26
|
}
|
|
27
|
+
if (href.endsWith('.avif')) {
|
|
28
|
+
return { assetType: 'image', mediaType: 'image/avif' };
|
|
29
|
+
}
|
|
27
30
|
// Fonts
|
|
28
31
|
if (href.endsWith('.ttf')) {
|
|
29
32
|
return { assetType: 'font', mediaType: 'font/ttf' };
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { isConfigInvalid };
|
|
2
|
+
export { isConfigInvalid_set };
|
|
3
|
+
declare let isConfigInvalid: false | {
|
|
4
|
+
err: unknown;
|
|
5
|
+
};
|
|
6
|
+
declare const isConfigInvalid_set: (val: typeof isConfigInvalid) => void;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { isConfigInvalid };
|
|
2
|
+
export { isConfigInvalid_set };
|
|
3
|
+
import { assert } from '../utils.js';
|
|
4
|
+
let isConfigInvalid;
|
|
5
|
+
const isConfigInvalid_set = (val) => {
|
|
6
|
+
assert(val === false || val.err);
|
|
3
7
|
isConfigInvalid = val;
|
|
4
8
|
};
|
|
@@ -8,13 +8,13 @@ export type { PageContextAfterRender };
|
|
|
8
8
|
export type { PageContextInitEnhanced };
|
|
9
9
|
import { type PageFile } from '../../../shared/getPageFiles.js';
|
|
10
10
|
import { type PageContextUrlInternal } from '../../../shared/getPageContextUrlComputed.js';
|
|
11
|
-
import { HttpResponse } from './
|
|
11
|
+
import { HttpResponse } from './createHttpResponse.js';
|
|
12
12
|
import { PageContext_loadUserFilesServerSide, type PageFiles } from './loadUserFilesServerSide.js';
|
|
13
13
|
import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
14
14
|
import { type PageRoutes } from '../../../shared/route/loadPageRoutes.js';
|
|
15
15
|
import type { Hook } from '../../../shared/hooks/getHook.js';
|
|
16
16
|
type PageContextAfterRender = {
|
|
17
|
-
httpResponse:
|
|
17
|
+
httpResponse: HttpResponse;
|
|
18
18
|
errorWhileRendering: null | Error;
|
|
19
19
|
};
|
|
20
20
|
declare function renderPageAlreadyRouted<PageContext extends {
|
|
@@ -10,7 +10,7 @@ import { assert, assertUsage, assertWarning, hasProp, normalizeHeaders, objectAs
|
|
|
10
10
|
import { serializePageContextClientSide } from '../html/serializePageContextClientSide.js';
|
|
11
11
|
import { getPageContextUrlComputed } from '../../../shared/getPageContextUrlComputed.js';
|
|
12
12
|
import { getGlobalContext } from '../globalContext.js';
|
|
13
|
-
import {
|
|
13
|
+
import { createHttpResponsePage, createHttpResponsePageContextJson } from './createHttpResponse.js';
|
|
14
14
|
import { loadUserFilesServerSide } from './loadUserFilesServerSide.js';
|
|
15
15
|
import { executeOnRenderHtmlHook } from './executeOnRenderHtmlHook.js';
|
|
16
16
|
import { executeOnBeforeRenderAndDataHooks } from './executeOnBeforeRenderAndDataHooks.js';
|
|
@@ -56,16 +56,10 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
56
56
|
return pageContext;
|
|
57
57
|
}
|
|
58
58
|
const renderHookResult = await executeOnRenderHtmlHook(pageContext);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
else {
|
|
64
|
-
const { htmlRender, renderHook } = renderHookResult;
|
|
65
|
-
const httpResponse = await createHttpResponseObject(htmlRender, renderHook, pageContext);
|
|
66
|
-
objectAssign(pageContext, { httpResponse });
|
|
67
|
-
return pageContext;
|
|
68
|
-
}
|
|
59
|
+
const { htmlRender, renderHook } = renderHookResult;
|
|
60
|
+
const httpResponse = await createHttpResponsePage(htmlRender, renderHook, pageContext);
|
|
61
|
+
objectAssign(pageContext, { httpResponse });
|
|
62
|
+
return pageContext;
|
|
69
63
|
}
|
|
70
64
|
async function prerenderPage(pageContext) {
|
|
71
65
|
objectAssign(pageContext, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { renderPage };
|
|
2
2
|
export { renderPage_addWrapper };
|
|
3
|
-
import { HttpResponse } from './renderPage/
|
|
3
|
+
import { HttpResponse } from './renderPage/createHttpResponse.js';
|
|
4
4
|
import type { PageContextServer } from '../../types/index.js';
|
|
5
5
|
declare let renderPage_wrapper: <PageContext>(_httpRequestId: number, ret: () => Promise<PageContext>) => Promise<{
|
|
6
6
|
pageContextReturn: Awaited<PageContext>;
|
|
@@ -12,5 +12,5 @@ declare function renderPage<PageContextUserAdded extends {}, PageContextInit ext
|
|
|
12
12
|
/** The URL of the HTTP request */
|
|
13
13
|
urlOriginal: string;
|
|
14
14
|
}>(pageContextInit: PageContextInit): Promise<PageContextInit & {
|
|
15
|
-
httpResponse: HttpResponse
|
|
15
|
+
httpResponse: HttpResponse;
|
|
16
16
|
} & Partial<PageContextServer & PageContextUserAdded>>;
|