vike 0.4.235 → 0.4.236-commit-64431e7
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/__internal/index.js +1 -1
- package/dist/cjs/client/shared/createGetGlobalContextClient.js +2 -3
- package/dist/cjs/client/shared/preparePageContextForPublicUsageClientShared.js +4 -4
- package/dist/cjs/node/api/prepareViteApiCall.js +1 -1
- package/dist/cjs/node/cli/index.js +1 -1
- package/dist/cjs/node/createPageRenderer.js +1 -1
- package/dist/cjs/node/importBuild.js +1 -1
- package/dist/cjs/node/prerender/context.js +1 -1
- package/dist/cjs/node/prerender/index.js +1 -1
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +2 -2
- package/dist/cjs/node/prerender/runPrerender.js +9 -13
- package/dist/cjs/node/runtime/globalContext.js +109 -28
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +8 -1
- package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +2 -0
- package/dist/cjs/node/runtime/html/serializeContext.js +73 -15
- package/dist/cjs/node/runtime/index-deprecated.js +1 -1
- package/dist/cjs/node/runtime/index.js +1 -1
- package/dist/cjs/node/runtime/page-files/setup.js +1 -1
- package/dist/cjs/node/runtime/renderPage/assertArguments.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +9 -6
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -4
- package/dist/cjs/node/runtime/renderPage/execHookDataAndOnBeforeRender.js +2 -2
- package/dist/cjs/node/runtime/renderPage/{createHttpResponse/getCacheControl.js → getCacheControl.js} +9 -9
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +4 -4
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +15 -12
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +35 -16
- package/dist/cjs/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -0
- package/dist/cjs/node/runtime/renderPage.js +4 -6
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/node/vite/index.js +2 -0
- package/dist/cjs/node/vite/onLoad.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +3 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildEntry.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +16 -7
- package/dist/cjs/node/vite/plugins/pluginCommon/assertResolveAlias.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginCommon.js +9 -4
- package/dist/cjs/node/vite/plugins/pluginDev.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +4 -4
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginFileEnv.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginViteRPC.js +42 -0
- package/dist/cjs/node/vite/shared/addSsrMiddleware.js +1 -1
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/cjs/node/vite/shared/loggerNotProd.js +10 -6
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +5 -1
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js +4 -6
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +1 -1
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +6 -6
- package/dist/cjs/shared/RenderErrorPage.js +1 -1
- package/dist/cjs/shared/abort.js +1 -1
- package/dist/cjs/shared/createGlobalContextShared.js +28 -7
- package/dist/cjs/shared/createPageContextShared.js +1 -2
- package/dist/cjs/shared/determinePageIdOld.js +1 -1
- package/dist/cjs/shared/error-page.js +3 -3
- package/dist/cjs/shared/getPageContextUrlComputed.js +4 -4
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +1 -1
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide/analyzeExports.js +1 -1
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -1
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide.js +2 -2
- package/dist/cjs/shared/getPageFiles/assert_exports_old_design.js +1 -1
- package/dist/cjs/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/cjs/shared/getPageFiles/getAllPageIdFiles.js +1 -1
- package/dist/cjs/shared/getPageFiles/getPageFileObject.js +1 -1
- package/dist/cjs/shared/getPageFiles/parseVirtualFileExports.js +1 -1
- package/dist/cjs/shared/getProxyForPublicUsage.js +3 -3
- package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +4 -3
- package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +10 -10
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/cjs/shared/preparePageContextForPublicUsage.js +5 -5
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/shared/route/deduceRouteStringFromFilesystemPath.js +1 -1
- package/dist/cjs/shared/route/execHookGuard.js +1 -1
- package/dist/cjs/shared/route/execHookOnBeforeRoute.js +1 -1
- package/dist/cjs/shared/route/index.js +1 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +10 -4
- package/dist/cjs/shared/route/resolveRouteFunction.js +3 -3
- package/dist/cjs/shared/route/resolveRouteString.js +1 -1
- package/dist/cjs/shared/route/routing.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +11 -8
- package/dist/cjs/utils/debug.js +1 -0
- package/dist/cjs/utils/debugGlob.js +1 -1
- package/dist/cjs/utils/getViteRPC.js +79 -0
- package/dist/cjs/utils/parseNpmPackage.js +1 -1
- package/dist/esm/__internal/index.d.ts +1 -1
- package/dist/esm/__internal/index.js +1 -1
- package/dist/esm/client/node.js +1 -1
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +10 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +6 -6
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/index.js +1 -1
- package/dist/esm/client/runtime-client-routing/isClientSideRoutable.js +1 -1
- package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.js +6 -6
- package/dist/esm/client/runtime-client-routing/prefetch.js +10 -10
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +3 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +3 -3
- package/dist/esm/client/runtime-client-routing/skipLink.js +1 -1
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +2 -2
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/index.js +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +5 -4
- package/dist/esm/client/shared/createGetGlobalContextClient.js +1 -2
- package/dist/esm/client/shared/execHookOnRenderClient.js +1 -1
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.js +4 -4
- package/dist/esm/node/api/prepareViteApiCall.js +1 -1
- package/dist/esm/node/cli/index.js +1 -1
- package/dist/esm/node/createPageRenderer.js +1 -1
- package/dist/esm/node/importBuild.js +1 -1
- package/dist/esm/node/prerender/context.js +1 -1
- package/dist/esm/node/prerender/index.js +1 -1
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +2 -2
- package/dist/esm/node/prerender/runPrerender.d.ts +42 -133
- package/dist/esm/node/prerender/runPrerender.js +9 -13
- package/dist/esm/node/runtime/globalContext.d.ts +39 -59
- package/dist/esm/node/runtime/globalContext.js +112 -31
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +8 -1
- package/dist/esm/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +2 -0
- package/dist/esm/node/runtime/html/serializeContext.d.ts +7 -1
- package/dist/esm/node/runtime/html/serializeContext.js +73 -15
- package/dist/esm/node/runtime/index-deprecated.js +1 -1
- package/dist/esm/node/runtime/index.js +1 -1
- package/dist/esm/node/runtime/page-files/setup.js +1 -1
- package/dist/esm/node/runtime/renderPage/assertArguments.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -0
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +9 -6
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +12 -35
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -4
- package/dist/esm/node/runtime/renderPage/execHookDataAndOnBeforeRender.js +2 -2
- package/dist/esm/node/runtime/renderPage/getCacheControl.d.ts +5 -0
- package/dist/esm/node/runtime/renderPage/{createHttpResponse/getCacheControl.js → getCacheControl.js} +8 -9
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +4 -4
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +16 -13
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +8 -4
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +36 -17
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +24 -68
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -0
- package/dist/esm/node/runtime/renderPage.d.ts +13 -36
- package/dist/esm/node/runtime/renderPage.js +4 -6
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/node/vite/index.js +3 -1
- package/dist/esm/node/vite/onLoad.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -3
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +3 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildEntry.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +16 -7
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +0 -1
- package/dist/esm/node/vite/plugins/pluginCommon/assertResolveAlias.js +1 -1
- package/dist/esm/node/vite/plugins/pluginCommon.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginCommon.js +9 -4
- package/dist/esm/node/vite/plugins/pluginDev.js +1 -1
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +1 -1
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +1 -1
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +1 -1
- package/dist/esm/node/vite/plugins/pluginViteRPC.d.ts +25 -0
- package/dist/esm/node/vite/plugins/pluginViteRPC.js +40 -0
- package/dist/esm/node/vite/shared/addSsrMiddleware.js +1 -1
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/esm/node/vite/shared/loggerNotProd.js +10 -0
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +5 -1
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js +4 -6
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +1 -1
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +6 -6
- package/dist/esm/shared/RenderErrorPage.js +1 -1
- package/dist/esm/shared/abort.js +1 -1
- package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/shared/createGlobalContextShared.js +28 -7
- package/dist/esm/shared/createPageContextShared.d.ts +2 -3
- package/dist/esm/shared/createPageContextShared.js +1 -2
- package/dist/esm/shared/determinePageIdOld.js +1 -1
- package/dist/esm/shared/error-page.js +3 -3
- package/dist/esm/shared/getPageContextUrlComputed.js +4 -4
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzePageClientSide/analyzeExports.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzePageClientSide.js +2 -2
- package/dist/esm/shared/getPageFiles/assert_exports_old_design.js +1 -1
- package/dist/esm/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/esm/shared/getPageFiles/getAllPageIdFiles.js +1 -1
- package/dist/esm/shared/getPageFiles/getPageFileObject.js +1 -1
- package/dist/esm/shared/getPageFiles/parseVirtualFileExports.js +1 -1
- package/dist/esm/shared/getProxyForPublicUsage.js +1 -1
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/getConfigDefinedAt.js +4 -3
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +12 -12
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/esm/shared/preparePageContextForPublicUsage.js +5 -5
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/deduceRouteStringFromFilesystemPath.js +1 -1
- package/dist/esm/shared/route/execHookGuard.js +1 -1
- package/dist/esm/shared/route/execHookOnBeforeRoute.js +1 -1
- package/dist/esm/shared/route/index.js +1 -1
- package/dist/esm/shared/route/loadPageRoutes.d.ts +5 -0
- package/dist/esm/shared/route/loadPageRoutes.js +10 -4
- package/dist/esm/shared/route/resolveRouteFunction.js +3 -3
- package/dist/esm/shared/route/resolveRouteString.js +1 -1
- package/dist/esm/shared/route/routing.js +1 -1
- package/dist/esm/types/Config.d.ts +9 -1
- package/dist/esm/types/PageContext.d.ts +8 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +11 -8
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +1 -0
- package/dist/esm/utils/debugGlob.js +1 -1
- package/dist/esm/utils/getViteRPC.d.ts +6 -0
- package/dist/esm/utils/getViteRPC.js +77 -0
- package/dist/esm/utils/parseNpmPackage.js +1 -1
- package/package.json +12 -6
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +0 -5
|
@@ -13,7 +13,7 @@ export { setGlobalContext_viteDevServer };
|
|
|
13
13
|
export { setGlobalContext_viteConfig };
|
|
14
14
|
export { setGlobalContext_isPrerendering };
|
|
15
15
|
export { setGlobalContext_isProduction };
|
|
16
|
-
export { setGlobalContext_buildEntry };
|
|
16
|
+
export { setGlobalContext_buildEntry }; // production entry
|
|
17
17
|
export { clearGlobalContext };
|
|
18
18
|
export { assertBuildInfo };
|
|
19
19
|
export { updateUserFiles };
|
|
@@ -26,11 +26,11 @@ export { vikeConfigErrorRecoverMsg };
|
|
|
26
26
|
// - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
|
|
27
27
|
// - In development: globalObject.viteDevServer which is Vite's development server
|
|
28
28
|
// - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExports
|
|
29
|
-
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, } from './utils.js';
|
|
29
|
+
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, } from './utils.js';
|
|
30
30
|
import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
|
|
31
31
|
import { virtualFileIdEntryServer } from '../shared/virtualFiles/virtualFileEntry.js';
|
|
32
32
|
import pc from '@brillout/picocolors';
|
|
33
|
-
import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
|
|
33
|
+
import { loadPageRoutes, loadPageRoutesSync } from '../../shared/route/loadPageRoutes.js';
|
|
34
34
|
import { assertV1Design } from '../shared/assertV1Design.js';
|
|
35
35
|
import { resolveBase } from '../shared/resolveBase.js';
|
|
36
36
|
import { createGlobalContextShared, getGlobalContextSyncErrMsg, } from '../../shared/createGlobalContextShared.js';
|
|
@@ -39,7 +39,7 @@ import { logRuntimeError, logRuntimeInfo } from './loggerRuntime.js';
|
|
|
39
39
|
import { getVikeConfigErrorBuild, setVikeConfigError } from '../shared/getVikeConfigError.js';
|
|
40
40
|
import { hasAlreadyLogged } from './renderPage/isNewError.js';
|
|
41
41
|
const debug = createDebugger('vike:globalContext');
|
|
42
|
-
const globalObject = getGlobalObject('runtime/globalContext.ts',
|
|
42
|
+
const globalObject = getGlobalObject('runtime/globalContext.ts', getInitialGlobalObject());
|
|
43
43
|
// Trick to break down TypeScript circular dependency
|
|
44
44
|
// https://chat.deepseek.com/a/chat/s/d7e9f90a-c7f3-4108-9cd5-4ad6caed3539
|
|
45
45
|
const globalObjectTyped = globalObject;
|
|
@@ -99,17 +99,19 @@ async function getGlobalContextAsync(isProduction) {
|
|
|
99
99
|
* Get runtime information about your app.
|
|
100
100
|
*
|
|
101
101
|
* https://vike.dev/getGlobalContext
|
|
102
|
-
*
|
|
103
|
-
* @deprecated
|
|
104
102
|
*/
|
|
105
103
|
function getGlobalContextSync() {
|
|
106
104
|
debug('getGlobalContextSync()');
|
|
107
105
|
const { globalContext } = globalObjectTyped;
|
|
108
106
|
assertUsage(globalContext, getGlobalContextSyncErrMsg);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
const isProd = globalContext._isProduction;
|
|
108
|
+
assert(typeof isProd === 'boolean');
|
|
109
|
+
assertWarning(isProd,
|
|
110
|
+
// - We discourage users from using it in development because `pageContext.globalContext` is safer: I ain't sure but there could be race conditions when using `getGlobalContextSync()` inside React/Vue components upon HMR.
|
|
111
|
+
// - I don't see any issues with getGlobalContextSync() in production.
|
|
112
|
+
// - getGlobalContextSync() is used in production by vike-vercel
|
|
113
|
+
// - https://discord.com/channels/@me/942519153502339072/1389546794676916344 (PM between Rom and Joël)
|
|
114
|
+
"getGlobalContextSync() shouldn't be used in development, see https://vike.dev/getGlobalContext", { onlyOnce: true });
|
|
113
115
|
return getGlobalContextForPublicUsage();
|
|
114
116
|
}
|
|
115
117
|
function getGlobalContextForPublicUsage() {
|
|
@@ -148,7 +150,12 @@ function setGlobalContext_isPrerendering() {
|
|
|
148
150
|
globalObject.isPrerendering = true;
|
|
149
151
|
setIsProduction(true);
|
|
150
152
|
}
|
|
151
|
-
function setGlobalContext_isProduction(isProduction, tolerateContraditction) {
|
|
153
|
+
function setGlobalContext_isProduction(isProduction, tolerateContraditction = false) {
|
|
154
|
+
// TODO/now: try to remove globalObject.isProduction ?
|
|
155
|
+
// TODO/now: `rename tolerateContraditction tolerateContradiction`
|
|
156
|
+
tolerateContraditction = true;
|
|
157
|
+
if (debug.isActivated)
|
|
158
|
+
debug('setGlobalContext_isProduction()', { isProduction, tolerateContraditction });
|
|
152
159
|
if (globalObject.isProduction === undefined) {
|
|
153
160
|
setIsProduction(isProduction);
|
|
154
161
|
}
|
|
@@ -197,7 +204,12 @@ async function initGlobalContext() {
|
|
|
197
204
|
const { isProduction } = globalObject;
|
|
198
205
|
assert(typeof isProduction === 'boolean');
|
|
199
206
|
if (!isProduction) {
|
|
200
|
-
|
|
207
|
+
if (isProcessSharedWithVite()) {
|
|
208
|
+
await globalObject.viteDevServerPromise;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
await updateUserFiles();
|
|
212
|
+
}
|
|
201
213
|
assert(globalObject.waitForUserFilesUpdate);
|
|
202
214
|
await globalObject.waitForUserFilesUpdate;
|
|
203
215
|
}
|
|
@@ -230,6 +242,7 @@ function assertViteManifest(manifest) {
|
|
|
230
242
|
async function loadBuildEntry(outDir) {
|
|
231
243
|
debug('loadBuildEntry()');
|
|
232
244
|
if (globalObject.globalContext) {
|
|
245
|
+
debug('loadBuildEntry() - already done');
|
|
233
246
|
return;
|
|
234
247
|
}
|
|
235
248
|
if (!globalObject.buildEntry) {
|
|
@@ -255,6 +268,8 @@ async function loadBuildEntry(outDir) {
|
|
|
255
268
|
globalObject.buildInfo = buildEntry.buildInfo;
|
|
256
269
|
await setGlobalContext(buildEntry.virtualFileExports);
|
|
257
270
|
}
|
|
271
|
+
// This is the production entry, see:
|
|
272
|
+
// https://github.com/vikejs/vike/blob/798e5465dc3e3e6723b38b601a50350c0a006fb8/packages/vike/node/vite/plugins/pluginBuild/pluginBuildEntry.ts#L47
|
|
258
273
|
async function setGlobalContext_buildEntry(buildEntry) {
|
|
259
274
|
debug('setGlobalContext_buildEntry()');
|
|
260
275
|
setIsProduction(true);
|
|
@@ -264,6 +279,7 @@ async function setGlobalContext_buildEntry(buildEntry) {
|
|
|
264
279
|
assert(globalObject.buildEntry); // ensure no infinite loop
|
|
265
280
|
await loadBuildEntry();
|
|
266
281
|
assertGlobalContextIsDefined();
|
|
282
|
+
debug('setGlobalContext_buildEntry() - done');
|
|
267
283
|
}
|
|
268
284
|
function assertBuildEntry(buildEntry) {
|
|
269
285
|
assert(isObject(buildEntry));
|
|
@@ -327,16 +343,27 @@ async function updateUserFiles() {
|
|
|
327
343
|
// Avoid race condition: abort if there is a new globalObject.viteDevServer (happens when vite.config.js is modified => Vite's dev server is fully reloaded).
|
|
328
344
|
viteDevServer !== globalObject.viteDevServer;
|
|
329
345
|
const { viteDevServer } = globalObject;
|
|
330
|
-
assert(viteDevServer);
|
|
331
346
|
let hasError = false;
|
|
332
347
|
let virtualFileExports;
|
|
333
348
|
let err;
|
|
334
|
-
|
|
335
|
-
|
|
349
|
+
if (viteDevServer) {
|
|
350
|
+
try {
|
|
351
|
+
virtualFileExports = await viteDevServer.ssrLoadModule(virtualFileIdEntryServer);
|
|
352
|
+
}
|
|
353
|
+
catch (err_) {
|
|
354
|
+
hasError = true;
|
|
355
|
+
err = err_;
|
|
356
|
+
}
|
|
336
357
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
358
|
+
else {
|
|
359
|
+
try {
|
|
360
|
+
// We don't directly use import() to workaround what seems to be a Vite HMR bug: using import() breaks the HMR of normal non-worker apps.
|
|
361
|
+
virtualFileExports = await __VIKE__DYNAMIC_IMPORT('virtual:vike:entry:server');
|
|
362
|
+
}
|
|
363
|
+
catch (err_) {
|
|
364
|
+
hasError = true;
|
|
365
|
+
err = err_;
|
|
366
|
+
}
|
|
340
367
|
}
|
|
341
368
|
if (isOutdated())
|
|
342
369
|
return { success: false };
|
|
@@ -360,40 +387,46 @@ async function updateUserFiles() {
|
|
|
360
387
|
return onSuccess();
|
|
361
388
|
}
|
|
362
389
|
async function setGlobalContext(virtualFileExports) {
|
|
390
|
+
debug('setGlobalContext()');
|
|
363
391
|
assert(!getVikeConfigErrorBuild());
|
|
364
|
-
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext);
|
|
392
|
+
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
|
|
365
393
|
assertV1Design(
|
|
366
394
|
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
367
395
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
368
396
|
assertGlobalContextIsDefined();
|
|
369
397
|
onSetupRuntime();
|
|
398
|
+
debug('setGlobalContext() - done');
|
|
370
399
|
// Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
|
|
371
400
|
return globalContext;
|
|
372
401
|
}
|
|
373
|
-
async function
|
|
402
|
+
async function addGlobalContextTmp(globalContext) {
|
|
403
|
+
debug('addGlobalContextTmp()');
|
|
374
404
|
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
405
|
+
return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
|
|
406
|
+
}
|
|
407
|
+
function addGlobalContext(globalContext) {
|
|
408
|
+
debug('addGlobalContext()');
|
|
409
|
+
const { pageRoutes, onBeforeRouteHook } = loadPageRoutesSync(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
410
|
+
return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
|
|
411
|
+
}
|
|
412
|
+
function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
375
413
|
const globalContextBase = {
|
|
376
414
|
isClientSide: false,
|
|
377
415
|
_pageRoutes: pageRoutes,
|
|
378
416
|
_onBeforeRouteHook: onBeforeRouteHook,
|
|
379
417
|
};
|
|
380
|
-
const { viteDevServer, viteConfig,
|
|
418
|
+
const { viteDevServer, viteConfig, isPrerendering, isProduction } = globalObject;
|
|
381
419
|
assert(typeof isProduction === 'boolean');
|
|
382
420
|
if (!isProduction) {
|
|
383
|
-
assert(viteDevServer);
|
|
384
421
|
assert(globalContext); // main common requirement
|
|
385
|
-
assert(viteConfig);
|
|
386
|
-
assert(viteConfigRuntime);
|
|
387
422
|
assert(!isPrerendering);
|
|
388
423
|
return {
|
|
389
424
|
...globalContextBase,
|
|
390
|
-
...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
|
|
391
425
|
_isProduction: false,
|
|
392
426
|
_isPrerendering: false,
|
|
393
427
|
assetsManifest: null,
|
|
394
428
|
_viteDevServer: viteDevServer,
|
|
395
429
|
viteConfig,
|
|
396
|
-
viteConfigRuntime,
|
|
397
430
|
};
|
|
398
431
|
}
|
|
399
432
|
else {
|
|
@@ -404,11 +437,9 @@ async function addGlobalContext(globalContext) {
|
|
|
404
437
|
assert(assetsManifest);
|
|
405
438
|
const globalContextBase2 = {
|
|
406
439
|
...globalContextBase,
|
|
407
|
-
...resolveBaseRuntime(buildInfo.viteConfigRuntime, globalContext.config),
|
|
408
440
|
_isProduction: true,
|
|
409
441
|
assetsManifest,
|
|
410
442
|
_viteDevServer: null,
|
|
411
|
-
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
412
443
|
_usesClientRouter: buildInfo.usesClientRouter,
|
|
413
444
|
};
|
|
414
445
|
if (isPrerendering) {
|
|
@@ -428,14 +459,45 @@ async function addGlobalContext(globalContext) {
|
|
|
428
459
|
}
|
|
429
460
|
}
|
|
430
461
|
}
|
|
462
|
+
async function addGlobalContextAsync(globalContext) {
|
|
463
|
+
debug('addGlobalContextAsync()');
|
|
464
|
+
let { viteConfigRuntime, buildInfo } = globalObject;
|
|
465
|
+
if (!viteConfigRuntime) {
|
|
466
|
+
if (buildInfo) {
|
|
467
|
+
viteConfigRuntime = buildInfo.viteConfigRuntime;
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
if (!isProcessSharedWithVite()) {
|
|
471
|
+
if (!globalObject.isProduction) {
|
|
472
|
+
const rpc = getViteRPC();
|
|
473
|
+
viteConfigRuntime = await rpc.getViteConfigRuntimeRPC();
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
assert(false); // production => globalObject.buildInfo should be set
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
assert(false); // process shared with Vite => globalObject.viteConfigRuntime should be set
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
assert(viteConfigRuntime);
|
|
485
|
+
return {
|
|
486
|
+
viteConfigRuntime,
|
|
487
|
+
...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
|
|
488
|
+
};
|
|
489
|
+
}
|
|
431
490
|
function clearGlobalContext() {
|
|
432
491
|
debug('clearGlobalContext()');
|
|
433
|
-
objectReplace(globalObject,
|
|
492
|
+
objectReplace(globalObject, getInitialGlobalObject(), ['buildEntryPrevious']);
|
|
434
493
|
}
|
|
435
|
-
function
|
|
436
|
-
|
|
494
|
+
function getInitialGlobalObject() {
|
|
495
|
+
const isProduction = getIsProductionStatic();
|
|
496
|
+
if (debug.isActivated)
|
|
497
|
+
debug('getInitialGlobalObject()', { isProduction });
|
|
437
498
|
const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = genPromise();
|
|
438
499
|
return {
|
|
500
|
+
isProduction,
|
|
439
501
|
viteDevServerPromise,
|
|
440
502
|
viteDevServerPromiseResolve,
|
|
441
503
|
};
|
|
@@ -446,3 +508,22 @@ function resolveBaseRuntime(viteConfigRuntime, config) {
|
|
|
446
508
|
const baseAssetsUnresolved = config.baseAssets ?? null;
|
|
447
509
|
return resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
448
510
|
}
|
|
511
|
+
function getIsProductionStatic() {
|
|
512
|
+
// TODO/now add @ts-ignore comments
|
|
513
|
+
// @ts-ignore
|
|
514
|
+
if (!import.meta.env)
|
|
515
|
+
return undefined;
|
|
516
|
+
// @ts-ignore
|
|
517
|
+
const PROD = import.meta.env.PROD;
|
|
518
|
+
return PROD;
|
|
519
|
+
}
|
|
520
|
+
function isProcessSharedWithVite() {
|
|
521
|
+
const ret = globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE;
|
|
522
|
+
if (globalObject.isProcessSharedWithVite !== undefined) {
|
|
523
|
+
assert(globalObject.isProcessSharedWithVite === ret);
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
globalObject.isProcessSharedWithVite = ret;
|
|
527
|
+
}
|
|
528
|
+
return ret;
|
|
529
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getViteDevScript };
|
|
2
|
+
import { getViteRPC } from '../../../../utils/getViteRPC.js';
|
|
2
3
|
import { assert, assertUsage, assertWarning } from '../../utils.js';
|
|
3
4
|
import pc from '@brillout/picocolors';
|
|
4
5
|
const reachOutCTA = 'Create a new GitHub issue to discuss a solution.';
|
|
@@ -11,7 +12,13 @@ async function getViteDevScript(pageContext) {
|
|
|
11
12
|
const fakeHtmlBegin = '<html> <head>'; // White space to test whether user is using a minifier
|
|
12
13
|
const fakeHtmlEnd = '</head><body></body></html>';
|
|
13
14
|
let fakeHtml = fakeHtmlBegin + fakeHtmlEnd;
|
|
14
|
-
|
|
15
|
+
if (viteDevServer) {
|
|
16
|
+
fakeHtml = await viteDevServer.transformIndexHtml('/', fakeHtml);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const rpc = getViteRPC();
|
|
20
|
+
fakeHtml = await rpc.transformIndexHtmlRPC(fakeHtml);
|
|
21
|
+
}
|
|
15
22
|
assertUsage(!fakeHtml.includes('vite-plugin-pwa'), `The HTML transformer of ${pc.cyan('vite-plugin-pwa')} cannot be applied, see workaround at https://github.com/vikejs/vike/issues/388#issuecomment-1199280084`);
|
|
16
23
|
assertUsage(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')), `Vite plugins that minify the HTML cannot be applied, see https://github.com/vikejs/vike/issues/224`);
|
|
17
24
|
assertUsage(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd), `You are using a Vite Plugin that transforms the HTML in a way that conflicts with Vike. ${reachOutCTA}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { injectAssets__public };
|
|
2
2
|
import { assertUsage, assertWarning, castProp, hasProp } from '../../utils.js';
|
|
3
3
|
import { injectHtmlTagsToString } from '../injectAssets.js';
|
|
4
|
-
//
|
|
4
|
+
// TO-DO/next-major-release: remove
|
|
5
5
|
async function injectAssets__public(htmlString, pageContext) {
|
|
6
6
|
assertWarning(false, '`_injectAssets()` is deprecated and will be removed.', { onlyOnce: true, showStackTrace: true });
|
|
7
7
|
assertUsage(typeof htmlString === 'string', '[injectAssets(htmlString, pageContext)]: Argument `htmlString` should be a string.', { showStackTrace: true });
|
|
@@ -149,6 +149,8 @@ function getTagClosing(tag) {
|
|
|
149
149
|
return tagClosing;
|
|
150
150
|
}
|
|
151
151
|
function injectAtPlaceholder(htmlFragment, htmlString, isFirst) {
|
|
152
|
+
// TO-DO/eventually: soft deprecate in favor of https://github.com/vikejs/vike/issues/695
|
|
153
|
+
// Used by BurdaForward https://github.com/vikejs/vike/discussions/2528#discussioncomment-13637156
|
|
152
154
|
const placeholder = isFirst ? '__VITE_PLUGIN_SSR__ASSETS_FIRST__' : '__VITE_PLUGIN__SSR_ASSETS_LAST__';
|
|
153
155
|
const parts = htmlString.split(placeholder);
|
|
154
156
|
if (parts.length === 1)
|
|
@@ -2,19 +2,25 @@ export { getPageContextClientSerialized };
|
|
|
2
2
|
export { getPageContextClientSerializedAbort };
|
|
3
3
|
export { getGlobalContextClientSerialized };
|
|
4
4
|
export type { PageContextSerialization };
|
|
5
|
+
export type { PassToClient };
|
|
5
6
|
import type { UrlRedirect } from '../../../shared/route/abort.js';
|
|
6
7
|
import type { GlobalContextServerInternal } from '../globalContext.js';
|
|
7
8
|
type PageContextSerialization = {
|
|
8
9
|
pageId: string;
|
|
9
10
|
routeParams: Record<string, string>;
|
|
10
|
-
_passToClient:
|
|
11
|
+
_passToClient: PassToClient;
|
|
11
12
|
is404: null | boolean;
|
|
12
13
|
pageProps?: Record<string, unknown>;
|
|
13
14
|
_pageContextInit: Record<string, unknown>;
|
|
14
15
|
_globalContext: GlobalContextServerInternal;
|
|
16
|
+
isClientSideNavigation: boolean;
|
|
15
17
|
};
|
|
16
18
|
declare function getPageContextClientSerialized(pageContext: PageContextSerialization): string;
|
|
17
19
|
declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization): string;
|
|
20
|
+
type PassToClient = (string | {
|
|
21
|
+
prop: string;
|
|
22
|
+
once?: boolean;
|
|
23
|
+
})[];
|
|
18
24
|
declare function getPageContextClientSerializedAbort(pageContext: Record<string, unknown> & ({
|
|
19
25
|
_urlRedirect: UrlRedirect;
|
|
20
26
|
} | {
|
|
@@ -27,20 +27,41 @@ const passToClientBuiltInPageContext = [
|
|
|
27
27
|
const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError];
|
|
28
28
|
function getPageContextClientSerialized(pageContext) {
|
|
29
29
|
const passToClientPageContext = getPassToClientPageContext(pageContext);
|
|
30
|
-
const
|
|
31
|
-
|
|
30
|
+
const getObj = (passToClientEntry) => {
|
|
31
|
+
if (passToClientEntry.once)
|
|
32
|
+
return undefined; // pass it to client-side globalContext
|
|
33
|
+
return { obj: pageContext, objName: 'pageContext' };
|
|
34
|
+
};
|
|
35
|
+
const res = applyPassToClient(passToClientPageContext, getObj);
|
|
36
|
+
const pageContextClient = res.objClient;
|
|
37
|
+
const pageContextClientProps = res.objClientProps;
|
|
38
|
+
if (pageContextClientProps.some((prop) => getPropVal(pageContext._pageContextInit, prop))) {
|
|
32
39
|
pageContextClient[pageContextInitIsPassedToClient] = true;
|
|
33
40
|
}
|
|
34
|
-
const pageContextClientSerialized = serializeObject(pageContextClient,
|
|
41
|
+
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, getObj);
|
|
35
42
|
return pageContextClientSerialized;
|
|
36
43
|
}
|
|
37
44
|
function getGlobalContextClientSerialized(pageContext) {
|
|
38
45
|
const passToClient = pageContext._passToClient;
|
|
39
|
-
const
|
|
40
|
-
const
|
|
46
|
+
const globalContext = pageContext._globalContext;
|
|
47
|
+
const getObj = ({ prop, once }) => {
|
|
48
|
+
if (once && getPropVal(pageContext, prop)) {
|
|
49
|
+
assert(typeof pageContext.isClientSideNavigation === 'boolean');
|
|
50
|
+
if (!pageContext.isClientSideNavigation) {
|
|
51
|
+
return { obj: pageContext, objName: 'pageContext' }; // pass it to client-side globalContext
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return undefined; // already passed to client-side
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { obj: globalContext, objName: 'globalContext' };
|
|
58
|
+
};
|
|
59
|
+
const res = applyPassToClient(passToClient, getObj);
|
|
60
|
+
const globalContextClient = res.objClient;
|
|
61
|
+
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, getObj);
|
|
41
62
|
return globalContextClientSerialized;
|
|
42
63
|
}
|
|
43
|
-
function serializeObject(obj,
|
|
64
|
+
function serializeObject(obj, passToClient, getObj) {
|
|
44
65
|
let serialized;
|
|
45
66
|
try {
|
|
46
67
|
serialized = serializeValue(obj);
|
|
@@ -49,11 +70,15 @@ function serializeObject(obj, objName, passToClient) {
|
|
|
49
70
|
const h = (s) => pc.cyan(s);
|
|
50
71
|
let hasWarned = false;
|
|
51
72
|
const propsNonSerializable = [];
|
|
52
|
-
passToClient.forEach((
|
|
73
|
+
passToClient.forEach((entry) => {
|
|
74
|
+
const entryNormalized = normalizePassToClientEntry(entry);
|
|
75
|
+
const { prop } = entryNormalized;
|
|
53
76
|
const res = getPropVal(obj, prop);
|
|
54
77
|
if (!res)
|
|
55
78
|
return;
|
|
56
79
|
const { value } = res;
|
|
80
|
+
const { objName } = getObj(entryNormalized) ?? {};
|
|
81
|
+
assert(objName);
|
|
57
82
|
const varName = `${objName}${getPropKeys(prop).map(getPropAccessNotation).join('')}`;
|
|
58
83
|
try {
|
|
59
84
|
serializeValue(value, varName);
|
|
@@ -103,7 +128,20 @@ function serializeObject(obj, objName, passToClient) {
|
|
|
103
128
|
return serialized;
|
|
104
129
|
}
|
|
105
130
|
function serializeValue(value, varName) {
|
|
106
|
-
return stringify(value, {
|
|
131
|
+
return stringify(value, {
|
|
132
|
+
forbidReactElements: true,
|
|
133
|
+
valueName: varName,
|
|
134
|
+
// Prevent Google from crawling URLs in JSON:
|
|
135
|
+
// - https://github.com/vikejs/vike/discussions/2541#discussioncomment-13660198
|
|
136
|
+
// - https://github.com/vikejs/vike/discussions/2277
|
|
137
|
+
// - https://github.com/vikejs/vike/pull/2542
|
|
138
|
+
replacer(_key, value) {
|
|
139
|
+
if (typeof value === 'string' && value.startsWith('/')) {
|
|
140
|
+
// No need to use a reviver: https://github.com/brillout/json-serializer/blob/70fc8ed3741306391b51655b05df24e6963d1fdb/test/main.spec.ts#L74-L80
|
|
141
|
+
return { replacement: (value = '!' + value) };
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
});
|
|
107
145
|
}
|
|
108
146
|
function getPassToClientPageContext(pageContext) {
|
|
109
147
|
let passToClient = [...pageContext._passToClient, ...passToClientBuiltInPageContext];
|
|
@@ -139,7 +177,7 @@ function getPageContextClientSerializedAbort(pageContext) {
|
|
|
139
177
|
assert(unknownProps.length === 0);
|
|
140
178
|
}
|
|
141
179
|
else {
|
|
142
|
-
//
|
|
180
|
+
// TO-DO/next-major-release: remove
|
|
143
181
|
assertWarning(unknownProps.length === 0, [
|
|
144
182
|
"The following pageContext values won't be available on the client-side:",
|
|
145
183
|
unknownProps.map((p) => ` pageContext[${JSON.stringify(p)}]`),
|
|
@@ -150,16 +188,36 @@ function getPageContextClientSerializedAbort(pageContext) {
|
|
|
150
188
|
}
|
|
151
189
|
return serializeValue(pageContext);
|
|
152
190
|
}
|
|
153
|
-
function applyPassToClient(passToClient,
|
|
154
|
-
const
|
|
155
|
-
|
|
191
|
+
function applyPassToClient(passToClient, getObj) {
|
|
192
|
+
const objClient = {};
|
|
193
|
+
const objClientProps = [];
|
|
194
|
+
passToClient.forEach((entry) => {
|
|
195
|
+
const entryNormalized = normalizePassToClientEntry(entry);
|
|
196
|
+
const { prop } = entryNormalized;
|
|
197
|
+
const { obj } = getObj(entryNormalized) ?? {};
|
|
198
|
+
if (!obj)
|
|
199
|
+
return;
|
|
156
200
|
// Get value from pageContext
|
|
157
|
-
const res = getPropVal(
|
|
201
|
+
const res = getPropVal(obj, prop);
|
|
158
202
|
if (!res)
|
|
159
203
|
return;
|
|
160
204
|
const { value } = res;
|
|
161
205
|
// Set value to pageContextClient
|
|
162
|
-
setPropVal(
|
|
206
|
+
setPropVal(objClient, prop, value);
|
|
207
|
+
objClientProps.push(prop);
|
|
163
208
|
});
|
|
164
|
-
return
|
|
209
|
+
return { objClient, objClientProps };
|
|
210
|
+
}
|
|
211
|
+
function normalizePassToClientEntry(entry) {
|
|
212
|
+
let once;
|
|
213
|
+
let prop;
|
|
214
|
+
if (typeof entry === 'string') {
|
|
215
|
+
prop = entry;
|
|
216
|
+
once = false;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
prop = entry.prop;
|
|
220
|
+
once = entry.once ?? false;
|
|
221
|
+
}
|
|
222
|
+
return { prop, once };
|
|
165
223
|
}
|
|
@@ -7,7 +7,7 @@ export { pipeWebStream, pipeNodeStream, pipeStream, stampPipe } from './html/str
|
|
|
7
7
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
8
8
|
export { getGlobalContext, getGlobalContextSync, getGlobalContextAsync } from './globalContext.js';
|
|
9
9
|
export { createDevMiddleware } from '../runtime-dev/index.js';
|
|
10
|
-
//
|
|
10
|
+
// TO-DO/next-major-release: remove
|
|
11
11
|
// Deprecated exports
|
|
12
12
|
export * from '../../types/index-dreprecated.js';
|
|
13
13
|
export { injectAssets__public as _injectAssets } from './html/injectAssets/injectAssets__public.js';
|
|
@@ -10,7 +10,7 @@ function assertArguments(...args) {
|
|
|
10
10
|
showStackTrace: true,
|
|
11
11
|
});
|
|
12
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
|
+
// TO-DO/next-major-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 });
|
|
16
16
|
pageContextInit.urlOriginal = pageContextInit.url;
|
|
@@ -28,6 +28,7 @@ declare function createHttpResponsePage(htmlRender: HtmlRender, renderHook: null
|
|
|
28
28
|
__getPageAssets: GetPageAssets;
|
|
29
29
|
_globalContext: GlobalContextServerInternal;
|
|
30
30
|
abortStatusCode?: AbortStatusCode;
|
|
31
|
+
headersResponse?: Headers;
|
|
31
32
|
}): Promise<HttpResponse>;
|
|
32
33
|
declare function createHttpResponse404(errMsg404: string): HttpResponse;
|
|
33
34
|
declare function createHttpResponseBaseIsMissing(urlOriginal: string, baseServer: string): HttpResponse;
|
|
@@ -9,8 +9,8 @@ import { assert, assertWarning, escapeHtml } from '../utils.js';
|
|
|
9
9
|
import { getErrorPageId, isErrorPage } from '../../../shared/error-page.js';
|
|
10
10
|
import { getHttpResponseBody, getHttpResponseBodyStreamHandlers } from './getHttpResponseBody.js';
|
|
11
11
|
import { getEarlyHints } from './getEarlyHints.js';
|
|
12
|
-
import { getCacheControl } from './createHttpResponse/getCacheControl.js';
|
|
13
12
|
import { assertNoInfiniteHttpRedirect } from './createHttpResponse/assertNoInfiniteHttpRedirect.js';
|
|
13
|
+
import { cacheControlDisable } from './getCacheControl.js';
|
|
14
14
|
async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
|
|
15
15
|
let statusCode = pageContext.abortStatusCode;
|
|
16
16
|
if (!statusCode) {
|
|
@@ -29,10 +29,13 @@ async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
|
|
|
29
29
|
}
|
|
30
30
|
const earlyHints = getEarlyHints(await pageContext.__getPageAssets());
|
|
31
31
|
const headers = [];
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
headers.push([
|
|
35
|
-
}
|
|
32
|
+
const headersResponse = pageContext.headersResponse || new Headers();
|
|
33
|
+
headersResponse.forEach((value, key) => {
|
|
34
|
+
headers.push([key, value]);
|
|
35
|
+
});
|
|
36
|
+
// An 5xx error page shouldn't be cached (it should be temporary)
|
|
37
|
+
if (statusCode >= 500)
|
|
38
|
+
headersResponse.set('Cache-Control', cacheControlDisable);
|
|
36
39
|
return createHttpResponse(statusCode, 'text/html;charset=utf-8', headers, htmlRender, earlyHints, renderHook);
|
|
37
40
|
}
|
|
38
41
|
function createHttpResponse404(errMsg404) {
|
|
@@ -102,7 +105,7 @@ function createHttpResponse(statusCode, contentType, headers, htmlRender, earlyH
|
|
|
102
105
|
return {
|
|
103
106
|
statusCode,
|
|
104
107
|
headers,
|
|
105
|
-
//
|
|
108
|
+
// TO-DO/next-major-release: remove
|
|
106
109
|
get contentType() {
|
|
107
110
|
assertWarning(false, 'pageContext.httpResponse.contentType is deprecated and will be removed in the next major release. Use pageContext.httpResponse.headers instead, see https://vike.dev/migration/0.4.134', { onlyOnce: true });
|
|
108
111
|
return contentType;
|