vike 0.4.220 → 0.4.221-commit-8577456
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 +5 -23
- package/dist/cjs/node/api/build.js +33 -24
- package/dist/cjs/node/api/context.js +6 -8
- package/dist/cjs/node/api/prepareViteApiCall.js +23 -21
- package/dist/cjs/node/api/prerender.js +1 -0
- package/dist/cjs/node/api/utils.js +2 -1
- package/dist/cjs/node/cli/context.js +16 -0
- package/dist/cjs/node/cli/entry.js +2 -0
- package/dist/cjs/node/cli/utils.js +1 -0
- package/dist/cjs/node/plugin/index.js +4 -8
- package/dist/cjs/node/plugin/onLoad.js +6 -1
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +34 -33
- package/dist/cjs/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildApp.js +72 -0
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +12 -12
- package/dist/cjs/node/plugin/plugins/buildConfig.js +17 -12
- package/dist/cjs/node/plugin/plugins/buildEntry/index.js +28 -24
- package/dist/cjs/node/plugin/plugins/commonConfig.js +9 -7
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +7 -4
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +15 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +11 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{assertExtensions.js → getVikeConfig/assertExtensions.js} +41 -36
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +59 -22
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{getConfigFileExport.js → getVikeConfig/getConfigFileExport.js} +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +159 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +40 -23
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +9 -64
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +403 -590
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{debug.js → virtual-files/debug.js} +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigValuesAll.js → virtual-files/getVirtualFilePageConfigValuesAll.js} +12 -9
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigs.js → virtual-files/getVirtualFilePageConfigs.js} +13 -11
- package/dist/cjs/node/plugin/plugins/packageJsonFile.js +2 -2
- package/dist/cjs/node/plugin/plugins/previewConfig.js +7 -7
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +3 -5
- package/dist/cjs/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/cjs/node/plugin/shared/getFullBuildInlineConfig.js +20 -0
- package/dist/cjs/{utils → node/plugin/shared}/getOutDirs.js +70 -61
- package/dist/cjs/node/plugin/{resolveClientEntriesDev.js → shared/resolveClientEntriesDev.js} +5 -8
- package/dist/cjs/{utils → node/plugin/shared}/viteIsSSR.js +2 -2
- package/dist/cjs/node/plugin/utils.js +1 -2
- package/dist/cjs/node/prerender/context.js +31 -0
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +46 -0
- package/dist/cjs/node/prerender/runPrerender.js +89 -68
- package/dist/cjs/node/prerender/utils.js +2 -2
- package/dist/cjs/node/runtime/globalContext.js +222 -150
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +11 -7
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +2 -3
- package/dist/cjs/node/runtime/html/injectAssets.js +4 -4
- package/dist/cjs/node/runtime/html/renderHtml.js +4 -5
- package/dist/cjs/node/runtime/page-files/setup.js +1 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -3
- package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +2 -27
- package/dist/cjs/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.js +2 -4
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +4 -4
- package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +3 -5
- package/dist/cjs/node/runtime/renderPage/isFontFallback.js +29 -0
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +5 -4
- package/dist/cjs/node/runtime/renderPage/log404/index.js +1 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +14 -10
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +6 -5
- package/dist/cjs/node/runtime/renderPage.js +31 -29
- package/dist/cjs/node/runtime/utils.js +3 -3
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +5 -3
- package/dist/cjs/node/shared/resolveBase.js +7 -0
- package/dist/cjs/shared/getPageConfigsRuntime.js +20 -0
- package/dist/cjs/shared/getPageContextUrlComputed.js +6 -1
- package/dist/cjs/shared/getPageFiles/fileTypes.js +0 -1
- package/dist/cjs/shared/getPageFiles/getAllPageIdFiles.js +0 -3
- package/dist/cjs/shared/getPageFiles/getPageFileObject.js +0 -5
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +4 -3
- package/dist/cjs/shared/getPageFiles.js +1 -3
- package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +15 -6
- package/dist/cjs/shared/page-configs/loadConfigValues.js +5 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +69 -18
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -0
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +1 -1
- package/dist/cjs/utils/catchInfiniteLoop.js +34 -0
- package/dist/cjs/utils/debug.js +8 -6
- package/dist/cjs/utils/findFile.js +4 -3
- package/dist/cjs/utils/isDev.js +2 -2
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -2
- package/dist/cjs/utils/makePublicCopy.js +32 -0
- package/dist/cjs/utils/objectAssignSafe.js +7 -0
- package/dist/cjs/utils/path.js +48 -0
- package/dist/cjs/utils/requireResolve.js +3 -3
- package/dist/esm/__internal/index.d.ts +2 -2
- package/dist/esm/__internal/index.js +7 -26
- package/dist/esm/client/client-routing-runtime/createPageContext.js +5 -9
- package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +23 -18
- package/dist/esm/client/client-routing-runtime/index.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/index.js +0 -1
- package/dist/esm/client/client-routing-runtime/initClientRouter.js +2 -2
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.d.ts +0 -4
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +0 -11
- package/dist/esm/client/client-routing-runtime/initOnPopState.d.ts +0 -10
- package/dist/esm/client/client-routing-runtime/initOnPopState.js +50 -70
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +15 -15
- package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +4 -6
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +17 -12
- package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/setScrollPosition.js +29 -5
- package/dist/esm/client/client-routing-runtime/skipLink.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/skipLink.js +0 -1
- package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/utils.js +1 -0
- package/dist/esm/client/server-routing-runtime/getPageContext.js +3 -4
- package/dist/esm/client/shared/loadUserFilesClientSide.js +3 -2
- package/dist/esm/node/api/build.d.ts +1 -6
- package/dist/esm/node/api/build.js +31 -25
- package/dist/esm/node/api/context.d.ts +4 -4
- package/dist/esm/node/api/context.js +6 -9
- package/dist/esm/node/api/prepareViteApiCall.d.ts +4 -3
- package/dist/esm/node/api/prepareViteApiCall.js +24 -22
- package/dist/esm/node/api/prerender.js +1 -0
- package/dist/esm/node/api/utils.d.ts +2 -1
- package/dist/esm/node/api/utils.js +2 -1
- package/dist/esm/node/cli/context.d.ts +5 -0
- package/dist/esm/node/cli/context.js +14 -0
- package/dist/esm/node/cli/entry.js +2 -0
- package/dist/esm/node/cli/parseCli.d.ts +3 -1
- package/dist/esm/node/cli/utils.d.ts +1 -0
- package/dist/esm/node/cli/utils.js +1 -0
- package/dist/esm/node/plugin/index.d.ts +29 -1
- package/dist/esm/node/plugin/index.js +5 -9
- package/dist/esm/node/plugin/onLoad.js +7 -2
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +35 -34
- package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/esm/node/plugin/plugins/buildApp.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/buildApp.js +70 -0
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +0 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +11 -11
- package/dist/esm/node/plugin/plugins/buildConfig.js +16 -11
- package/dist/esm/node/plugin/plugins/buildEntry/index.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/buildEntry/index.js +28 -24
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +8 -2
- package/dist/esm/node/plugin/plugins/commonConfig.js +7 -5
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +6 -3
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +14 -9
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +11 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.d.ts +6 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{assertExtensions.js → getVikeConfig/assertExtensions.js} +41 -36
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +58 -21
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getConfigFileExport.js → getVikeConfig/getConfigFileExport.js} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.d.ts +39 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +154 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +15 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +41 -24
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +8 -18
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +10 -65
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +6 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +12 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +10 -122
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +407 -594
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{debug.js → virtual-files/debug.js} +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigValuesAll.js → virtual-files/getVirtualFilePageConfigValuesAll.js} +12 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigs.js → virtual-files/getVirtualFilePageConfigs.js} +13 -11
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{isRuntimeEnvMatch.d.ts → virtual-files/isRuntimeEnvMatch.d.ts} +1 -1
- package/dist/esm/node/plugin/plugins/packageJsonFile.js +1 -1
- package/dist/esm/node/plugin/plugins/previewConfig.js +5 -5
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +4 -6
- package/dist/esm/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/esm/node/plugin/shared/getFullBuildInlineConfig.d.ts +2 -0
- package/dist/esm/node/plugin/shared/getFullBuildInlineConfig.js +17 -0
- package/dist/esm/{utils → node/plugin/shared}/getOutDirs.d.ts +1 -1
- package/dist/esm/{utils → node/plugin/shared}/getOutDirs.js +52 -43
- package/dist/esm/node/plugin/{resolveClientEntriesDev.js → shared/resolveClientEntriesDev.js} +5 -8
- package/dist/esm/{utils → node/plugin/shared}/viteIsSSR.d.ts +2 -5
- package/dist/esm/{utils → node/plugin/shared}/viteIsSSR.js +2 -2
- package/dist/esm/node/plugin/utils.d.ts +0 -1
- package/dist/esm/node/plugin/utils.js +1 -2
- package/dist/esm/node/prerender/context.d.ts +11 -0
- package/dist/esm/node/prerender/context.js +29 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +12 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +44 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +42 -1
- package/dist/esm/node/prerender/runPrerender.js +90 -69
- package/dist/esm/node/prerender/utils.d.ts +2 -2
- package/dist/esm/node/prerender/utils.js +2 -2
- package/dist/esm/node/runtime/globalContext.d.ts +44 -36
- package/dist/esm/node/runtime/globalContext.js +223 -151
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +11 -7
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +4 -1
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +2 -3
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -0
- package/dist/esm/node/runtime/html/injectAssets.js +4 -4
- package/dist/esm/node/runtime/html/renderHtml.js +4 -5
- package/dist/esm/node/runtime/page-files/setup.js +1 -1
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -1
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -3
- package/dist/esm/node/runtime/renderPage/getEarlyHints.js +1 -26
- package/dist/esm/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.js +2 -4
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +3 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +4 -4
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +3 -5
- package/dist/esm/node/runtime/renderPage/isFontFallback.d.ts +3 -0
- package/dist/esm/node/runtime/renderPage/isFontFallback.js +27 -0
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +6 -5
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/log404/index.js +1 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +3 -0
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +26 -10
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +14 -10
- package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/resolveRedirects.js +5 -5
- package/dist/esm/node/runtime/renderPage.js +32 -30
- package/dist/esm/node/runtime/utils.d.ts +3 -3
- package/dist/esm/node/runtime/utils.js +3 -3
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +5 -3
- package/dist/esm/node/shared/resolveBase.d.ts +5 -1
- package/dist/esm/node/shared/resolveBase.js +7 -0
- package/dist/esm/shared/getPageConfigsRuntime.d.ts +13 -0
- package/dist/esm/shared/getPageConfigsRuntime.js +18 -0
- package/dist/esm/shared/getPageContextUrlComputed.js +6 -1
- package/dist/esm/shared/getPageFiles/fileTypes.js +1 -2
- package/dist/esm/shared/getPageFiles/getAllPageIdFiles.js +0 -3
- package/dist/esm/shared/getPageFiles/getPageFileObject.js +0 -5
- package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +1 -1
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +4 -3
- package/dist/esm/shared/getPageFiles.d.ts +0 -1
- package/dist/esm/shared/getPageFiles.js +0 -1
- package/dist/esm/shared/page-configs/Config.d.ts +83 -3
- package/dist/esm/shared/page-configs/PageConfig.d.ts +30 -18
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +6 -8
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +15 -6
- package/dist/esm/shared/page-configs/loadConfigValues.js +6 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +7 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +70 -19
- package/dist/esm/shared/route/loadPageRoutes.js +1 -0
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- 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 +1 -1
- package/dist/esm/utils/catchInfiniteLoop.d.ts +2 -0
- package/dist/esm/utils/catchInfiniteLoop.js +32 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +8 -6
- package/dist/esm/utils/findFile.js +2 -1
- package/dist/esm/utils/isDev.js +3 -3
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
- package/dist/esm/utils/makePublicCopy.d.ts +3 -0
- package/dist/esm/utils/makePublicCopy.js +30 -0
- package/dist/esm/utils/objectAssignSafe.d.ts +1 -0
- package/dist/esm/utils/objectAssignSafe.js +4 -0
- package/dist/esm/utils/path.d.ts +14 -0
- package/dist/esm/utils/path.js +46 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -17
- package/dist/cjs/node/plugin/plugins/importUserCode/addImportStatement.js +0 -29
- package/dist/cjs/node/prerender/isPrerenderAutoRunEnabled.js +0 -16
- package/dist/cjs/node/shared/assertPluginManifest.js +0 -20
- package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -16
- package/dist/cjs/shared/assertPageFilePath.js +0 -11
- package/dist/cjs/shared/getPageFiles/getPageFiles.js +0 -48
- package/dist/cjs/utils/filesystemPathHandling.js +0 -18
- package/dist/cjs/utils/path-shim.js +0 -19
- package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -15
- package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.d.ts +0 -14
- package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.js +0 -27
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +0 -5
- package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.d.ts +0 -5
- package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.js +0 -14
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -12
- package/dist/esm/node/shared/assertPluginManifest.js +0 -18
- package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -10
- package/dist/esm/node/shared/assertRuntimeManifest.js +0 -14
- package/dist/esm/shared/assertPageFilePath.d.ts +0 -2
- package/dist/esm/shared/assertPageFilePath.js +0 -9
- package/dist/esm/shared/getPageFiles/getPageFiles.d.ts +0 -15
- package/dist/esm/shared/getPageFiles/getPageFiles.js +0 -46
- package/dist/esm/utils/filesystemPathHandling.d.ts +0 -4
- package/dist/esm/utils/filesystemPathHandling.js +0 -16
- package/dist/esm/utils/path-shim.d.ts +0 -2
- package/dist/esm/utils/path-shim.js +0 -17
- /package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{isRuntimeEnvMatch.js → virtual-files/isRuntimeEnvMatch.js} +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getConfigFileExport.d.ts → getVikeConfig/getConfigFileExport.d.ts} +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{debug.d.ts → virtual-files/debug.d.ts} +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigValuesAll.d.ts → virtual-files/getVirtualFilePageConfigValuesAll.d.ts} +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigs.d.ts → virtual-files/getVirtualFilePageConfigs.d.ts} +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{isRuntimeEnvMatch.js → virtual-files/isRuntimeEnvMatch.js} +0 -0
- /package/dist/esm/node/plugin/{resolveClientEntriesDev.d.ts → shared/resolveClientEntriesDev.d.ts} +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pathJoin = pathJoin;
|
|
4
|
+
exports.pathIsRelative = pathIsRelative;
|
|
5
|
+
exports.toPosixPath = toPosixPath;
|
|
6
|
+
exports.assertPosixPath = assertPosixPath;
|
|
7
|
+
// Utilites for handling file paths.
|
|
8
|
+
// - Shims `import * from "node:path"` for server runtime.
|
|
9
|
+
// - Robust shim reference: https://github.com/unjs/pathe
|
|
10
|
+
const assert_js_1 = require("./assert.js");
|
|
11
|
+
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
12
|
+
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
13
|
+
/**********************/
|
|
14
|
+
/****** SHIMS *********/
|
|
15
|
+
/**********************/
|
|
16
|
+
function pathJoin(path1, path2) {
|
|
17
|
+
(0, assert_js_1.assert)(!path1.includes('\\'));
|
|
18
|
+
(0, assert_js_1.assert)(!path2.includes('\\'));
|
|
19
|
+
let joined = [...path1.split('/'), ...path2.split('/')].filter(Boolean).join('/');
|
|
20
|
+
if (path1.startsWith('/'))
|
|
21
|
+
joined = '/' + joined;
|
|
22
|
+
return joined;
|
|
23
|
+
}
|
|
24
|
+
/* https://github.com/brillout/telefunc/blob/0fd44322acbd07857ae29361ba7c998607f17dd5/telefunc/utils/path-shim.ts#L17-L21
|
|
25
|
+
const IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/
|
|
26
|
+
function pathIsAbsolute(filePath: string) {
|
|
27
|
+
return IS_ABSOLUTE_RE.test(filePath)
|
|
28
|
+
}
|
|
29
|
+
//*/
|
|
30
|
+
/**********************/
|
|
31
|
+
/****** UTILS *********/
|
|
32
|
+
/**********************/
|
|
33
|
+
function toPosixPath(path) {
|
|
34
|
+
const pathPosix = path.split('\\').join('/');
|
|
35
|
+
assertPosixPath(pathPosix);
|
|
36
|
+
return pathPosix;
|
|
37
|
+
}
|
|
38
|
+
function assertPosixPath(path) {
|
|
39
|
+
const errMsg = (msg) => `Not a posix path: ${msg}`;
|
|
40
|
+
(0, assert_js_1.assert)(path !== null, errMsg('null'));
|
|
41
|
+
(0, assert_js_1.assert)(typeof path === 'string', errMsg(`typeof path === ${JSON.stringify(typeof path)}`));
|
|
42
|
+
(0, assert_js_1.assert)(path !== '', errMsg('(empty string)'));
|
|
43
|
+
(0, assert_js_1.assert)(path);
|
|
44
|
+
(0, assert_js_1.assert)(!path.includes('\\'), errMsg(path));
|
|
45
|
+
}
|
|
46
|
+
function pathIsRelative(importPath) {
|
|
47
|
+
return importPath.startsWith('./') || importPath.startsWith('../');
|
|
48
|
+
}
|
|
@@ -4,7 +4,7 @@ exports.requireResolve = requireResolve;
|
|
|
4
4
|
const assert_js_1 = require("./assert.js");
|
|
5
5
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
6
6
|
const assertSetup_js_1 = require("./assertSetup.js");
|
|
7
|
-
const
|
|
7
|
+
const path_js_1 = require("./path.js");
|
|
8
8
|
const isScriptFile_js_1 = require("./isScriptFile.js");
|
|
9
9
|
const module_1 = require("module");
|
|
10
10
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
@@ -15,7 +15,7 @@ const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
|
15
15
|
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
16
16
|
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
17
17
|
function requireResolve(importPath, cwd) {
|
|
18
|
-
(0,
|
|
18
|
+
(0, path_js_1.assertPosixPath)(cwd);
|
|
19
19
|
const clean = addFileExtensionsToRequireResolve();
|
|
20
20
|
importPath = removeFileExtention(importPath);
|
|
21
21
|
let importedFile;
|
|
@@ -29,7 +29,7 @@ function requireResolve(importPath, cwd) {
|
|
|
29
29
|
clean();
|
|
30
30
|
}
|
|
31
31
|
if (importedFile) {
|
|
32
|
-
importedFile = (0,
|
|
32
|
+
importedFile = (0, path_js_1.toPosixPath)(importedFile);
|
|
33
33
|
}
|
|
34
34
|
return importedFile;
|
|
35
35
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export { setGlobalContext_buildEntry } from '../node/runtime/globalContext.js';
|
|
2
2
|
export { route, getPagesAndRoutes };
|
|
3
3
|
export type { PageRoutes, PageFile, PageConfigRuntime as PageConfig };
|
|
4
|
-
export { getMiddlewares };
|
|
5
4
|
import { route as routeInternal, type PageRoutes } from '../shared/route/index.js';
|
|
6
5
|
import type { PageFile } from '../shared/getPageFiles/getPageFileObject.js';
|
|
7
6
|
import { PageConfigRuntime } from '../shared/page-configs/PageConfig.js';
|
|
8
7
|
/**
|
|
9
8
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel} to compute some rewrite rules and extract { isr } configs.
|
|
9
|
+
*
|
|
10
|
+
* TODO/eventually: remove
|
|
10
11
|
*/
|
|
11
12
|
declare function getPagesAndRoutes(): Promise<{
|
|
12
13
|
pageRoutes: PageRoutes;
|
|
@@ -14,7 +15,6 @@ declare function getPagesAndRoutes(): Promise<{
|
|
|
14
15
|
pageConfigs: PageConfigRuntime[];
|
|
15
16
|
allPageIds: string[];
|
|
16
17
|
}>;
|
|
17
|
-
declare function getMiddlewares(): Promise<unknown[]>;
|
|
18
18
|
declare function route(pageContext: Parameters<typeof routeInternal>[0]): Promise<{
|
|
19
19
|
pageContextAddendum: import("../shared/route/index.js").PageContextFromRoute;
|
|
20
20
|
}>;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Needed by Vike
|
|
2
2
|
export { setGlobalContext_buildEntry } from '../node/runtime/globalContext.js';
|
|
3
|
-
//
|
|
3
|
+
// Needed by vite-plugin-vercel
|
|
4
4
|
export { route, getPagesAndRoutes };
|
|
5
|
-
// Internals needed by experimental implementation of vike-telefunc
|
|
6
|
-
export { getMiddlewares };
|
|
7
5
|
import { route as routeInternal } from '../shared/route/index.js';
|
|
8
|
-
import {
|
|
9
|
-
import { getGlobalContext, initGlobalContext_getGlobalContextAsync } from '../node/runtime/globalContext.js';
|
|
6
|
+
import { getGlobalContextInternal, initGlobalContext_getPagesAndRoutes } from '../node/runtime/globalContext.js';
|
|
10
7
|
import { setNodeEnvProduction } from '../utils/assertSetup.js';
|
|
11
8
|
/**
|
|
12
9
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel} to compute some rewrite rules and extract { isr } configs.
|
|
10
|
+
*
|
|
11
|
+
* TODO/eventually: remove
|
|
13
12
|
*/
|
|
14
13
|
async function getPagesAndRoutes() {
|
|
15
14
|
setNodeEnvProduction();
|
|
16
|
-
|
|
15
|
+
await initGlobalContext_getPagesAndRoutes();
|
|
16
|
+
const globalContext = await getGlobalContextInternal();
|
|
17
17
|
const {
|
|
18
18
|
//
|
|
19
19
|
pageRoutes, pageFilesAll, pageConfigs, allPageIds } = globalContext;
|
|
@@ -24,25 +24,6 @@ async function getPagesAndRoutes() {
|
|
|
24
24
|
allPageIds
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
// TODO/eventually:
|
|
28
|
-
// - Remove the need for `isProduction` after Vike's CLI is implemented
|
|
29
|
-
// - Remove it in favor of https://vike.dev/getGlobalContext
|
|
30
|
-
async function getMiddlewares() {
|
|
31
|
-
const isProduction = process.env.NODE_ENV === 'production';
|
|
32
|
-
const { pageConfigs } = await getPageFilesAllSafe(isProduction);
|
|
33
|
-
const middlewares = pageConfigs[0].configValues.middleware.value.flat(Infinity);
|
|
34
|
-
return middlewares;
|
|
35
|
-
}
|
|
36
|
-
// TODO/eventually:
|
|
37
|
-
// - Make it cleaner once the internal refactoring about global configs is done.
|
|
38
|
-
// - Remove it in favor of https://vike.dev/getGlobalContext
|
|
39
|
-
// Demo usage: https://github.com/vikejs/vike/pull/1823
|
|
40
|
-
async function getPageFilesAllSafe(isProduction) {
|
|
41
|
-
await initGlobalContext_getGlobalContextAsync(isProduction);
|
|
42
|
-
const globalContext = getGlobalContext();
|
|
43
|
-
const pageFilesAll = await getPageFilesAll(false, globalContext.isProduction);
|
|
44
|
-
return pageFilesAll;
|
|
45
|
-
}
|
|
46
27
|
async function route(pageContext) {
|
|
47
28
|
const pageContextFromRoute = await routeInternal(pageContext);
|
|
48
29
|
// Old interface
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
export { createPageContext };
|
|
2
|
+
import { getPageConfigsRuntime } from '../../shared/getPageConfigsRuntime.js';
|
|
2
3
|
import { getPageContextUrlComputed } from '../../shared/getPageContextUrlComputed.js';
|
|
3
|
-
import { getPageFilesAll, setPageFiles } from '../../shared/getPageFiles/getPageFiles.js';
|
|
4
4
|
import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
|
|
5
5
|
import { getBaseServer } from './getBaseServer.js';
|
|
6
|
-
import { assert, isBaseServer,
|
|
6
|
+
import { assert, isBaseServer, objectAssign } from './utils.js';
|
|
7
|
+
// TODO/now: can we avoid optimizeDeps.exclude of client runtime?
|
|
7
8
|
// @ts-ignore
|
|
8
|
-
import * as
|
|
9
|
-
const
|
|
10
|
-
setPageFiles(pageFilesExports);
|
|
9
|
+
import * as virtualFileExports from 'virtual:vike:importUserCode:client:client-routing';
|
|
10
|
+
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal } = getPageConfigsRuntime(virtualFileExports);
|
|
11
11
|
async function createPageContext(urlOriginal) {
|
|
12
|
-
if (!globalObject.pageFilesData) {
|
|
13
|
-
globalObject.pageFilesData = await getPageFilesAll(true);
|
|
14
|
-
}
|
|
15
|
-
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal } = globalObject.pageFilesData;
|
|
16
12
|
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
|
|
17
13
|
const baseServer = getBaseServer();
|
|
18
14
|
assert(isBaseServer(baseServer));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { pushHistoryState };
|
|
2
|
+
export { replaceHistoryStateOriginal };
|
|
2
3
|
export { onPopStateBegin };
|
|
3
4
|
export { saveScrollPosition };
|
|
4
5
|
export { initHistoryState };
|
|
@@ -17,13 +18,14 @@ type ScrollPosition = {
|
|
|
17
18
|
};
|
|
18
19
|
declare function saveScrollPosition(): void;
|
|
19
20
|
declare function pushHistoryState(url: string, overwriteLastHistoryEntry: boolean): void;
|
|
21
|
+
declare function replaceHistoryStateOriginal(state: unknown, url: string): void;
|
|
20
22
|
declare function monkeyPatchHistoryAPI(): void;
|
|
21
23
|
type HistoryInfo = {
|
|
22
24
|
url: `/${string}`;
|
|
23
25
|
state: StateEnhanced;
|
|
24
26
|
};
|
|
25
27
|
declare function onPopStateBegin(): {
|
|
26
|
-
|
|
28
|
+
isHistoryStateEnhanced: boolean;
|
|
27
29
|
previous: HistoryInfo;
|
|
28
30
|
current: HistoryInfo;
|
|
29
31
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { pushHistoryState };
|
|
2
|
+
export { replaceHistoryStateOriginal };
|
|
2
3
|
export { onPopStateBegin };
|
|
3
4
|
export { saveScrollPosition };
|
|
4
5
|
export { initHistoryState };
|
|
5
6
|
export { monkeyPatchHistoryAPI };
|
|
6
7
|
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
7
|
-
import { assert, assertUsage, getGlobalObject,
|
|
8
|
+
import { assert, assertUsage, getGlobalObject, isObject } from './utils.js';
|
|
8
9
|
initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
|
|
9
10
|
const globalObject = getGlobalObject('history.ts', { previous: getHistoryInfo() });
|
|
10
11
|
// `window.history.state === null` when:
|
|
@@ -90,6 +91,11 @@ function replaceHistoryState(state, url) {
|
|
|
90
91
|
const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
|
|
91
92
|
window.history.replaceState(state, '', url_);
|
|
92
93
|
}
|
|
94
|
+
function replaceHistoryStateOriginal(state, url) {
|
|
95
|
+
// Bypass all monkey patches.
|
|
96
|
+
// - Useful, for example, to avoid other tools listening to history.replaceState() calls
|
|
97
|
+
History.prototype.replaceState.bind(window.history)(state, '', url);
|
|
98
|
+
}
|
|
93
99
|
// Monkey patch:
|
|
94
100
|
// - history.pushState()
|
|
95
101
|
// - history.replaceState()
|
|
@@ -116,21 +122,19 @@ function monkeyPatchHistoryAPI() {
|
|
|
116
122
|
});
|
|
117
123
|
}
|
|
118
124
|
function isVikeEnhanced(state) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (state.scrollPosition !== null) {
|
|
131
|
-
assert(hasProp(state, 'scrollPosition', 'object'));
|
|
132
|
-
assert(hasProp(state.scrollPosition, 'x', 'number') && hasProp(state.scrollPosition, 'y', 'number'));
|
|
125
|
+
if (isObject(state) && '_isVikeEnhanced' in state) {
|
|
126
|
+
/* We don't use the assert() below to save client-side KBs.
|
|
127
|
+
assert(hasProp(state, '_isVikeEnhanced', 'true'))
|
|
128
|
+
assert(hasProp(state, 'timestamp', 'number'))
|
|
129
|
+
assert(hasProp(state, 'scrollPosition'))
|
|
130
|
+
if (state.scrollPosition !== null) {
|
|
131
|
+
assert(hasProp(state, 'scrollPosition', 'object'))
|
|
132
|
+
assert(hasProp(state.scrollPosition, 'x', 'number') && hasProp(state.scrollPosition, 'y', 'number'))
|
|
133
|
+
}
|
|
134
|
+
//*/
|
|
135
|
+
return true;
|
|
133
136
|
}
|
|
137
|
+
return false;
|
|
134
138
|
}
|
|
135
139
|
function getHistoryInfo() {
|
|
136
140
|
return {
|
|
@@ -140,12 +144,13 @@ function getHistoryInfo() {
|
|
|
140
144
|
}
|
|
141
145
|
function onPopStateBegin() {
|
|
142
146
|
const { previous } = globalObject;
|
|
143
|
-
const
|
|
144
|
-
if (
|
|
147
|
+
const isHistoryStateEnhanced = window.history.state !== null;
|
|
148
|
+
if (!isHistoryStateEnhanced)
|
|
145
149
|
enhanceHistoryState();
|
|
150
|
+
assert(isVikeEnhanced(window.history.state));
|
|
146
151
|
const current = getHistoryInfo();
|
|
147
152
|
globalObject.previous = current;
|
|
148
|
-
return {
|
|
153
|
+
return { isHistoryStateEnhanced, previous, current };
|
|
149
154
|
}
|
|
150
155
|
function initHistoryState() {
|
|
151
156
|
enhanceHistoryState();
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { navigate, reload } from './navigate.js';
|
|
2
2
|
export { prefetch } from './prefetch.js';
|
|
3
|
-
export { onPopState } from './initOnPopState.js';
|
|
4
3
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
5
4
|
import type { PageContextBuiltInClientWithClientRouting } from '../../shared/types.js';
|
|
6
5
|
/** @deprecated
|
|
@@ -3,7 +3,7 @@ import { assert } from './utils.js';
|
|
|
3
3
|
import { getRenderCount, renderPageClientSide } from './renderPageClientSide.js';
|
|
4
4
|
import { initOnPopState } from './initOnPopState.js';
|
|
5
5
|
import { initOnLinkClick } from './initOnLinkClick.js';
|
|
6
|
-
import {
|
|
6
|
+
import { scrollRestoration_init } from './scrollRestoration.js';
|
|
7
7
|
import { autoSaveScrollPosition } from './setScrollPosition.js';
|
|
8
8
|
import { initLinkPrefetchHandlers } from './prefetch.js';
|
|
9
9
|
import { initHistoryState, monkeyPatchHistoryAPI } from './history.js';
|
|
@@ -28,9 +28,9 @@ async function renderFirstPage() {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
function initHistoryAndScroll() {
|
|
31
|
+
scrollRestoration_init();
|
|
31
32
|
monkeyPatchHistoryAPI();
|
|
32
33
|
initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
|
|
33
|
-
setupNativeScrollRestoration();
|
|
34
34
|
autoSaveScrollPosition();
|
|
35
35
|
// Handle back-/forward navigation
|
|
36
36
|
initOnPopState();
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
// Code adapted from https://github.com/HenrikJoreteg/internal-nav-helper/blob/5199ec5448d0b0db7ec63cf76d88fa6cad878b7d/src/index.js#L11-L29
|
|
2
1
|
export { initOnLinkClick };
|
|
3
|
-
export { getCurrentLinkClick };
|
|
4
|
-
import { getGlobalObject } from './utils.js';
|
|
5
2
|
import { isSameAsCurrentUrl, skipLink } from './skipLink.js';
|
|
6
3
|
import { renderPageClientSide } from './renderPageClientSide.js';
|
|
7
4
|
import { scrollToHashOrTop } from './setScrollPosition.js';
|
|
8
|
-
const globalObject = getGlobalObject('initOnLinkClick.ts', {});
|
|
9
5
|
function initOnLinkClick() {
|
|
10
6
|
document.addEventListener('click', onClick);
|
|
11
7
|
}
|
|
@@ -18,10 +14,6 @@ async function onClick(ev) {
|
|
|
18
14
|
const href = linkTag.getAttribute('href');
|
|
19
15
|
if (href === null)
|
|
20
16
|
return;
|
|
21
|
-
globalObject.currentLinkClick = { href };
|
|
22
|
-
setTimeout(() => {
|
|
23
|
-
delete globalObject.currentLinkClick;
|
|
24
|
-
}, 0);
|
|
25
17
|
// Workaround for Firefox bug: clicking on a hash link that doesn't change the current URL causes Firefox to erroneously set `window.history.state = null` without firing any signal that we can detect.
|
|
26
18
|
// - https://github.com/vikejs/vike/issues/1962
|
|
27
19
|
// - https://github.com/sveltejs/kit/issues/8725
|
|
@@ -60,6 +52,3 @@ function findLinkTag(target) {
|
|
|
60
52
|
}
|
|
61
53
|
return target;
|
|
62
54
|
}
|
|
63
|
-
function getCurrentLinkClick() {
|
|
64
|
-
return globalObject.currentLinkClick;
|
|
65
|
-
}
|
|
@@ -1,12 +1,2 @@
|
|
|
1
1
|
export { initOnPopState };
|
|
2
|
-
export { onPopState };
|
|
3
|
-
import { type HistoryInfo } from './history.js';
|
|
4
2
|
declare function initOnPopState(): void;
|
|
5
|
-
type Listener = (arg: {
|
|
6
|
-
previous: HistoryInfo;
|
|
7
|
-
}) => void | boolean;
|
|
8
|
-
/** Control back-/forward navigation.
|
|
9
|
-
*
|
|
10
|
-
* https://vike.dev/onPopState
|
|
11
|
-
*/
|
|
12
|
-
declare function onPopState(listener: Listener): void;
|
|
@@ -1,79 +1,59 @@
|
|
|
1
1
|
export { initOnPopState };
|
|
2
|
-
export { onPopState };
|
|
3
|
-
import { assertWarning, getGlobalObject } from './utils.js';
|
|
4
2
|
import { onPopStateBegin } from './history.js';
|
|
5
3
|
import { renderPageClientSide } from './renderPageClientSide.js';
|
|
6
4
|
import { setScrollPosition } from './setScrollPosition.js';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { catchInfiniteLoop } from './utils.js';
|
|
6
|
+
// The 'popstate' event is trigged when the browser doesn't fully load the new URL, for example:
|
|
7
|
+
// - `location.hash='#foo'` triggers the popstate event while `location.href='/foo'` doesn't.
|
|
8
|
+
// - Clicking on the browser's back-/forward button triggers a popstate event only if the history entry was generated with history.pushState() — no popstate event is fired upon Server Routing.
|
|
9
|
+
// Concretely, 'popstate' is fired when:
|
|
10
|
+
// 1. Back-/forward navigation:
|
|
11
|
+
// - By the user using the browser's back-/forward navigation
|
|
12
|
+
// - By the app using `history.back()` / `history.forward()` / `history.go()`
|
|
13
|
+
// > Except of history entries triggered by Server Routing, see comment above.
|
|
14
|
+
// 2. URL hash changes:
|
|
15
|
+
// - By the user clicking on `<a href="#some-hash">`
|
|
16
|
+
// - The popstate event is *only* triggered if `href` starts with '#' (even if `href==='/foo#bar'` and the current URL has the same pathname '/foo' then popstate isn't triggered)
|
|
17
|
+
// - Vike doesn't intercept hash links (see `skipLink()`) and let's the browser handle them.
|
|
18
|
+
// - By the app using a `location` API such as `location.hash = 'some-hash'`
|
|
19
|
+
// - Only upon hash navigation: setting `location.href='/foo'` triggers a full page reload and no popstate event is fired.
|
|
20
|
+
// - Also upon `location.href='/foo#bar'` while the current URL is '/foo' (unlike <a> clicks).
|
|
21
|
+
// Notes:
|
|
22
|
+
// - The 'hashchange' event is fired after popstate, so we cannot use it to distinguish between hash and non-hash navigations.
|
|
23
|
+
// - It isn't possible to monkey patch the `location` APIs. (Chrome throws `TypeError: Cannot redefine property` when attempt to overwrite any `location` property.)
|
|
24
|
+
// - Text links aren't supported: https://github.com/vikejs/vike/issues/2114
|
|
25
|
+
// - docs/ is a good playground to test all this.
|
|
10
26
|
function initOnPopState() {
|
|
11
|
-
|
|
12
|
-
// - Back-/forward navigation.
|
|
13
|
-
// - By user clicking on his browser's back-/forward navigation (or using a shortcut)
|
|
14
|
-
// - By JavaScript: `history.back()` / `history.forward()`
|
|
15
|
-
// - URL hash change.
|
|
16
|
-
// - Click on `<a href="#some-hash" />`
|
|
17
|
-
// - The popstate event is *only* triggered if `href` starts with '#' (even if `href` is '/#some-hash' while the current URL's pathname is '/' then the popstate still isn't triggered)
|
|
18
|
-
// - `location.hash = 'some-hash'`
|
|
19
|
-
// - The `event` argument of `window.addEventListener('popstate', (event) => /*...*/)` is useless: the History API doesn't provide the previous state (the popped state), see https://stackoverflow.com/questions/48055323/is-history-state-always-the-same-as-popstate-event-state
|
|
20
|
-
window.addEventListener('popstate', async () => {
|
|
21
|
-
const currentLinkClick = getCurrentLinkClick();
|
|
22
|
-
const { isNewState, previous, current } = onPopStateBegin();
|
|
23
|
-
// We use currentLinkClick.href instead of current.url because current.url missing text links such as #:~:text=With%20frontmatter-,Global%20metadata,-What%20is%20global (e.g. Chrome strips the `#:~:text=` part from the URL before the popstate event).
|
|
24
|
-
if (currentLinkClick && isSamePageHashLink(currentLinkClick.href)) {
|
|
25
|
-
// Let the browser handle hash links
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const scrollTarget = current.state.scrollPosition || undefined;
|
|
29
|
-
const isUserPushStateNavigation = current.state.triggeredBy === 'user' || previous.state.triggeredBy === 'user';
|
|
30
|
-
const isHashNavigation = removeHash(current.url) === removeHash(previous.url) && current.url !== previous.url;
|
|
31
|
-
// - `isNewState === true` when:
|
|
32
|
-
// - Click on `<a href="#some-hash" />` (note that Vike's `initOnLinkClick()` handler skips hash links)
|
|
33
|
-
// - `location.hash = 'some-hash'`
|
|
34
|
-
// - `isNewState === false` when `popstate` was triggered by the user clicking on his browser's forward/backward history button.
|
|
35
|
-
const isHashNavigationNew = isHashNavigation && isNewState;
|
|
36
|
-
const isBackwardNavigation = !current.state.timestamp || !previous.state.timestamp ? null : current.state.timestamp < previous.state.timestamp;
|
|
37
|
-
// We have to scroll ourselves because we use `window.history.scrollRestoration = 'manual'`. So far this seems to work. Alternatives in case it doesn't work:
|
|
38
|
-
// - Alternative: we use `window.history.scrollRestoration = 'auto'`
|
|
39
|
-
// - Problem: I don't think it's possbible to set `window.history.scrollRestoration = 'auto'` only for hash navigation and not for non-hash navigations?
|
|
40
|
-
// - Problem: inconsistencies between browsers? For example specification says that setting `window.history.scrollRestoration` only affects the current entry in the session history but this contradicts what people are experiencing in practice.
|
|
41
|
-
// - Specification: https://html.spec.whatwg.org/multipage/history.html#the-history-interface
|
|
42
|
-
// - Practice: https://stackoverflow.com/questions/70188241/history-scrollrestoration-manual-doesnt-prevent-safari-from-restoring-scrol
|
|
43
|
-
// - Alternative: we completely take over hash navigation and reproduce the browser's native behavior upon hash navigation.
|
|
44
|
-
// - By using the `hashchange` event.
|
|
45
|
-
// - Problem: conflict if user wants to override the browser's default behavior? E.g. for smooth scrolling, or when using hashes for saving states of some fancy animations.
|
|
46
|
-
if (isHashNavigation) {
|
|
47
|
-
if (!isHashNavigationNew) {
|
|
48
|
-
setScrollPosition(scrollTarget);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
// The browser already scrolled to `#${hash}` => the current scroll position is the right one => we saved it with `enhanceHistoryState()`.
|
|
52
|
-
}
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
let doNotRenderIfSamePage = isUserPushStateNavigation;
|
|
56
|
-
let abort;
|
|
57
|
-
globalObject.listeners.forEach((listener) => {
|
|
58
|
-
abort || (abort = listener({ previous }));
|
|
59
|
-
});
|
|
60
|
-
if (abort) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (abort === false) {
|
|
64
|
-
doNotRenderIfSamePage = false;
|
|
65
|
-
}
|
|
66
|
-
await renderPageClientSide({ scrollTarget, isBackwardNavigation, doNotRenderIfSamePage });
|
|
67
|
-
});
|
|
27
|
+
window.addEventListener('popstate', onPopState);
|
|
68
28
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
29
|
+
async function onPopState() {
|
|
30
|
+
catchInfiniteLoop('onPopState()');
|
|
31
|
+
const { isHistoryStateEnhanced, previous, current } = onPopStateBegin();
|
|
32
|
+
// - `isHistoryStateEnhanced===false` <=> new hash navigation:
|
|
33
|
+
// - Click on `<a href="#some-hash">`
|
|
34
|
+
// - Using the `location` API (only hash navigation, see comments above).
|
|
35
|
+
// - `isHistoryStateEnhanced===true` <=> back-/forward navigation (including back-/forward hash navigation).
|
|
36
|
+
// > Only back-/forward client-side navigation: no 'popstate' event is fired upon Server Routing (when the user clicks on a link before the page's JavaScript loaded), see comments above.
|
|
37
|
+
if (!isHistoryStateEnhanced) {
|
|
38
|
+
// Let the browser handle it
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
await handleBackForwardNavigation(previous, current);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function handleBackForwardNavigation(previous, current) {
|
|
46
|
+
const scrollTarget = current.state.scrollPosition || undefined;
|
|
47
|
+
const isHashNavigation = removeHash(current.url) === removeHash(previous.url) && current.url !== previous.url;
|
|
48
|
+
if (isHashNavigation) {
|
|
49
|
+
// We have to scroll ourselves because we have set `window.history.scrollRestoration = 'manual'`
|
|
50
|
+
setScrollPosition(scrollTarget);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const isUserPushStateNavigation = current.state.triggeredBy === 'user' || previous.state.triggeredBy === 'user';
|
|
54
|
+
const doNotRenderIfSamePage = isUserPushStateNavigation;
|
|
55
|
+
const isBackwardNavigation = !current.state.timestamp || !previous.state.timestamp ? null : current.state.timestamp < previous.state.timestamp;
|
|
56
|
+
await renderPageClientSide({ scrollTarget, isBackwardNavigation, doNotRenderIfSamePage });
|
|
77
57
|
}
|
|
78
58
|
function removeHash(url) {
|
|
79
59
|
return url.split('#')[0];
|
|
@@ -2,7 +2,7 @@ export { renderPageClientSide };
|
|
|
2
2
|
export { getRenderCount };
|
|
3
3
|
export { disableClientRouting };
|
|
4
4
|
export { firstRenderStartPromise };
|
|
5
|
-
import { assert, isSameErrorMessage, objectAssign, redirectHard, getGlobalObject, executeHook, hasProp, augmentType, genPromise, isCallable } from './utils.js';
|
|
5
|
+
import { assert, isSameErrorMessage, objectAssign, redirectHard, getGlobalObject, executeHook, hasProp, augmentType, genPromise, isCallable, catchInfiniteLoop } from './utils.js';
|
|
6
6
|
import { getPageContextFromClientHooks, getPageContextFromServerHooks, getPageContextFromHooks_isHydration, getPageContextFromHooks_serialized, setPageContextInitIsPassedToClient } from './getPageContextFromHooks.js';
|
|
7
7
|
import { createPageContext } from './createPageContext.js';
|
|
8
8
|
import { addLinkPrefetchHandlers, addLinkPrefetchHandlers_unwatch, addLinkPrefetchHandlers_watch, getPageContextPrefetched, populatePageContextPrefetchCache } from './prefetch.js';
|
|
@@ -15,7 +15,7 @@ import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError,
|
|
|
15
15
|
import { route } from '../../shared/route/index.js';
|
|
16
16
|
import { isClientSideRoutable } from './isClientSideRoutable.js';
|
|
17
17
|
import { setScrollPosition } from './setScrollPosition.js';
|
|
18
|
-
import {
|
|
18
|
+
import { scrollRestoration_initialRenderIsDone } from './scrollRestoration.js';
|
|
19
19
|
import { getErrorPageId } from '../../shared/error-page.js';
|
|
20
20
|
import { setPageContextCurrent } from './getPageContextCurrent.js';
|
|
21
21
|
import { getRouteStringParameterList } from '../../shared/route/resolveRouteString.js';
|
|
@@ -31,6 +31,7 @@ const globalObject = getGlobalObject('renderPageClientSide.ts', (() => {
|
|
|
31
31
|
})());
|
|
32
32
|
const { firstRenderStartPromise } = globalObject;
|
|
33
33
|
async function renderPageClientSide(renderArgs) {
|
|
34
|
+
catchInfiniteLoop('renderPageClientSide()');
|
|
34
35
|
const { urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0, doNotRenderIfSamePage, isClientSideNavigation = true, pageContextInitClient } = renderArgs;
|
|
35
36
|
let { scrollTarget } = renderArgs;
|
|
36
37
|
const { previousPageContext } = globalObject;
|
|
@@ -391,18 +392,18 @@ async function renderPageClientSide(renderArgs) {
|
|
|
391
392
|
}
|
|
392
393
|
}
|
|
393
394
|
};
|
|
394
|
-
// We use globalObject.
|
|
395
|
-
if (globalObject.
|
|
395
|
+
// We use globalObject.onRenderClientPreviousPromise in order to ensure that there is never two concurrent onRenderClient() calls
|
|
396
|
+
if (globalObject.onRenderClientPreviousPromise) {
|
|
396
397
|
// Make sure that the previous render has finished
|
|
397
|
-
await globalObject.
|
|
398
|
-
assert(globalObject.
|
|
398
|
+
await globalObject.onRenderClientPreviousPromise;
|
|
399
|
+
assert(globalObject.onRenderClientPreviousPromise === undefined);
|
|
399
400
|
if (isRenderOutdated())
|
|
400
401
|
return;
|
|
401
402
|
}
|
|
402
403
|
changeUrl(urlOriginal, overwriteLastHistoryEntry);
|
|
403
404
|
globalObject.previousPageContext = pageContext;
|
|
404
|
-
assert(globalObject.
|
|
405
|
-
|
|
405
|
+
assert(globalObject.onRenderClientPreviousPromise === undefined);
|
|
406
|
+
const onRenderClientPromise = (async () => {
|
|
406
407
|
let onRenderClientError;
|
|
407
408
|
try {
|
|
408
409
|
await executeOnRenderClientHook(pageContext, true);
|
|
@@ -410,12 +411,13 @@ async function renderPageClientSide(renderArgs) {
|
|
|
410
411
|
catch (err) {
|
|
411
412
|
onRenderClientError = err;
|
|
412
413
|
}
|
|
413
|
-
globalObject.
|
|
414
|
+
globalObject.onRenderClientPreviousPromise = undefined;
|
|
414
415
|
globalObject.isFirstRenderDone = true;
|
|
415
416
|
return onRenderClientError;
|
|
416
417
|
})();
|
|
417
|
-
|
|
418
|
-
|
|
418
|
+
globalObject.onRenderClientPreviousPromise = onRenderClientPromise;
|
|
419
|
+
const onRenderClientError = await onRenderClientPromise;
|
|
420
|
+
assert(globalObject.onRenderClientPreviousPromise === undefined);
|
|
419
421
|
if (onRenderClientError) {
|
|
420
422
|
await onError(onRenderClientError);
|
|
421
423
|
if (!isErrorPage)
|
|
@@ -475,9 +477,8 @@ async function renderPageClientSide(renderArgs) {
|
|
|
475
477
|
}
|
|
476
478
|
}
|
|
477
479
|
// Page scrolling
|
|
478
|
-
setScrollPosition(scrollTarget);
|
|
479
|
-
|
|
480
|
-
setInitialRenderIsDone();
|
|
480
|
+
setScrollPosition(scrollTarget, urlOriginal);
|
|
481
|
+
scrollRestoration_initialRenderIsDone();
|
|
481
482
|
if (pageContext._hasPageContextFromServer)
|
|
482
483
|
setPageContextInitIsPassedToClient(pageContext);
|
|
483
484
|
// Add link prefetch handlers
|
|
@@ -488,7 +489,6 @@ async function renderPageClientSide(renderArgs) {
|
|
|
488
489
|
function changeUrl(url, overwriteLastHistoryEntry) {
|
|
489
490
|
if (getCurrentUrl() === url)
|
|
490
491
|
return;
|
|
491
|
-
browserNativeScrollRestoration_disable();
|
|
492
492
|
pushHistoryState(url, overwriteLastHistoryEntry);
|
|
493
493
|
}
|
|
494
494
|
function handleErrorFetchingStaticAssets(err, pageContext, isFirstRender) {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
declare function
|
|
5
|
-
declare function setInitialRenderIsDone(): void;
|
|
6
|
-
declare function browserNativeScrollRestoration_disable(): void;
|
|
1
|
+
export { scrollRestoration_init };
|
|
2
|
+
export { scrollRestoration_initialRenderIsDone };
|
|
3
|
+
declare function scrollRestoration_init(): void;
|
|
4
|
+
declare function scrollRestoration_initialRenderIsDone(): void;
|
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export { scrollRestoration_init };
|
|
2
|
+
export { scrollRestoration_initialRenderIsDone };
|
|
3
|
+
// Using `window.history.scrollRestoration` to recover scroll position when user reloads the page or Cmd-Shift-T back to it.
|
|
4
|
+
// We let the browser do it because it's fast.
|
|
5
|
+
// - Alternatively we could inject an inline script `<script>scrollTo(history.state.scrollPosition)</script>` early, which seems to be equally fast. (See for example https://vike.dev/usePageContext which sets the main scroll position and the navigation scroll position equally fast.)
|
|
6
|
+
// - Firefox doesn't restore the scroll position upon page reload but does upon Cmd-Shift-T
|
|
7
|
+
// See also: https://github.com/cyco130/knave/blob/e9e1bc7687848504293197f1b314b7d12ad0d228/design.md#scroll-restoration
|
|
5
8
|
import { getGlobalObject, onPageHide, onPageShow } from './utils.js';
|
|
6
9
|
const globalObject = getGlobalObject('scrollRestoration.ts', {});
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
onPageHide(
|
|
11
|
-
onPageShow(() => globalObject.initialRenderIsDone &&
|
|
10
|
+
function scrollRestoration_init() {
|
|
11
|
+
// Use the native scroll restoration mechanism only for the first render
|
|
12
|
+
scrollRestoration_enable();
|
|
13
|
+
onPageHide(scrollRestoration_enable);
|
|
14
|
+
onPageShow(() => globalObject.initialRenderIsDone && scrollRestoration_disable());
|
|
12
15
|
}
|
|
13
|
-
function
|
|
16
|
+
function scrollRestoration_initialRenderIsDone() {
|
|
14
17
|
globalObject.initialRenderIsDone = true;
|
|
18
|
+
scrollRestoration_disable();
|
|
15
19
|
}
|
|
16
|
-
function
|
|
20
|
+
function scrollRestoration_disable() {
|
|
17
21
|
if ('scrollRestoration' in window.history) {
|
|
18
22
|
window.history.scrollRestoration = 'manual';
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
|
-
function
|
|
25
|
+
function scrollRestoration_enable() {
|
|
22
26
|
if ('scrollRestoration' in window.history) {
|
|
27
|
+
// Use the browser's native scroll restoration mechanism
|
|
23
28
|
window.history.scrollRestoration = 'auto';
|
|
24
29
|
}
|
|
25
30
|
}
|