vike 0.4.236-commit-eab75f6 → 0.4.237-commit-85e89b1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/runtime-client-routing/globalContext.js +2 -2
- package/dist/cjs/client/runtime-server-routing/globalContext.js +2 -2
- package/dist/cjs/client/shared/createGetGlobalContextClient.js +5 -7
- package/dist/cjs/node/api/preview.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +4 -4
- package/dist/cjs/node/runtime/globalContext.js +21 -22
- package/dist/cjs/node/runtime/html/serializeContext.js +8 -47
- package/dist/cjs/node/runtime/html/stream.js +1 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +3 -3
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -4
- package/dist/cjs/node/runtime/renderPage/getPageAssets/{retrieveAssetsDev.js → retrievePageAssetsDev.js} +21 -6
- package/dist/cjs/node/runtime/renderPage/getPageAssets/{retrieveAssetsProd.js → retrievePageAssetsProd.js} +19 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +5 -34
- package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +50 -14
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +22 -9
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -3
- package/dist/cjs/node/runtime/renderPage.js +7 -6
- package/dist/cjs/node/shared/virtualFileId.js +110 -0
- package/dist/cjs/node/vite/index.js +3 -3
- package/dist/cjs/node/vite/onLoad.js +5 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +10 -10
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +20 -11
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildEntry.js +4 -4
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +4 -10
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +46 -44
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +5 -12
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +5 -5
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +5 -1
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +2 -6
- package/dist/cjs/node/vite/plugins/pluginPreview.js +11 -4
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +5 -12
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigsEager.js → generateVirtualFileGlobalEntry.js} +7 -9
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFileEntry.js → generateVirtualFileGlobalEntryWithOldDesign.js} +11 -11
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigLazy.js → generateVirtualFilePageEntry.js} +10 -12
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +67 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +14 -12
- package/dist/cjs/node/vite/shared/findPageFiles.js +1 -1
- package/dist/cjs/node/vite/shared/{resolveClientEntriesDev.js → getClientEntrySrcDev.js} +2 -2
- package/dist/cjs/node/vite/shared/getMagicString.js +1 -1
- package/dist/cjs/node/vite/shared/getOutDirs.js +18 -12
- package/dist/cjs/node/vite/shared/getViteConfigRuntime.js +1 -1
- package/dist/cjs/node/vite/shared/isViteServerBuild.js +54 -31
- package/dist/cjs/node/vite/shared/loggerVite.js +1 -1
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +8 -19
- package/dist/cjs/shared/createGlobalContextShared.js +23 -10
- package/dist/cjs/shared/getPageFiles/{parseVirtualFileExports.js → parseVirtualFileExportsGlobalEntry.js} +20 -26
- package/dist/cjs/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/cjs/shared/page-configs/loadPageEntry.js +25 -0
- package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +4 -4
- package/dist/cjs/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js} +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +15 -16
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/cast.js +1 -1
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +12 -12
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +35 -48
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/globalContext.js +2 -2
- package/dist/esm/client/runtime-client-routing/history.d.ts +3 -5
- package/dist/esm/client/runtime-client-routing/history.js +39 -22
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
- package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/prefetch.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/prefetch.js +2 -2
- package/dist/esm/client/runtime-client-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +4 -4
- package/dist/esm/client/runtime-client-routing/utils.d.ts +2 -0
- package/dist/esm/client/runtime-client-routing/utils.js +2 -0
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +3 -3
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +2 -2
- package/dist/esm/client/runtime-server-routing/globalContext.js +2 -2
- package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +3 -3
- package/dist/esm/client/shared/createGetGlobalContextClient.js +5 -7
- package/dist/esm/client/shared/execHookOnRenderClient.d.ts +2 -2
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +1 -1
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +4 -4
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +2 -2
- package/dist/esm/node/api/preview.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +9 -9
- package/dist/esm/node/prerender/runPrerender.js +4 -4
- package/dist/esm/node/runtime/globalContext.d.ts +10 -10
- package/dist/esm/node/runtime/globalContext.js +21 -22
- package/dist/esm/node/runtime/html/serializeContext.d.ts +8 -3
- package/dist/esm/node/runtime/html/serializeContext.js +8 -47
- package/dist/esm/node/runtime/html/stream.js +1 -1
- package/dist/esm/node/runtime/renderPage/analyzePage.js +3 -3
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -4
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrievePageAssetsDev.d.ts +10 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets/{retrieveAssetsDev.js → retrievePageAssetsDev.js} +22 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrievePageAssetsProd.d.ts +10 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets/{retrieveAssetsProd.js → retrievePageAssetsProd.js} +19 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +0 -6
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +4 -33
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +51 -15
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +25 -12
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +2 -3
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +10 -11
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -3
- package/dist/esm/node/runtime/renderPage.d.ts +3 -2
- package/dist/esm/node/runtime/renderPage.js +7 -6
- package/dist/esm/node/shared/virtualFileId.d.ts +28 -0
- package/dist/esm/node/shared/virtualFileId.js +107 -0
- package/dist/esm/node/vite/index.js +3 -3
- package/dist/esm/node/vite/onLoad.js +5 -3
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +2 -2
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +11 -11
- package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +1 -0
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +21 -12
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildEntry.js +4 -4
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +5 -8
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +47 -45
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +6 -10
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +4 -4
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +6 -2
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +2 -6
- package/dist/esm/node/vite/plugins/pluginPreview.js +13 -6
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +6 -10
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.d.ts +2 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigsEager.js → generateVirtualFileGlobalEntry.js} +7 -9
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.d.ts +6 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFileEntry.js → generateVirtualFileGlobalEntryWithOldDesign.js} +11 -11
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigLazy.js → generateVirtualFilePageEntry.js} +10 -12
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +14 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +65 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +14 -12
- package/dist/esm/node/vite/shared/findPageFiles.js +1 -1
- package/dist/esm/node/vite/shared/getClientEntrySrcDev.d.ts +4 -0
- package/dist/esm/node/vite/shared/{resolveClientEntriesDev.js → getClientEntrySrcDev.js} +2 -2
- package/dist/esm/node/vite/shared/getMagicString.js +1 -1
- package/dist/esm/node/vite/shared/getOutDirs.d.ts +6 -3
- package/dist/esm/node/vite/shared/getOutDirs.js +19 -13
- package/dist/esm/node/vite/shared/getViteConfigRuntime.js +1 -1
- package/dist/esm/node/vite/shared/isViteServerBuild.d.ts +14 -11
- package/dist/esm/node/vite/shared/isViteServerBuild.js +55 -31
- package/dist/esm/node/vite/shared/loggerVite.js +1 -1
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +3 -5
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +10 -21
- package/dist/esm/shared/createGlobalContextShared.d.ts +6 -6
- package/dist/esm/shared/createGlobalContextShared.js +25 -12
- package/dist/esm/shared/getPageFiles/{parseVirtualFileExports.d.ts → parseVirtualFileExportsGlobalEntry.d.ts} +2 -2
- package/dist/esm/shared/getPageFiles/{parseVirtualFileExports.js → parseVirtualFileExportsGlobalEntry.js} +20 -26
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/hooks/execHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/modifyUrlSameOrigin.d.ts +1 -1
- package/dist/esm/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/esm/shared/page-configs/loadPageEntry.d.ts +3 -0
- package/dist/esm/shared/page-configs/loadPageEntry.js +23 -0
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.d.ts +9 -9
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +4 -4
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +1 -1
- package/dist/esm/shared/page-configs/serialize/{parsePageConfigs.d.ts → parsePageConfigsSerialized.d.ts} +2 -2
- package/dist/esm/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js} +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +15 -16
- package/dist/esm/shared/utils.d.ts +2 -0
- package/dist/esm/shared/utils.js +2 -0
- package/dist/esm/types/Config.d.ts +33 -98
- package/dist/esm/types/PageConfig.d.ts +9 -7
- package/dist/esm/types/VikeNamespace.d.ts +13 -0
- package/dist/esm/types/index.d.ts +3 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/cast.d.ts +2 -2
- package/dist/esm/utils/cast.js +1 -1
- package/dist/esm/utils/objectFilter.d.ts +1 -1
- package/package.json +3 -3
- package/dist/cjs/node/shared/virtualFiles/virtualFileEntry.js +0 -31
- package/dist/cjs/node/shared/virtualFiles/virtualFilePageConfigLazy.js +0 -45
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -23
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +0 -11
- package/dist/cjs/shared/page-configs/loadConfigValues.js +0 -21
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.d.ts +0 -4
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +0 -4
- package/dist/esm/node/shared/virtualFiles/virtualFileEntry.d.ts +0 -11
- package/dist/esm/node/shared/virtualFiles/virtualFileEntry.js +0 -28
- package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.d.ts +0 -9
- package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.js +0 -43
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFileEntry.d.ts +0 -5
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.d.ts +0 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.d.ts +0 -7
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -21
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.d.ts +0 -3
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +0 -9
- package/dist/esm/node/vite/shared/resolveClientEntriesDev.d.ts +0 -4
- package/dist/esm/shared/page-configs/loadConfigValues.d.ts +0 -3
- package/dist/esm/shared/page-configs/loadConfigValues.js +0 -19
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadPageEntry = loadPageEntry;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
const parsePageConfigsSerialized_js_1 = require("./serialize/parsePageConfigsSerialized.js");
|
|
6
|
+
async function loadPageEntry(pageConfig, isDev) {
|
|
7
|
+
if ('isPageEntryLoaded' in pageConfig &&
|
|
8
|
+
// We don't need to cache in dev, since Vite already caches the virtual module
|
|
9
|
+
!isDev) {
|
|
10
|
+
return pageConfig;
|
|
11
|
+
}
|
|
12
|
+
const { moduleId, moduleExportsPromise } = pageConfig.loadVirtualFilePageEntry();
|
|
13
|
+
const virtualFileExportsPageEntry = await moduleExportsPromise;
|
|
14
|
+
// `configValuesLoaded` is sometimes `undefined` https://github.com/vikejs/vike/discussions/2092
|
|
15
|
+
if (!virtualFileExportsPageEntry)
|
|
16
|
+
(0, utils_js_1.assert)(false, { moduleExportsPromise, virtualFileExportsPageEntry, moduleId });
|
|
17
|
+
const configValues = parseVirtualFileExportsPageEntry(virtualFileExportsPageEntry);
|
|
18
|
+
Object.assign(pageConfig.configValues, configValues);
|
|
19
|
+
(0, utils_js_1.objectAssign)(pageConfig, { isPageEntryLoaded: true });
|
|
20
|
+
return pageConfig;
|
|
21
|
+
}
|
|
22
|
+
function parseVirtualFileExportsPageEntry(virtualFileExportsPageEntry) {
|
|
23
|
+
const configValues = (0, parsePageConfigsSerialized_js_1.parseConfigValuesSerialized)(virtualFileExportsPageEntry.configValuesSerialized);
|
|
24
|
+
return configValues;
|
|
25
|
+
}
|
|
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveVikeConfigPublicGlobal = resolveVikeConfigPublicGlobal;
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
7
|
+
exports.resolveVikeConfigPublicPageEagerLoaded = resolveVikeConfigPublicPageEagerLoaded;
|
|
8
|
+
exports.resolveVikeConfigPublicPageLazyLoaded = resolveVikeConfigPublicPageLazyLoaded;
|
|
9
9
|
const assert_exports_old_design_js_1 = require("../getPageFiles/assert_exports_old_design.js");
|
|
10
10
|
const getConfigDefinedAt_js_1 = require("./getConfigDefinedAt.js");
|
|
11
11
|
const helpers_js_1 = require("./helpers.js");
|
|
12
12
|
const utils_js_1 = require("../utils.js");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
|
-
function
|
|
14
|
+
function resolveVikeConfigPublicPageEagerLoaded(pageConfigGlobalValues, pageConfig, pageConfigValues) {
|
|
15
15
|
const vikeConfigPublicPage_ = resolveVikeConfigPublic_base({ pageConfigGlobalValues, pageConfigValues });
|
|
16
16
|
const vikeConfigPublicPage = getPublicCopy(vikeConfigPublicPage_);
|
|
17
17
|
let page;
|
|
@@ -46,7 +46,7 @@ function resolveVikeConfigPublicGlobal({ pageConfigGlobalValues, }) {
|
|
|
46
46
|
const vikeConfigPublicGlobal = resolveVikeConfigPublic_V1Design({ configValues: pageConfigGlobalValues });
|
|
47
47
|
return getPublicCopy(vikeConfigPublicGlobal);
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function resolveVikeConfigPublicPageLazyLoaded(pageFiles, // V0.4 design
|
|
50
50
|
pageConfig, // V1 design
|
|
51
51
|
pageConfigGlobal) {
|
|
52
52
|
const config = {};
|
package/dist/cjs/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js}
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parsePageConfigsSerialized = parsePageConfigsSerialized;
|
|
4
4
|
exports.parseConfigValuesSerialized = parseConfigValuesSerialized;
|
|
5
5
|
const utils_js_1 = require("../../utils.js");
|
|
6
6
|
const getConfigDefinedAt_js_1 = require("../getConfigDefinedAt.js");
|
|
7
7
|
const parse_1 = require("@brillout/json-serializer/parse");
|
|
8
8
|
const assertPlusFileExport_js_1 = require("../assertPlusFileExport.js");
|
|
9
|
-
function
|
|
9
|
+
function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
10
10
|
// pageConfigs
|
|
11
11
|
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
12
12
|
const configValues = parseConfigValuesSerialized(pageConfigSerialized.configValuesSerialized);
|
|
@@ -12,19 +12,19 @@ const pointerImports_js_1 = require("../../../node/vite/shared/resolveVikeConfig
|
|
|
12
12
|
const helpers_js_1 = require("../helpers.js");
|
|
13
13
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
14
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
15
|
-
const
|
|
15
|
+
const getConfigValueSourcesRelevant_js_1 = require("../../../node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js");
|
|
16
16
|
const stringifyOptions = { forbidReactElements: true };
|
|
17
17
|
const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
|
|
18
18
|
const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
19
|
-
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with
|
|
20
|
-
// - vike/shared/page-configs/serialize/
|
|
21
|
-
// -
|
|
19
|
+
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with parsePageConfigsSerialized()
|
|
20
|
+
// - vike/shared/page-configs/serialize/parsePageConfigsSerialized.ts
|
|
21
|
+
// - parsePageConfigsSerialized() is loaded on both the client- and server-side.
|
|
22
22
|
(0, utils_js_1.assertIsNotBrowser)();
|
|
23
23
|
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
24
|
-
function serializeConfigValues(pageConfig, importStatements, filesEnv,
|
|
24
|
+
function serializeConfigValues(pageConfig, importStatements, filesEnv, runtimeEnv, tabspace, isEager) {
|
|
25
25
|
const lines = [];
|
|
26
26
|
tabspace += ' ';
|
|
27
|
-
getConfigValuesBase(pageConfig,
|
|
27
|
+
getConfigValuesBase(pageConfig, runtimeEnv, isEager).forEach((entry) => {
|
|
28
28
|
if (entry.configValueBase.type === 'computed') {
|
|
29
29
|
(0, utils_js_1.assert)('value' in entry); // Help TS
|
|
30
30
|
const { configValueBase, value, configName, configEnv } = entry;
|
|
@@ -181,12 +181,12 @@ function logJsonSerializeError(err, configName, definedAtData) {
|
|
|
181
181
|
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
182
182
|
(0, utils_js_1.assertUsage)(false, `${picocolors_1.default.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined using a separate file ${picocolors_1.default.bold(`+${configName}.js`)}, see https://vike.dev/error/runtime-in-config`);
|
|
183
183
|
}
|
|
184
|
-
function getConfigValuesBase(pageConfig,
|
|
184
|
+
function getConfigValuesBase(pageConfig, runtimeEnv, isEager) {
|
|
185
185
|
const fromComputed = Object.entries(pageConfig.configValuesComputed ?? {}).map(([configName, valueInfo]) => {
|
|
186
186
|
const { configEnv, value } = valueInfo;
|
|
187
|
-
if (!
|
|
187
|
+
if (!(0, getConfigValueSourcesRelevant_js_1.isRuntimeEnvMatch)(configEnv, runtimeEnv))
|
|
188
188
|
return 'SKIP';
|
|
189
|
-
//
|
|
189
|
+
// AFAICT this should never happen: I ain't aware of a use case for overriding computed values. If there is a use case, then configValueSources has higher precedence.
|
|
190
190
|
if (pageConfig.configValueSources[configName])
|
|
191
191
|
return 'SKIP';
|
|
192
192
|
const configValueBase = {
|
|
@@ -195,16 +195,17 @@ function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
|
|
|
195
195
|
};
|
|
196
196
|
return { configValueBase, value, configName, configEnv };
|
|
197
197
|
});
|
|
198
|
-
const fromSources = Object.entries(pageConfig.configValueSources).map(([configName
|
|
198
|
+
const fromSources = Object.entries(pageConfig.configValueSources).map(([configName]) => {
|
|
199
199
|
const configDef = pageConfig.configDefinitions[configName];
|
|
200
200
|
(0, utils_js_1.assert)(configDef);
|
|
201
201
|
if (isEager !== null && isEager !== !!configDef.eager)
|
|
202
202
|
return 'SKIP';
|
|
203
203
|
if (!configDef.cumulative) {
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
if (!
|
|
204
|
+
const sourcesRelevant = (0, getConfigValueSourcesRelevant_js_1.getConfigValueSourcesRelevant)(configName, runtimeEnv, pageConfig);
|
|
205
|
+
const source = sourcesRelevant[0];
|
|
206
|
+
if (!source)
|
|
207
207
|
return 'SKIP';
|
|
208
|
+
(0, utils_js_1.assert)(sourcesRelevant.length === 1);
|
|
208
209
|
const definedAtFile = getDefinedAtFileSource(source);
|
|
209
210
|
const configValueBase = {
|
|
210
211
|
type: 'standard',
|
|
@@ -213,9 +214,7 @@ function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
|
|
|
213
214
|
return { configValueBase, sourceRelevant: source, configName };
|
|
214
215
|
}
|
|
215
216
|
else {
|
|
216
|
-
const sourcesRelevant =
|
|
217
|
-
.filter((source) => !(0, resolveVikeConfigInternal_js_1.isOverridden)(source, configName, pageConfig))
|
|
218
|
-
.filter((source) => isEnvMatch(source.configEnv));
|
|
217
|
+
const sourcesRelevant = (0, getConfigValueSourcesRelevant_js_1.getConfigValueSourcesRelevant)(configName, runtimeEnv, pageConfig);
|
|
219
218
|
if (sourcesRelevant.length === 0)
|
|
220
219
|
return 'SKIP';
|
|
221
220
|
const definedAtData = [];
|
package/dist/cjs/shared/utils.js
CHANGED
|
@@ -45,3 +45,5 @@ __exportStar(require("../utils/objectDefineProperty.js"), exports);
|
|
|
45
45
|
__exportStar(require("../utils/isScriptFile.js"), exports);
|
|
46
46
|
__exportStar(require("../utils/objectFilter.js"), exports);
|
|
47
47
|
__exportStar(require("../utils/getPropAccessNotation.js"), exports);
|
|
48
|
+
__exportStar(require("../utils/getGlobalObject.js"), exports);
|
|
49
|
+
__exportStar(require("../utils/genPromise.js"), exports);
|
package/dist/cjs/utils/cast.js
CHANGED
|
@@ -10,7 +10,7 @@ declare function createPageContextClientSide(urlOriginal: string): Promise<{
|
|
|
10
10
|
_globalContext: {
|
|
11
11
|
isGlobalContext: true;
|
|
12
12
|
_isOriginalObject: true;
|
|
13
|
-
|
|
13
|
+
_virtualFileExportsGlobalEntry: unknown;
|
|
14
14
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
15
15
|
_pageConfigs: import("../../types/PageConfig.js").PageConfigRuntime[];
|
|
16
16
|
_pageConfigGlobal: import("../../types/PageConfig.js").PageConfigGlobalRuntime;
|
|
@@ -23,7 +23,7 @@ declare function createPageContextClientSide(urlOriginal: string): Promise<{
|
|
|
23
23
|
};
|
|
24
24
|
config: import("../../types/index.js").ConfigResolved;
|
|
25
25
|
pages: {
|
|
26
|
-
[k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").
|
|
26
|
+
[k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEagerLoaded;
|
|
27
27
|
};
|
|
28
28
|
} & {
|
|
29
29
|
isClientSide: true;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { setPageContextCurrent };
|
|
2
2
|
export { getPageContextCurrent };
|
|
3
|
-
import type {
|
|
4
|
-
type PageContextCurrent =
|
|
3
|
+
import type { VikeConfigPublicPageLazyLoaded } from '../../shared/getPageFiles.js';
|
|
4
|
+
type PageContextCurrent = VikeConfigPublicPageLazyLoaded & {
|
|
5
5
|
urlPathname: string;
|
|
6
6
|
};
|
|
7
7
|
declare function getPageContextCurrent(): null | PageContextCurrent;
|
|
@@ -5,7 +5,7 @@ export { getPageContextFromClientHooks };
|
|
|
5
5
|
export { setPageContextInitIsPassedToClient };
|
|
6
6
|
export { execHookClient };
|
|
7
7
|
export type { PageContextFromServerHooks };
|
|
8
|
-
import type {
|
|
8
|
+
import type { VikeConfigPublicPageLazyLoaded, PageFile } from '../../shared/getPageFiles.js';
|
|
9
9
|
import type { HookName } from '../../types/Config.js';
|
|
10
10
|
import type { PageContextCreated } from './createPageContextClientSide.js';
|
|
11
11
|
import type { PageContextBegin } from './renderPageClientSide.js';
|
|
@@ -18,7 +18,7 @@ declare function getPageContextFromHooks_serialized(): PageContextSerialized & {
|
|
|
18
18
|
routeParams: Record<string, string>;
|
|
19
19
|
_hasPageContextFromServer: true;
|
|
20
20
|
};
|
|
21
|
-
declare function getPageContextFromHooks_isHydration(pageContext: PageContextSerialized & PageContextBegin &
|
|
21
|
+
declare function getPageContextFromHooks_isHydration(pageContext: PageContextSerialized & PageContextBegin & VikeConfigPublicPageLazyLoaded & {
|
|
22
22
|
_hasPageContextFromServer: true;
|
|
23
23
|
} & PageContextForPublicUsageClient): Promise<PageContextSerialized & {
|
|
24
24
|
_isOriginalObject: true;
|
|
@@ -30,7 +30,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
|
|
|
30
30
|
_globalContext: {
|
|
31
31
|
isGlobalContext: true;
|
|
32
32
|
_isOriginalObject: true;
|
|
33
|
-
|
|
33
|
+
_virtualFileExportsGlobalEntry: unknown;
|
|
34
34
|
_pageFilesAll: PageFile[];
|
|
35
35
|
_pageConfigs: import("../../types/PageConfig.js").PageConfigRuntime[];
|
|
36
36
|
_pageConfigGlobal: import("../../types/PageConfig.js").PageConfigGlobalRuntime;
|
|
@@ -43,7 +43,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
|
|
|
43
43
|
};
|
|
44
44
|
config: import("../../types/index.js").ConfigResolved;
|
|
45
45
|
pages: {
|
|
46
|
-
[k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").
|
|
46
|
+
[k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEagerLoaded;
|
|
47
47
|
};
|
|
48
48
|
} & {
|
|
49
49
|
isClientSide: true;
|
|
@@ -70,7 +70,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
|
|
|
70
70
|
isHydration: boolean;
|
|
71
71
|
previousPageContext: ({
|
|
72
72
|
pageId: string;
|
|
73
|
-
} &
|
|
73
|
+
} & VikeConfigPublicPageLazyLoaded & {
|
|
74
74
|
pageId: string;
|
|
75
75
|
routeParams: Record<string, string>;
|
|
76
76
|
} & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & import("../../types/PageContext.js").PageContextInternalClient & Omit<Partial<{
|
|
@@ -144,7 +144,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
|
|
|
144
144
|
} & {
|
|
145
145
|
urlOriginal: string;
|
|
146
146
|
}) | null;
|
|
147
|
-
} &
|
|
147
|
+
} & VikeConfigPublicPageLazyLoaded & {
|
|
148
148
|
_hasPageContextFromServer: true;
|
|
149
149
|
} & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & Omit<Partial<{
|
|
150
150
|
isPageContext: true;
|
|
@@ -231,7 +231,7 @@ declare function getPageContextFromServerHooks(pageContext: {
|
|
|
231
231
|
declare function getPageContextFromClientHooks(pageContext: {
|
|
232
232
|
pageId: string;
|
|
233
233
|
_hasPageContextFromServer: boolean;
|
|
234
|
-
} & PageContextBegin &
|
|
234
|
+
} & PageContextBegin & VikeConfigPublicPageLazyLoaded & PageContextForPublicUsageClient, isErrorPage: boolean): Promise<{
|
|
235
235
|
pageId: string;
|
|
236
236
|
_hasPageContextFromServer: boolean;
|
|
237
237
|
} & {
|
|
@@ -244,7 +244,7 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
244
244
|
_globalContext: {
|
|
245
245
|
isGlobalContext: true;
|
|
246
246
|
_isOriginalObject: true;
|
|
247
|
-
|
|
247
|
+
_virtualFileExportsGlobalEntry: unknown;
|
|
248
248
|
_pageFilesAll: PageFile[];
|
|
249
249
|
_pageConfigs: import("../../types/PageConfig.js").PageConfigRuntime[];
|
|
250
250
|
_pageConfigGlobal: import("../../types/PageConfig.js").PageConfigGlobalRuntime;
|
|
@@ -257,7 +257,7 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
257
257
|
};
|
|
258
258
|
config: import("../../types/index.js").ConfigResolved;
|
|
259
259
|
pages: {
|
|
260
|
-
[k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").
|
|
260
|
+
[k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEagerLoaded;
|
|
261
261
|
};
|
|
262
262
|
} & {
|
|
263
263
|
isClientSide: true;
|
|
@@ -284,7 +284,7 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
284
284
|
isHydration: boolean;
|
|
285
285
|
previousPageContext: ({
|
|
286
286
|
pageId: string;
|
|
287
|
-
} &
|
|
287
|
+
} & VikeConfigPublicPageLazyLoaded & {
|
|
288
288
|
pageId: string;
|
|
289
289
|
routeParams: Record<string, string>;
|
|
290
290
|
} & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & import("../../types/PageContext.js").PageContextInternalClient & Omit<Partial<{
|
|
@@ -358,7 +358,7 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
358
358
|
} & {
|
|
359
359
|
urlOriginal: string;
|
|
360
360
|
}) | null;
|
|
361
|
-
} &
|
|
361
|
+
} & VikeConfigPublicPageLazyLoaded & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & Omit<Partial<{
|
|
362
362
|
isPageContext: true;
|
|
363
363
|
Page: import("../../types/Config.js").Config["Page"];
|
|
364
364
|
routeParams: Record<string, string>;
|
|
@@ -429,7 +429,7 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
429
429
|
} & {
|
|
430
430
|
urlOriginal: string;
|
|
431
431
|
}>;
|
|
432
|
-
type PageContextExecHookClient =
|
|
432
|
+
type PageContextExecHookClient = VikeConfigPublicPageLazyLoaded & PageContextForPublicUsageClient;
|
|
433
433
|
declare function execHookClient(hookName: HookName, pageContext: PageContextExecHookClient): Promise<(import("../../shared/hooks/getHook.js").HookLoc & {
|
|
434
434
|
hookFn: (arg: import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum | import("../../shared/prepareGlobalContextForPublicUsage.js").GlobalContextPrepareMinimum) => unknown;
|
|
435
435
|
hookTimeout: import("../../shared/hooks/getHook.js").HookTimeout;
|
|
@@ -23,7 +23,6 @@ const globalObject = getGlobalObject('runtime-client-routing/getPageContextFromH
|
|
|
23
23
|
// TO-DO/eventually: rename
|
|
24
24
|
function getPageContextFromHooks_serialized() {
|
|
25
25
|
const pageContextSerialized = getPageContextSerializedInHtml();
|
|
26
|
-
assertUsage(!('urlOriginal' in pageContextSerialized), "Adding 'urlOriginal' to passToClient is forbidden");
|
|
27
26
|
processPageContextFromServer(pageContextSerialized);
|
|
28
27
|
objectAssign(pageContextSerialized, {
|
|
29
28
|
_hasPageContextFromServer: true,
|
|
@@ -33,6 +32,9 @@ function getPageContextFromHooks_serialized() {
|
|
|
33
32
|
// TO-DO/eventually: rename
|
|
34
33
|
async function getPageContextFromHooks_isHydration(pageContext) {
|
|
35
34
|
for (const hookName of ['data', 'onBeforeRender']) {
|
|
35
|
+
// TO-DO/soon/cumulative-hooks: filter & execute all client-only hooks
|
|
36
|
+
// - The client-side needs to know what hooks are client-only
|
|
37
|
+
// - Possible implementation: new computed prop `clientOnlyHooks: string[]` (list of hook ids) and add `hookId` to serialized config values
|
|
36
38
|
if (hookClientOnlyExists(hookName, pageContext)) {
|
|
37
39
|
await execHookDataLike(hookName, pageContext);
|
|
38
40
|
}
|
|
@@ -65,7 +67,7 @@ async function getPageContextFromServerHooks(pageContext, isErrorPage) {
|
|
|
65
67
|
return { pageContextFromServerHooks };
|
|
66
68
|
}
|
|
67
69
|
async function getPageContextFromClientHooks(pageContext, isErrorPage) {
|
|
68
|
-
let
|
|
70
|
+
let dataHookExecuted = false;
|
|
69
71
|
// At this point, we need to call the client-side guard(), data() and onBeforeRender() hooks, if they exist on client
|
|
70
72
|
// env. However if we have fetched pageContext from the server, some of them might have run already on the
|
|
71
73
|
// server-side, so we run only the client-only ones in this case.
|
|
@@ -82,9 +84,10 @@ async function getPageContextFromClientHooks(pageContext, isErrorPage) {
|
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
else {
|
|
87
|
+
// TO-DO/soon/cumulative-hooks: filter & execute all client-only hooks (see other TO-DO/soon/cumulative-hooks entries)
|
|
85
88
|
if (hookClientOnlyExists(hookName, pageContext) || !pageContext._hasPageContextFromServer) {
|
|
86
89
|
if (hookName === 'data')
|
|
87
|
-
|
|
90
|
+
dataHookExecuted = true;
|
|
88
91
|
// This won't do anything if no hook has been defined or if the hook's env.client is false.
|
|
89
92
|
await execHookDataLike(hookName, pageContext);
|
|
90
93
|
}
|
|
@@ -92,7 +95,7 @@ async function getPageContextFromClientHooks(pageContext, isErrorPage) {
|
|
|
92
95
|
}
|
|
93
96
|
// Execute +onData
|
|
94
97
|
const dataHookEnv = getHookEnv('data', pageContext);
|
|
95
|
-
if ((
|
|
98
|
+
if ((dataHookExecuted && dataHookEnv.client) || (pageContext._hasPageContextFromServer && dataHookEnv.server)) {
|
|
96
99
|
await execHookClient('onData', pageContext);
|
|
97
100
|
}
|
|
98
101
|
const pageContextFromClientHooks = pageContext;
|
|
@@ -154,61 +157,40 @@ function setPageContextInitIsPassedToClient(pageContext) {
|
|
|
154
157
|
}
|
|
155
158
|
// TO-DO/next-major-release: make it sync
|
|
156
159
|
async function hasPageContextServer(pageContext) {
|
|
157
|
-
|
|
158
|
-
(await hookServerOnlyExists('data', pageContext)) ||
|
|
159
|
-
(await hookServerOnlyExists('onBeforeRender', pageContext)));
|
|
160
|
-
}
|
|
161
|
-
// TO-DO/next-major-release: make it sync
|
|
162
|
-
/**
|
|
163
|
-
* @param hookName
|
|
164
|
-
* @param pageContext
|
|
165
|
-
* @returns `true` if the given page has a `hookName` hook defined with a server-only env.
|
|
166
|
-
*/
|
|
167
|
-
async function hookServerOnlyExists(hookName, pageContext) {
|
|
168
|
-
if (pageContext._globalContext._pageConfigs.length > 0) {
|
|
169
|
-
// V1
|
|
170
|
-
const pageConfig = getPageConfig(pageContext.pageId, pageContext._globalContext._pageConfigs);
|
|
171
|
-
const hookEnv = getConfigValueRuntime(pageConfig, `${hookName}Env`)?.value;
|
|
172
|
-
if (hookEnv === null)
|
|
173
|
-
return false;
|
|
174
|
-
assert(isObject(hookEnv));
|
|
175
|
-
const { client, server } = hookEnv;
|
|
176
|
-
assert(client === true || client === undefined);
|
|
177
|
-
assert(server === true || server === undefined);
|
|
178
|
-
assert(client || server);
|
|
179
|
-
return !!server && !client;
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
// TO-DO/next-major-release: remove
|
|
183
|
-
// V0.4
|
|
184
|
-
// data() hooks didn't exist in the V0.4 design
|
|
185
|
-
if (hookName === 'data')
|
|
186
|
-
return false;
|
|
187
|
-
assert(hookName === 'onBeforeRender');
|
|
160
|
+
if (isOldDesign(pageContext)) {
|
|
188
161
|
const { hasOnBeforeRenderServerSideOnlyHook } = await analyzePageServerSide(pageContext._pageFilesAll, pageContext.pageId);
|
|
162
|
+
// data() hooks didn't exist in the V0.4 design
|
|
189
163
|
return hasOnBeforeRenderServerSideOnlyHook;
|
|
190
164
|
}
|
|
165
|
+
return !!globalObject.pageContextInitIsPassedToClient || hasServerOnlyHook(pageContext);
|
|
166
|
+
}
|
|
167
|
+
function hasServerOnlyHook(pageContext) {
|
|
168
|
+
if (isOldDesign(pageContext))
|
|
169
|
+
return false;
|
|
170
|
+
const pageConfig = getPageConfig(pageContext.pageId, pageContext._globalContext._pageConfigs);
|
|
171
|
+
const val = getConfigValueRuntime(pageConfig, `serverOnlyHooks`)?.value;
|
|
172
|
+
assert(val === true || val === false);
|
|
173
|
+
return val;
|
|
191
174
|
}
|
|
192
175
|
function hookClientOnlyExists(hookName, pageContext) {
|
|
193
176
|
const hookEnv = getHookEnv(hookName, pageContext);
|
|
194
177
|
return !!hookEnv.client && !hookEnv.server;
|
|
195
178
|
}
|
|
196
179
|
function getHookEnv(hookName, pageContext) {
|
|
197
|
-
if (pageContext
|
|
198
|
-
// V1
|
|
199
|
-
const pageConfig = getPageConfig(pageContext.pageId, pageContext._globalContext._pageConfigs);
|
|
200
|
-
// No runtime validation to save client-side KBs
|
|
201
|
-
const hookEnv = (getConfigValueRuntime(pageConfig, `${hookName}Env`)?.value ?? {});
|
|
202
|
-
return hookEnv;
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
// TO-DO/next-major-release: remove
|
|
180
|
+
if (isOldDesign(pageContext)) {
|
|
206
181
|
// Client-only onBeforeRender() or data() hooks were never supported for the V0.4 design
|
|
207
182
|
return { client: false, server: true };
|
|
208
183
|
}
|
|
184
|
+
const pageConfig = getPageConfig(pageContext.pageId, pageContext._globalContext._pageConfigs);
|
|
185
|
+
// No runtime validation to save client-side KBs
|
|
186
|
+
const hookEnv = (getConfigValueRuntime(pageConfig, `${hookName}Env`)?.value ?? {});
|
|
187
|
+
return hookEnv;
|
|
209
188
|
}
|
|
210
189
|
async function fetchPageContextFromServer(pageContext) {
|
|
211
|
-
|
|
190
|
+
let pageContextUrl = getPageContextRequestUrl(pageContext._urlRewrite ?? pageContext.urlOriginal);
|
|
191
|
+
/* TO-DO/soon/once: pass & use previousUrl
|
|
192
|
+
pageContextUrl = modifyUrlSameOrigin(pageContextUrl, { search: { _vike: JSON.stringify({ previousUrl: pageContext.previousPageContext.urlOriginal }) } })
|
|
193
|
+
*/
|
|
212
194
|
const response = await fetch(pageContextUrl);
|
|
213
195
|
{
|
|
214
196
|
const contentType = response.headers.get('content-type');
|
|
@@ -231,10 +213,15 @@ async function fetchPageContextFromServer(pageContext) {
|
|
|
231
213
|
if ('serverSideError' in pageContextFromServer || isServerSideError in pageContextFromServer) {
|
|
232
214
|
throw getProjectError(`pageContext couldn't be fetched because an error occurred on the server-side`);
|
|
233
215
|
}
|
|
234
|
-
assert(hasProp(pageContextFromServer, 'pageId', 'string'));
|
|
235
216
|
processPageContextFromServer(pageContextFromServer);
|
|
236
217
|
return { pageContextFromServer };
|
|
237
218
|
}
|
|
238
|
-
function processPageContextFromServer(
|
|
239
|
-
|
|
219
|
+
function processPageContextFromServer(pageContext) {
|
|
220
|
+
assertUsage(!('urlOriginal' in pageContext), "Adding 'urlOriginal' to passToClient is forbidden");
|
|
221
|
+
assert(hasProp(pageContext, 'pageId', 'string'));
|
|
222
|
+
removeBuiltInOverrides(pageContext);
|
|
223
|
+
}
|
|
224
|
+
// TO-DO/next-major-release: remove
|
|
225
|
+
function isOldDesign(pageContext) {
|
|
226
|
+
return pageContext._globalContext._pageConfigs.length === 0;
|
|
240
227
|
}
|
|
@@ -7,7 +7,7 @@ type GlobalContextClientInternal = Awaited<ReturnType<typeof getGlobalContextCli
|
|
|
7
7
|
declare const getGlobalContextClientInternal: () => Promise<{
|
|
8
8
|
isGlobalContext: true;
|
|
9
9
|
_isOriginalObject: true;
|
|
10
|
-
|
|
10
|
+
_virtualFileExportsGlobalEntry: unknown;
|
|
11
11
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
12
12
|
_pageConfigs: import("../../types/PageConfig.js").PageConfigRuntime[];
|
|
13
13
|
_pageConfigGlobal: import("../../types/PageConfig.js").PageConfigGlobalRuntime;
|
|
@@ -20,7 +20,7 @@ declare const getGlobalContextClientInternal: () => Promise<{
|
|
|
20
20
|
};
|
|
21
21
|
config: import("../../types/index.js").ConfigResolved;
|
|
22
22
|
pages: {
|
|
23
|
-
[k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").
|
|
23
|
+
[k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEagerLoaded;
|
|
24
24
|
};
|
|
25
25
|
} & {
|
|
26
26
|
isClientSide: true;
|
|
@@ -2,8 +2,8 @@ export { getGlobalContextClientInternal };
|
|
|
2
2
|
import { createGetGlobalContextClient } from '../shared/createGetGlobalContextClient.js';
|
|
3
3
|
import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
|
|
4
4
|
// @ts-ignore
|
|
5
|
-
import * as
|
|
6
|
-
const getGlobalContextClientInternal = createGetGlobalContextClient(
|
|
5
|
+
import * as virtualFileExportsGlobalEntry from 'virtual:vike:global-entry:client:client-routing';
|
|
6
|
+
const getGlobalContextClientInternal = createGetGlobalContextClient(virtualFileExportsGlobalEntry, true, addGlobalContext);
|
|
7
7
|
async function addGlobalContext(globalContext) {
|
|
8
8
|
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
9
9
|
return {
|
|
@@ -2,8 +2,7 @@ export { pushHistoryState };
|
|
|
2
2
|
export { replaceHistoryStateOriginal };
|
|
3
3
|
export { onPopStateBegin };
|
|
4
4
|
export { saveScrollPosition };
|
|
5
|
-
export {
|
|
6
|
-
export { monkeyPatchHistoryAPI };
|
|
5
|
+
export { initHistory };
|
|
7
6
|
export type { HistoryInfo };
|
|
8
7
|
export type { ScrollPosition };
|
|
9
8
|
type StateEnhanced = {
|
|
@@ -18,8 +17,7 @@ type ScrollPosition = {
|
|
|
18
17
|
};
|
|
19
18
|
declare function saveScrollPosition(): void;
|
|
20
19
|
declare function pushHistoryState(url: string, overwriteLastHistoryEntry: boolean): void;
|
|
21
|
-
declare function replaceHistoryStateOriginal(state: unknown, url:
|
|
22
|
-
declare function monkeyPatchHistoryAPI(): void;
|
|
20
|
+
declare function replaceHistoryStateOriginal(state: unknown, url: Parameters<typeof window.history.replaceState>[2]): void;
|
|
23
21
|
type HistoryInfo = {
|
|
24
22
|
url: `/${string}`;
|
|
25
23
|
state: StateEnhanced;
|
|
@@ -29,4 +27,4 @@ declare function onPopStateBegin(): {
|
|
|
29
27
|
previous: HistoryInfo;
|
|
30
28
|
current: HistoryInfo;
|
|
31
29
|
};
|
|
32
|
-
declare function
|
|
30
|
+
declare function initHistory(): void;
|
|
@@ -2,21 +2,23 @@ export { pushHistoryState };
|
|
|
2
2
|
export { replaceHistoryStateOriginal };
|
|
3
3
|
export { onPopStateBegin };
|
|
4
4
|
export { saveScrollPosition };
|
|
5
|
-
export {
|
|
6
|
-
export { monkeyPatchHistoryAPI };
|
|
5
|
+
export { initHistory };
|
|
7
6
|
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
8
|
-
import { assert, assertUsage, getGlobalObject, isObject } from './utils.js';
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import { assert, assertUsage, getGlobalObject, isObject, deepEqual, cast } from './utils.js';
|
|
8
|
+
const globalObject = getGlobalObject('history.ts', {
|
|
9
|
+
monkeyPatched: false,
|
|
10
|
+
previous: undefined,
|
|
11
|
+
});
|
|
12
|
+
initHistory(); // we redundantly call initHistory() to ensure it's called early
|
|
13
|
+
globalObject.previous = getHistoryInfo();
|
|
11
14
|
// `window.history.state === null` when:
|
|
12
15
|
// - The very first render
|
|
13
16
|
// - Click on `<a href="#some-hash" />`
|
|
14
17
|
// - `location.hash = 'some-hash'`
|
|
15
18
|
function enhanceHistoryState() {
|
|
16
|
-
|
|
17
|
-
if (isVikeEnhanced(stateNotEnhanced))
|
|
19
|
+
if (isVikeEnhanced(window.history.state))
|
|
18
20
|
return;
|
|
19
|
-
const stateVikeEnhanced = enhance(
|
|
21
|
+
const stateVikeEnhanced = enhance(window.history.state);
|
|
20
22
|
replaceHistoryState(stateVikeEnhanced);
|
|
21
23
|
}
|
|
22
24
|
function enhance(stateNotEnhanced) {
|
|
@@ -34,6 +36,7 @@ function enhance(stateNotEnhanced) {
|
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
36
38
|
// State information may be incomplete if `window.history.state` is set by an old Vike version. (E.g. `state.timestamp` was introduced for `pageContext.isBackwardNavigation` in `0.4.19`.)
|
|
39
|
+
cast(stateNotEnhanced);
|
|
37
40
|
stateVikeEnhanced = {
|
|
38
41
|
timestamp: stateNotEnhanced.timestamp ?? timestamp,
|
|
39
42
|
scrollPosition: stateNotEnhanced.scrollPosition ?? scrollPosition,
|
|
@@ -41,21 +44,17 @@ function enhance(stateNotEnhanced) {
|
|
|
41
44
|
_isVikeEnhanced: true,
|
|
42
45
|
};
|
|
43
46
|
}
|
|
44
|
-
|
|
47
|
+
assertIsVikeEnhanced(stateVikeEnhanced);
|
|
45
48
|
return stateVikeEnhanced;
|
|
46
49
|
}
|
|
47
50
|
function getState() {
|
|
48
|
-
const state =
|
|
51
|
+
const state = window.history.state;
|
|
49
52
|
// *Every* state added to the history needs to go through Vike.
|
|
50
53
|
// - Otherwise Vike's `popstate` listener won't work. (Because, for example, if globalObject.previous is outdated => isHashNavigation faulty => client-side navigation is wrongfully skipped.)
|
|
51
54
|
// - Therefore, we have to monkey patch history.pushState() and history.replaceState()
|
|
52
55
|
// - Therefore, we need the assert() below to ensure history.state has been enhanced by Vike
|
|
53
56
|
// - If users stumble upon this assert() then let's make it a assertUsage()
|
|
54
|
-
|
|
55
|
-
return state;
|
|
56
|
-
}
|
|
57
|
-
function getStateNotEnhanced() {
|
|
58
|
-
const state = window.history.state;
|
|
57
|
+
assertIsVikeEnhanced(state);
|
|
59
58
|
return state;
|
|
60
59
|
}
|
|
61
60
|
function getScrollPosition() {
|
|
@@ -90,6 +89,7 @@ function pushHistoryState(url, overwriteLastHistoryEntry) {
|
|
|
90
89
|
function replaceHistoryState(state, url) {
|
|
91
90
|
const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
|
|
92
91
|
window.history.replaceState(state, '', url_);
|
|
92
|
+
assertIsVikeEnhanced(window.history.state);
|
|
93
93
|
}
|
|
94
94
|
function replaceHistoryStateOriginal(state, url) {
|
|
95
95
|
// Bypass all monkey patches.
|
|
@@ -100,7 +100,9 @@ function replaceHistoryStateOriginal(state, url) {
|
|
|
100
100
|
// - history.pushState()
|
|
101
101
|
// - history.replaceState()
|
|
102
102
|
function monkeyPatchHistoryAPI() {
|
|
103
|
-
|
|
103
|
+
if (globalObject.monkeyPatched)
|
|
104
|
+
return;
|
|
105
|
+
globalObject.monkeyPatched = true;
|
|
104
106
|
['pushState', 'replaceState'].forEach((funcName) => {
|
|
105
107
|
const funcOriginal = window.history[funcName].bind(window.history);
|
|
106
108
|
window.history[funcName] = (stateOriginal = {}, ...rest) => {
|
|
@@ -114,10 +116,19 @@ function monkeyPatchHistoryAPI() {
|
|
|
114
116
|
triggeredBy: 'user',
|
|
115
117
|
...stateOriginal,
|
|
116
118
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
assertIsVikeEnhanced(stateEnhanced);
|
|
120
|
+
funcOriginal(stateEnhanced, ...rest);
|
|
121
|
+
assert(deepEqual(stateEnhanced, window.history.state));
|
|
119
122
|
globalObject.previous = getHistoryInfo();
|
|
120
|
-
|
|
123
|
+
// Workaround https://github.com/vikejs/vike/issues/2504#issuecomment-3149764736
|
|
124
|
+
queueMicrotask(() => {
|
|
125
|
+
if (deepEqual(stateEnhanced, window.history.state))
|
|
126
|
+
return;
|
|
127
|
+
Object.assign(stateEnhanced, window.history.state);
|
|
128
|
+
assertIsVikeEnhanced(stateEnhanced);
|
|
129
|
+
replaceHistoryStateOriginal(stateEnhanced, rest[1]);
|
|
130
|
+
assert(deepEqual(stateEnhanced, window.history.state));
|
|
131
|
+
});
|
|
121
132
|
};
|
|
122
133
|
});
|
|
123
134
|
}
|
|
@@ -136,6 +147,11 @@ function isVikeEnhanced(state) {
|
|
|
136
147
|
}
|
|
137
148
|
return false;
|
|
138
149
|
}
|
|
150
|
+
function assertIsVikeEnhanced(state) {
|
|
151
|
+
if (isVikeEnhanced(state))
|
|
152
|
+
return;
|
|
153
|
+
assert(false, { state });
|
|
154
|
+
}
|
|
139
155
|
function getHistoryInfo() {
|
|
140
156
|
return {
|
|
141
157
|
url: getCurrentUrl(),
|
|
@@ -147,11 +163,12 @@ function onPopStateBegin() {
|
|
|
147
163
|
const isHistoryStateEnhanced = window.history.state !== null;
|
|
148
164
|
if (!isHistoryStateEnhanced)
|
|
149
165
|
enhanceHistoryState();
|
|
150
|
-
|
|
166
|
+
assertIsVikeEnhanced(window.history.state);
|
|
151
167
|
const current = getHistoryInfo();
|
|
152
168
|
globalObject.previous = current;
|
|
153
169
|
return { isHistoryStateEnhanced, previous, current };
|
|
154
170
|
}
|
|
155
|
-
function
|
|
156
|
-
|
|
171
|
+
function initHistory() {
|
|
172
|
+
monkeyPatchHistoryAPI(); // the earlier we call it the better (Vike can workaround erroneous library monkey patches if Vike is the last one in the monkey patch chain)
|
|
173
|
+
enhanceHistoryState(); // enhance very first window.history.state which is `null`
|
|
157
174
|
}
|