vike 0.4.236 → 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.
Files changed (261) hide show
  1. package/dist/cjs/client/runtime-client-routing/globalContext.js +2 -2
  2. package/dist/cjs/client/runtime-server-routing/globalContext.js +2 -2
  3. package/dist/cjs/client/shared/createGetGlobalContextClient.js +21 -13
  4. package/dist/cjs/client/shared/getJsonSerializedInHtml.js +10 -1
  5. package/dist/cjs/client/shared/utils.js +1 -0
  6. package/dist/cjs/node/api/preview.js +1 -1
  7. package/dist/cjs/node/prerender/runPrerender.js +4 -4
  8. package/dist/cjs/node/runtime/globalContext.js +127 -41
  9. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
  10. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +3 -1
  11. package/dist/cjs/node/runtime/html/serializeContext.js +25 -64
  12. package/dist/cjs/node/runtime/html/stream.js +1 -1
  13. package/dist/cjs/node/runtime/renderPage/analyzePage.js +3 -3
  14. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -7
  15. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -4
  16. package/dist/cjs/node/runtime/renderPage/getPageAssets/{retrieveAssetsDev.js → retrievePageAssetsDev.js} +21 -2
  17. package/dist/cjs/node/runtime/renderPage/getPageAssets/{retrieveAssetsProd.js → retrievePageAssetsProd.js} +19 -2
  18. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +8 -34
  19. package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +50 -14
  20. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +23 -9
  21. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -5
  22. package/dist/cjs/node/runtime/renderPage.js +9 -8
  23. package/dist/cjs/node/runtime/utils.js +4 -0
  24. package/dist/cjs/node/shared/utils.js +1 -0
  25. package/dist/cjs/node/shared/virtualFileId.js +110 -0
  26. package/dist/cjs/node/vite/index.js +5 -3
  27. package/dist/cjs/node/vite/onLoad.js +5 -3
  28. package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +31 -23
  29. package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +3 -3
  30. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +29 -13
  31. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +20 -14
  32. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildEntry.js +4 -4
  33. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +17 -5
  34. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +1 -1
  35. package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +6 -12
  36. package/dist/cjs/node/vite/plugins/pluginCommon.js +1 -0
  37. package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +119 -73
  38. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +8 -15
  39. package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +8 -9
  40. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +7 -3
  41. package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +47 -0
  42. package/dist/cjs/node/vite/plugins/pluginPreview.js +11 -4
  43. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +6 -13
  44. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigsEager.js → generateVirtualFileGlobalEntry.js} +11 -9
  45. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFileEntry.js → generateVirtualFileGlobalEntryWithOldDesign.js} +11 -11
  46. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigLazy.js → generateVirtualFilePageEntry.js} +10 -11
  47. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +67 -0
  48. package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +18 -17
  49. package/dist/cjs/node/vite/shared/findPageFiles.js +1 -1
  50. package/dist/cjs/node/vite/shared/{resolveClientEntriesDev.js → getClientEntrySrcDev.js} +2 -2
  51. package/dist/cjs/node/vite/shared/getMagicString.js +18 -0
  52. package/dist/cjs/node/vite/shared/getManifestFilePathRelative.js +10 -0
  53. package/dist/cjs/node/vite/shared/getOutDirs.js +18 -12
  54. package/dist/cjs/node/vite/shared/getViteConfigRuntime.js +1 -1
  55. package/dist/cjs/node/vite/shared/isViteServerBuild.js +54 -31
  56. package/dist/cjs/node/vite/shared/loggerVite.js +1 -1
  57. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
  58. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -3
  59. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +8 -19
  60. package/dist/cjs/node/vite/utils.js +1 -0
  61. package/dist/cjs/shared/createGlobalContextShared.js +36 -15
  62. package/dist/cjs/shared/getPageFiles/{parseVirtualFileExports.js → parseVirtualFileExportsGlobalEntry.js} +20 -20
  63. package/dist/cjs/shared/getProxyForPublicUsage.js +2 -2
  64. package/dist/cjs/shared/modifyUrlSameOrigin.js +9 -4
  65. package/dist/cjs/shared/page-configs/loadPageEntry.js +25 -0
  66. package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +4 -4
  67. package/dist/cjs/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js} +2 -2
  68. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +16 -16
  69. package/dist/cjs/shared/utils.js +2 -0
  70. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  71. package/dist/cjs/utils/assertSetup.js +7 -5
  72. package/dist/cjs/utils/cast.js +1 -1
  73. package/dist/cjs/utils/debug.js +1 -0
  74. package/dist/cjs/utils/getViteRPC.js +79 -0
  75. package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +1 -0
  76. package/dist/cjs/utils/isRunnableDevEnvironment.js +9 -0
  77. package/dist/cjs/utils/virtualFileId.js +39 -0
  78. package/dist/esm/client/node.js +1 -1
  79. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +3 -3
  80. package/dist/esm/client/runtime-client-routing/getPageContextCurrent.d.ts +2 -2
  81. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +14 -14
  82. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +35 -48
  83. package/dist/esm/client/runtime-client-routing/globalContext.d.ts +3 -3
  84. package/dist/esm/client/runtime-client-routing/globalContext.js +2 -2
  85. package/dist/esm/client/runtime-client-routing/history.d.ts +3 -5
  86. package/dist/esm/client/runtime-client-routing/history.js +39 -22
  87. package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
  88. package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.d.ts +2 -2
  89. package/dist/esm/client/runtime-client-routing/prefetch.d.ts +2 -2
  90. package/dist/esm/client/runtime-client-routing/prefetch.js +2 -2
  91. package/dist/esm/client/runtime-client-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
  92. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +5 -5
  93. package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +43 -30
  94. package/dist/esm/client/runtime-client-routing/utils.d.ts +2 -0
  95. package/dist/esm/client/runtime-client-routing/utils.js +2 -0
  96. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +4 -4
  97. package/dist/esm/client/runtime-server-routing/globalContext.d.ts +3 -3
  98. package/dist/esm/client/runtime-server-routing/globalContext.js +2 -2
  99. package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
  100. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +4 -4
  101. package/dist/esm/client/shared/createGetGlobalContextClient.js +21 -13
  102. package/dist/esm/client/shared/execHookOnRenderClient.d.ts +2 -2
  103. package/dist/esm/client/shared/getJsonSerializedInHtml.js +10 -1
  104. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +1 -1
  105. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +4 -4
  106. package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +2 -2
  107. package/dist/esm/client/shared/utils.d.ts +1 -0
  108. package/dist/esm/client/shared/utils.js +1 -0
  109. package/dist/esm/node/api/preview.js +1 -1
  110. package/dist/esm/node/prerender/runPrerender.d.ts +49 -141
  111. package/dist/esm/node/prerender/runPrerender.js +4 -4
  112. package/dist/esm/node/runtime/globalContext.d.ts +43 -63
  113. package/dist/esm/node/runtime/globalContext.js +128 -42
  114. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
  115. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +4 -2
  116. package/dist/esm/node/runtime/html/serializeContext.d.ts +11 -6
  117. package/dist/esm/node/runtime/html/serializeContext.js +25 -64
  118. package/dist/esm/node/runtime/html/stream.js +1 -1
  119. package/dist/esm/node/runtime/renderPage/analyzePage.js +3 -3
  120. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +13 -36
  121. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -7
  122. package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +2 -2
  123. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -4
  124. package/dist/esm/node/runtime/renderPage/getPageAssets/retrievePageAssetsDev.d.ts +10 -0
  125. package/dist/esm/node/runtime/renderPage/getPageAssets/{retrieveAssetsDev.js → retrievePageAssetsDev.js} +22 -3
  126. package/dist/esm/node/runtime/renderPage/getPageAssets/retrievePageAssetsProd.d.ts +10 -0
  127. package/dist/esm/node/runtime/renderPage/getPageAssets/{retrieveAssetsProd.js → retrievePageAssetsProd.js} +19 -2
  128. package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +0 -6
  129. package/dist/esm/node/runtime/renderPage/getPageAssets.js +8 -34
  130. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
  131. package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.d.ts +1 -1
  132. package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +51 -15
  133. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +3 -3
  134. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +26 -12
  135. package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
  136. package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +2 -3
  137. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +30 -77
  138. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -5
  139. package/dist/esm/node/runtime/renderPage.d.ts +13 -35
  140. package/dist/esm/node/runtime/renderPage.js +9 -8
  141. package/dist/esm/node/runtime/utils.d.ts +4 -0
  142. package/dist/esm/node/runtime/utils.js +4 -0
  143. package/dist/esm/node/shared/utils.d.ts +1 -0
  144. package/dist/esm/node/shared/utils.js +1 -0
  145. package/dist/esm/node/shared/virtualFileId.d.ts +28 -0
  146. package/dist/esm/node/shared/virtualFileId.js +107 -0
  147. package/dist/esm/node/vite/index.js +5 -3
  148. package/dist/esm/node/vite/onLoad.js +5 -3
  149. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +3 -3
  150. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +32 -24
  151. package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +3 -3
  152. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +29 -13
  153. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +0 -2
  154. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +21 -14
  155. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildEntry.js +4 -4
  156. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +17 -5
  157. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +1 -1
  158. package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +7 -10
  159. package/dist/esm/node/vite/plugins/pluginCommon.d.ts +3 -0
  160. package/dist/esm/node/vite/plugins/pluginCommon.js +1 -0
  161. package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +121 -75
  162. package/dist/esm/node/vite/plugins/pluginEnvVars.js +6 -10
  163. package/dist/esm/node/vite/plugins/pluginExtractAssets.js +7 -8
  164. package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +6 -2
  165. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.d.ts +26 -0
  166. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +45 -0
  167. package/dist/esm/node/vite/plugins/pluginPreview.js +13 -6
  168. package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +6 -10
  169. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.d.ts +2 -0
  170. package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigsEager.js → generateVirtualFileGlobalEntry.js} +11 -9
  171. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.d.ts +6 -0
  172. package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFileEntry.js → generateVirtualFileGlobalEntryWithOldDesign.js} +11 -11
  173. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.d.ts +3 -0
  174. package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigLazy.js → generateVirtualFilePageEntry.js} +10 -11
  175. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +14 -0
  176. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +65 -0
  177. package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +17 -16
  178. package/dist/esm/node/vite/shared/findPageFiles.js +1 -1
  179. package/dist/esm/node/vite/shared/getClientEntrySrcDev.d.ts +4 -0
  180. package/dist/esm/node/vite/shared/{resolveClientEntriesDev.js → getClientEntrySrcDev.js} +2 -2
  181. package/dist/esm/node/vite/shared/getMagicString.d.ts +9 -0
  182. package/dist/esm/node/vite/shared/getMagicString.js +13 -0
  183. package/dist/esm/node/vite/shared/getManifestFilePathRelative.d.ts +2 -0
  184. package/dist/esm/node/vite/shared/getManifestFilePathRelative.js +8 -0
  185. package/dist/esm/node/vite/shared/getOutDirs.d.ts +6 -3
  186. package/dist/esm/node/vite/shared/getOutDirs.js +19 -13
  187. package/dist/esm/node/vite/shared/getViteConfigRuntime.js +1 -1
  188. package/dist/esm/node/vite/shared/isViteServerBuild.d.ts +14 -11
  189. package/dist/esm/node/vite/shared/isViteServerBuild.js +55 -31
  190. package/dist/esm/node/vite/shared/loggerVite.js +1 -1
  191. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +2 -2
  192. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
  193. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -3
  194. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +3 -5
  195. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +10 -21
  196. package/dist/esm/node/vite/utils.d.ts +1 -0
  197. package/dist/esm/node/vite/utils.js +1 -0
  198. package/dist/esm/shared/createGlobalContextShared.d.ts +8 -8
  199. package/dist/esm/shared/createGlobalContextShared.js +38 -17
  200. package/dist/esm/shared/getPageFiles/{parseVirtualFileExports.d.ts → parseVirtualFileExportsGlobalEntry.d.ts} +2 -2
  201. package/dist/esm/shared/getPageFiles/{parseVirtualFileExports.js → parseVirtualFileExportsGlobalEntry.js} +20 -20
  202. package/dist/esm/shared/getPageFiles.d.ts +1 -1
  203. package/dist/esm/shared/hooks/execHook.d.ts +2 -2
  204. package/dist/esm/shared/hooks/getHook.d.ts +3 -3
  205. package/dist/esm/shared/modifyUrlSameOrigin.d.ts +1 -1
  206. package/dist/esm/shared/modifyUrlSameOrigin.js +9 -4
  207. package/dist/esm/shared/page-configs/loadPageEntry.d.ts +3 -0
  208. package/dist/esm/shared/page-configs/loadPageEntry.js +23 -0
  209. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.d.ts +9 -9
  210. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +4 -4
  211. package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +1 -1
  212. package/dist/esm/shared/page-configs/serialize/{parsePageConfigs.d.ts → parsePageConfigsSerialized.d.ts} +2 -2
  213. package/dist/esm/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js} +2 -2
  214. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -2
  215. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +17 -17
  216. package/dist/esm/shared/utils.d.ts +2 -0
  217. package/dist/esm/shared/utils.js +2 -0
  218. package/dist/esm/types/Config.d.ts +33 -98
  219. package/dist/esm/types/PageConfig.d.ts +9 -7
  220. package/dist/esm/types/VikeNamespace.d.ts +13 -0
  221. package/dist/esm/types/index.d.ts +3 -1
  222. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  223. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  224. package/dist/esm/utils/assertSetup.js +7 -5
  225. package/dist/esm/utils/cast.d.ts +2 -2
  226. package/dist/esm/utils/cast.js +1 -1
  227. package/dist/esm/utils/debug.d.ts +1 -1
  228. package/dist/esm/utils/debug.js +1 -0
  229. package/dist/esm/utils/getViteRPC.d.ts +6 -0
  230. package/dist/esm/utils/getViteRPC.js +77 -0
  231. package/dist/esm/utils/isFilePathAbsoluteFilesystem.d.ts +7 -0
  232. package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -0
  233. package/dist/esm/utils/isRunnableDevEnvironment.d.ts +3 -0
  234. package/dist/esm/utils/isRunnableDevEnvironment.js +7 -0
  235. package/dist/esm/utils/objectFilter.d.ts +1 -1
  236. package/dist/esm/utils/virtualFileId.d.ts +6 -0
  237. package/dist/esm/{node/shared/virtualFiles.js → utils/virtualFileId.js} +15 -17
  238. package/package.json +16 -7
  239. package/dist/cjs/node/shared/virtualFiles/virtualFileEntry.js +0 -29
  240. package/dist/cjs/node/shared/virtualFiles/virtualFilePageConfigLazy.js +0 -39
  241. package/dist/cjs/node/shared/virtualFiles.js +0 -41
  242. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -23
  243. package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +0 -10
  244. package/dist/cjs/shared/page-configs/loadConfigValues.js +0 -21
  245. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.d.ts +0 -4
  246. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +0 -4
  247. package/dist/esm/node/shared/virtualFiles/virtualFileEntry.d.ts +0 -11
  248. package/dist/esm/node/shared/virtualFiles/virtualFileEntry.js +0 -26
  249. package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.d.ts +0 -9
  250. package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.js +0 -37
  251. package/dist/esm/node/shared/virtualFiles.d.ts +0 -8
  252. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFileEntry.d.ts +0 -5
  253. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.d.ts +0 -3
  254. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.d.ts +0 -2
  255. package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.d.ts +0 -7
  256. package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -21
  257. package/dist/esm/node/vite/shared/applyRegExWithMagicString.d.ts +0 -3
  258. package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +0 -8
  259. package/dist/esm/node/vite/shared/resolveClientEntriesDev.d.ts +0 -4
  260. package/dist/esm/shared/page-configs/loadConfigValues.d.ts +0 -3
  261. package/dist/esm/shared/page-configs/loadConfigValues.js +0 -19
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRunnableDevEnvironment = isRunnableDevEnvironment;
4
+ // We use this instead of `import { isRunnableDevEnvironment } from 'vite'` because:
5
+ // - Vite's isRunnableDevEnvironment() isn't reliable in monorepos where multiple Vite instances can be used simultaneously (it uses `instanceof RunnableDevEnvironment` which fails)
6
+ // - We can use this in Vike's server production runtime without having to load the 'vite' package
7
+ function isRunnableDevEnvironment(environment) {
8
+ return !!environment && 'runner' in environment && !!environment.runner;
9
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isVirtualFileId = isVirtualFileId;
7
+ exports.addVirtualFileIdPrefix = addVirtualFileIdPrefix;
8
+ exports.removeVirtualFileIdPrefix = removeVirtualFileIdPrefix;
9
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
+ const assert_js_1 = require("./assert.js");
11
+ const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
12
+ (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
13
+ const idBase = 'virtual:vike:';
14
+ // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
15
+ const prefix = '\0';
16
+ function isVirtualFileId(id) {
17
+ if (id.startsWith(idBase))
18
+ return true;
19
+ if (id.startsWith(prefix + idBase))
20
+ return true;
21
+ // https://github.com/vikejs/vike/issues/1985
22
+ (0, assert_js_1.assertUsage)(!id.includes(idBase), `Encountered a module ID ${picocolors_1.default.cyan(id)} that is unexpected. Are you using a tool that modifies the ID of modules? For example, the baseUrl setting in tsconfig.json cannot be used.`);
23
+ return false;
24
+ }
25
+ function addVirtualFileIdPrefix(id) {
26
+ (0, assert_js_1.assert)(isVirtualFileId(id));
27
+ if (!id.startsWith(prefix)) {
28
+ id = prefix + id;
29
+ }
30
+ (0, assert_js_1.assert)(id.startsWith(prefix));
31
+ return id;
32
+ }
33
+ function removeVirtualFileIdPrefix(id) {
34
+ if (id.startsWith(prefix)) {
35
+ id = id.slice(prefix.length);
36
+ }
37
+ (0, assert_js_1.assert)(!id.startsWith(prefix));
38
+ return id;
39
+ }
@@ -1,4 +1,4 @@
1
- import { assertUsage } from './runtime-server-routing/utils.js';
1
+ import { assertUsage } from '../utils/assert.js';
2
2
  assertUsage(false, [
3
3
  'Server imports are forbidden on the client-side:',
4
4
  " import { something } from 'vike/server'",
@@ -10,7 +10,7 @@ declare function createPageContextClientSide(urlOriginal: string): Promise<{
10
10
  _globalContext: {
11
11
  isGlobalContext: true;
12
12
  _isOriginalObject: true;
13
- _virtualFileExports: unknown;
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,14 +23,14 @@ 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").VikeConfigPublicPageEager;
26
+ [k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEagerLoaded;
27
27
  };
28
28
  } & {
29
29
  isClientSide: true;
30
30
  } & {
31
31
  _pageRoutes: import("../../__internal/index.js").PageRoutes;
32
32
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
33
- };
33
+ } & Record<string, any>;
34
34
  _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
35
35
  _urlHandler: null;
36
36
  _urlRewrite: null | string;
@@ -1,7 +1,7 @@
1
1
  export { setPageContextCurrent };
2
2
  export { getPageContextCurrent };
3
- import type { VikeConfigPublicPageLazy } from '../../shared/getPageFiles.js';
4
- type PageContextCurrent = VikeConfigPublicPageLazy & {
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 { VikeConfigPublicPageLazy, PageFile } from '../../shared/getPageFiles.js';
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 & VikeConfigPublicPageLazy & {
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
- _virtualFileExports: unknown;
33
+ _virtualFileExportsGlobalEntry: unknown;
34
34
  _pageFilesAll: PageFile[];
35
35
  _pageConfigs: import("../../types/PageConfig.js").PageConfigRuntime[];
36
36
  _pageConfigGlobal: import("../../types/PageConfig.js").PageConfigGlobalRuntime;
@@ -43,14 +43,14 @@ 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").VikeConfigPublicPageEager;
46
+ [k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEagerLoaded;
47
47
  };
48
48
  } & {
49
49
  isClientSide: true;
50
50
  } & {
51
51
  _pageRoutes: import("../../__internal/index.js").PageRoutes;
52
52
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
53
- };
53
+ } & Record<string, any>;
54
54
  _pageFilesAll: PageFile[];
55
55
  _urlHandler: null;
56
56
  _urlRewrite: null | string;
@@ -70,7 +70,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
70
70
  isHydration: boolean;
71
71
  previousPageContext: ({
72
72
  pageId: string;
73
- } & VikeConfigPublicPageLazy & {
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
- } & VikeConfigPublicPageLazy & {
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 & VikeConfigPublicPageLazy & PageContextForPublicUsageClient, isErrorPage: boolean): Promise<{
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
- _virtualFileExports: unknown;
247
+ _virtualFileExportsGlobalEntry: unknown;
248
248
  _pageFilesAll: PageFile[];
249
249
  _pageConfigs: import("../../types/PageConfig.js").PageConfigRuntime[];
250
250
  _pageConfigGlobal: import("../../types/PageConfig.js").PageConfigGlobalRuntime;
@@ -257,14 +257,14 @@ 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").VikeConfigPublicPageEager;
260
+ [k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEagerLoaded;
261
261
  };
262
262
  } & {
263
263
  isClientSide: true;
264
264
  } & {
265
265
  _pageRoutes: import("../../__internal/index.js").PageRoutes;
266
266
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
267
- };
267
+ } & Record<string, any>;
268
268
  _pageFilesAll: PageFile[];
269
269
  _urlHandler: null;
270
270
  _urlRewrite: null | string;
@@ -284,7 +284,7 @@ declare function getPageContextFromClientHooks(pageContext: {
284
284
  isHydration: boolean;
285
285
  previousPageContext: ({
286
286
  pageId: string;
287
- } & VikeConfigPublicPageLazy & {
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
- } & VikeConfigPublicPageLazy & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & Omit<Partial<{
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 = VikeConfigPublicPageLazy & PageContextForPublicUsageClient;
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 dataHookExec = false;
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
- dataHookExec = true;
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 ((dataHookExec && dataHookEnv.client) || (pageContext._hasPageContextFromServer && dataHookEnv.server)) {
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
- return (!!globalObject.pageContextInitIsPassedToClient ||
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._globalContext._pageConfigs.length > 0) {
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
- const pageContextUrl = getPageContextRequestUrl(pageContext._urlRewrite ?? pageContext.urlOriginal);
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(pageContextFromServer) {
239
- removeBuiltInOverrides(pageContextFromServer);
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
- _virtualFileExports: unknown;
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,11 +20,11 @@ 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").VikeConfigPublicPageEager;
23
+ [k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEagerLoaded;
24
24
  };
25
25
  } & {
26
26
  isClientSide: true;
27
27
  } & {
28
28
  _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
29
29
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
30
- }>;
30
+ } & Record<string, any>>;
@@ -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 virtualFileExports from 'virtual:vike:entry:client:client-routing';
6
- const getGlobalContextClientInternal = createGetGlobalContextClient(virtualFileExports, true, addGlobalContext);
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 { initHistoryState };
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: string): void;
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 initHistoryState(): void;
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 { initHistoryState };
6
- export { monkeyPatchHistoryAPI };
5
+ export { initHistory };
7
6
  import { getCurrentUrl } from '../shared/getCurrentUrl.js';
8
- import { assert, assertUsage, getGlobalObject, isObject } from './utils.js';
9
- initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
10
- const globalObject = getGlobalObject('runtime-client-routing/history.ts', { previous: getHistoryInfo() });
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
- const stateNotEnhanced = getStateNotEnhanced();
17
- if (isVikeEnhanced(stateNotEnhanced))
19
+ if (isVikeEnhanced(window.history.state))
18
20
  return;
19
- const stateVikeEnhanced = enhance(stateNotEnhanced);
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
- assert(isVikeEnhanced(stateVikeEnhanced));
47
+ assertIsVikeEnhanced(stateVikeEnhanced);
45
48
  return stateVikeEnhanced;
46
49
  }
47
50
  function getState() {
48
- const state = getStateNotEnhanced();
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
- assert(isVikeEnhanced(state), { state });
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
- assert(isVikeEnhanced(stateEnhanced));
118
- const ret = funcOriginal(stateEnhanced, ...rest);
119
+ assertIsVikeEnhanced(stateEnhanced);
120
+ funcOriginal(stateEnhanced, ...rest);
121
+ assert(deepEqual(stateEnhanced, window.history.state));
119
122
  globalObject.previous = getHistoryInfo();
120
- return ret;
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
- assert(isVikeEnhanced(window.history.state));
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 initHistoryState() {
156
- enhanceHistoryState();
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
  }
@@ -6,7 +6,7 @@ import { initOnLinkClick } from './initOnLinkClick.js';
6
6
  import { scrollRestoration_init } from './scrollRestoration.js';
7
7
  import { autoSaveScrollPosition } from './setScrollPosition.js';
8
8
  import { initLinkPrefetchHandlers } from './prefetch.js';
9
- import { initHistoryState, monkeyPatchHistoryAPI } from './history.js';
9
+ import { initHistory } from './history.js';
10
10
  async function initClientRouter() {
11
11
  // Init navigation history and scroll restoration
12
12
  initHistoryAndScroll();
@@ -29,8 +29,7 @@ async function renderFirstPage() {
29
29
  }
30
30
  function initHistoryAndScroll() {
31
31
  scrollRestoration_init();
32
- monkeyPatchHistoryAPI();
33
- initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
32
+ initHistory(); // we redundantly call initHistory() to ensure it's called early
34
33
  autoSaveScrollPosition();
35
34
  // Handle back-/forward navigation
36
35
  initOnPopState();
@@ -1,10 +1,10 @@
1
1
  export { getPrefetchSettings };
2
2
  export { PAGE_CONTEXT_MAX_AGE_DEFAULT };
3
3
  export type { PrefetchSettingResolved };
4
- import type { VikeConfigPublicPageLazy } from '../../../shared/getPageFiles.js';
4
+ import type { VikeConfigPublicPageLazyLoaded } from '../../../shared/getPageFiles.js';
5
5
  declare const PAGE_CONTEXT_MAX_AGE_DEFAULT = 5000;
6
6
  type PrefetchSettingResolved = {
7
7
  staticAssets: false | 'hover' | 'viewport';
8
8
  pageContext: false | number;
9
9
  };
10
- declare function getPrefetchSettings(pageContext: VikeConfigPublicPageLazy, linkTag: null | HTMLElement): PrefetchSettingResolved;
10
+ declare function getPrefetchSettings(pageContext: VikeConfigPublicPageLazyLoaded, linkTag: null | HTMLElement): PrefetchSettingResolved;
@@ -7,14 +7,14 @@ export { addLinkPrefetchHandlers_watch };
7
7
  export { addLinkPrefetchHandlers_unwatch };
8
8
  import { type PageContextCreated } from './createPageContextClientSide.js';
9
9
  import { type PageContextFromServerHooks, getPageContextFromServerHooks } from './getPageContextFromHooks.js';
10
- import type { VikeConfigPublicPageLazy } from '../../shared/getPageFiles.js';
10
+ import type { VikeConfigPublicPageLazyLoaded } from '../../shared/getPageFiles.js';
11
11
  type ResultPageContextFromServer = Awaited<ReturnType<typeof getPageContextFromServerHooks>>;
12
12
  type PageContextForPrefetch = PageContextCreated & {
13
13
  pageId: string;
14
14
  };
15
15
  declare function getPageContextPrefetched(pageContext: {
16
16
  urlPathname: string;
17
- } & VikeConfigPublicPageLazy): null | PageContextFromServerHooks;
17
+ } & VikeConfigPublicPageLazyLoaded): null | PageContextFromServerHooks;
18
18
  declare function populatePageContextPrefetchCache(pageContext: PageContextForPrefetch, result: ResultPageContextFromServer): void;
19
19
  /**
20
20
  * Programmatically prefetch client assets.
@@ -60,8 +60,8 @@ async function prefetchPageContextFromServerHooks(pageContextLink, resultMaxAge)
60
60
  const result = await getPageContextFromServerHooks(pageContextLink, false);
61
61
  setPageContextPrefetchCache(pageContextLink, result, resultMaxAge);
62
62
  }
63
- function populatePageContextPrefetchCache(pageContext /*& VikeConfigPublicPageLazy*/, result) {
64
- // TO-DO/pageContext-prefetch: replace with using pageContext.config.prerender instead. (For being able to do that: eager configs need to be accessible without have to use VikeConfigPublicPageLazy as it isn't available here.)
63
+ function populatePageContextPrefetchCache(pageContext /*& VikeConfigPublicPageLazyLoaded*/, result) {
64
+ // TO-DO/pageContext-prefetch: replace with using pageContext.config.prerender instead. (For being able to do that: eager configs need to be accessible without have to use VikeConfigPublicPageLazyLoaded as it isn't available here.)
65
65
  if (!isBrilloutDocpress())
66
66
  return;
67
67
  setPageContextPrefetchCache(pageContext, result, null);
@@ -1,9 +1,9 @@
1
1
  export { preparePageContextForPublicUsageClient };
2
2
  export type { PageContextForPublicUsageClient };
3
- import type { VikeConfigPublicPageLazy } from '../../shared/getPageFiles.js';
3
+ import type { VikeConfigPublicPageLazyLoaded } from '../../shared/getPageFiles.js';
4
4
  import type { PageContextInternalClient_ClientRouting } from '../../types/PageContext.js';
5
5
  import type { PageContextPrepareMinimum } from '../../shared/preparePageContextForPublicUsage.js';
6
- type PageContextForPublicUsageClient = PageContextPrepareMinimum & PageContextInternalClient_ClientRouting & VikeConfigPublicPageLazy & {
6
+ type PageContextForPublicUsageClient = PageContextPrepareMinimum & PageContextInternalClient_ClientRouting & VikeConfigPublicPageLazyLoaded & {
7
7
  urlOriginal: string;
8
8
  };
9
9
  declare function preparePageContextForPublicUsageClient<PageContext extends PageContextForPublicUsageClient>(pageContext: PageContext): PageContext & {