vike 0.4.247-commit-a642bde → 0.4.247-commit-903de25
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/esm/client/runtime-client-routing/getPageContextFromHooks.js +28 -21
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +9 -0
- package/dist/esm/types/Config.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// TODO/now: rename
|
|
1
2
|
export { getPageContextFromHooks_isHydration };
|
|
2
3
|
export { getPageContextFromHooks_serialized };
|
|
3
4
|
export { getPageContextFromServerHooks };
|
|
@@ -20,6 +21,10 @@ import { isServerSideError } from '../../shared/misc/isServerSideError.js';
|
|
|
20
21
|
import { execHook } from '../../shared/hooks/execHook.js';
|
|
21
22
|
import { preparePageContextForPublicUsageClient, } from './preparePageContextForPublicUsageClient.js';
|
|
22
23
|
const globalObject = getGlobalObject('runtime-client-routing/getPageContextFromHooks.ts', {});
|
|
24
|
+
// TO-DO/soon/cumulative-hooks: filter & execute all client-only hooks (see other TO-DO/soon/cumulative-hooks entries)
|
|
25
|
+
// - The client-side needs to know what hooks are client-only
|
|
26
|
+
// - Possible implementation: new computed prop `clientOnlyHooks: string[]` (list of hook ids) and add `hookId` to serialized config values
|
|
27
|
+
const clientHooks = ['guard', 'data', 'onBeforeRender'];
|
|
23
28
|
// TO-DO/eventually: rename
|
|
24
29
|
function getPageContextFromHooks_serialized() {
|
|
25
30
|
const pageContextSerialized = getPageContextSerializedInHtml();
|
|
@@ -31,11 +36,13 @@ function getPageContextFromHooks_serialized() {
|
|
|
31
36
|
}
|
|
32
37
|
// TO-DO/eventually: rename
|
|
33
38
|
async function getPageContextFromHooks_isHydration(pageContext) {
|
|
34
|
-
for (const hookName of
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
for (const hookName of clientHooks) {
|
|
40
|
+
if (!hookClientOnlyExists(hookName, pageContext))
|
|
41
|
+
continue;
|
|
42
|
+
if (hookName === 'guard') {
|
|
43
|
+
await execHookGuardClient(pageContext);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
39
46
|
await execHookDataLike(hookName, pageContext);
|
|
40
47
|
}
|
|
41
48
|
}
|
|
@@ -73,24 +80,18 @@ async function getPageContextFromClientHooks(pageContext, isErrorPage) {
|
|
|
73
80
|
// server-side, so we run only the client-only ones in this case.
|
|
74
81
|
// Note: for the error page, we also execute the client-side data() and onBeforeRender() hooks, but maybe we
|
|
75
82
|
// shouldn't? The server-side does it as well (but maybe it shouldn't).
|
|
76
|
-
for (const hookName of
|
|
83
|
+
for (const hookName of clientHooks) {
|
|
84
|
+
if (!hookClientOnlyExists(hookName, pageContext) && pageContext._hasPageContextFromServer)
|
|
85
|
+
continue;
|
|
77
86
|
if (hookName === 'guard') {
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// Should we really call the guard() hook on the client-side? Shouldn't we make the guard() hook a server-side
|
|
82
|
-
// only hook? Or maybe make its env configurable like data() and onBeforeRender()?
|
|
83
|
-
await execHookGuard(pageContext, (pageContext) => preparePageContextForPublicUsageClient(pageContext));
|
|
84
|
-
}
|
|
87
|
+
if (isErrorPage)
|
|
88
|
+
continue;
|
|
89
|
+
await execHookGuardClient(pageContext);
|
|
85
90
|
}
|
|
86
91
|
else {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
dataHookExecuted = true;
|
|
91
|
-
// This won't do anything if no hook has been defined or if the hook's env.client is false.
|
|
92
|
-
await execHookDataLike(hookName, pageContext);
|
|
93
|
-
}
|
|
92
|
+
if (hookName === 'data')
|
|
93
|
+
dataHookExecuted = true;
|
|
94
|
+
await execHookDataLike(hookName, pageContext);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
// Execute +onData
|
|
@@ -104,6 +105,9 @@ async function getPageContextFromClientHooks(pageContext, isErrorPage) {
|
|
|
104
105
|
async function execHookClient(hookName, pageContext) {
|
|
105
106
|
return await execHook(hookName, pageContext, (p) => preparePageContextForPublicUsageClient(p));
|
|
106
107
|
}
|
|
108
|
+
// It's a no-op if:
|
|
109
|
+
// - No hook has been defined, or
|
|
110
|
+
// - The hook's `env.client` is `false`
|
|
107
111
|
async function execHookDataLike(hookName, pageContext) {
|
|
108
112
|
let pageContextFromHook;
|
|
109
113
|
if (hookName === 'data') {
|
|
@@ -178,7 +182,7 @@ function hookClientOnlyExists(hookName, pageContext) {
|
|
|
178
182
|
}
|
|
179
183
|
function getHookEnv(hookName, pageContext) {
|
|
180
184
|
if (isOldDesign(pageContext)) {
|
|
181
|
-
// Client-only onBeforeRender() or
|
|
185
|
+
// Client-only onBeforeRender(), data(), or guard() hooks were never supported for the V0.4 design
|
|
182
186
|
return { client: false, server: true };
|
|
183
187
|
}
|
|
184
188
|
const pageConfig = getPageConfig(pageContext.pageId, pageContext._globalContext._pageConfigs);
|
|
@@ -225,3 +229,6 @@ function processPageContextFromServer(pageContext) {
|
|
|
225
229
|
function isOldDesign(pageContext) {
|
|
226
230
|
return pageContext._globalContext._pageConfigs.length === 0;
|
|
227
231
|
}
|
|
232
|
+
async function execHookGuardClient(pageContext) {
|
|
233
|
+
await execHookGuard(pageContext, (pageContext) => preparePageContextForPublicUsageClient(pageContext));
|
|
234
|
+
}
|
|
@@ -142,6 +142,7 @@ const configDefinitionsBuiltIn = {
|
|
|
142
142
|
!!getConfigEnv(pageConfig, 'Page')?.client);
|
|
143
143
|
},
|
|
144
144
|
},
|
|
145
|
+
// TODO/now: rename entries comments
|
|
145
146
|
// TO-DO/soon/cumulative-hooks: remove and replace with new computed prop `clientOnlyHooks: string[]` (see other TO-DO/soon/cumulative-hooks entries)
|
|
146
147
|
onBeforeRenderEnv: {
|
|
147
148
|
env: { client: true },
|
|
@@ -158,6 +159,14 @@ const configDefinitionsBuiltIn = {
|
|
|
158
159
|
return !isConfigSet(pageConfig, 'data') ? null : getConfigEnv(pageConfig, 'data');
|
|
159
160
|
},
|
|
160
161
|
},
|
|
162
|
+
// TO-DO/soon/cumulative-hooks: remove and replace with new computed prop `clientOnlyHooks: string[]` (see other TO-DO/soon/cumulative-hooks entries)
|
|
163
|
+
guardEnv: {
|
|
164
|
+
env: { client: true },
|
|
165
|
+
eager: true,
|
|
166
|
+
_computed: (pageConfig) => {
|
|
167
|
+
return !isConfigSet(pageConfig, 'guard') ? null : getConfigEnv(pageConfig, 'guard');
|
|
168
|
+
},
|
|
169
|
+
},
|
|
161
170
|
hooksTimeout: {
|
|
162
171
|
env: { server: true, client: true },
|
|
163
172
|
},
|
|
@@ -52,7 +52,7 @@ type HookName = HookNamePage | HookNameGlobal;
|
|
|
52
52
|
type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data' | 'onData' | 'route';
|
|
53
53
|
type HookNameGlobal = 'onBeforeRoute' | 'onPrerenderStart' | 'onCreatePageContext' | 'onCreateGlobalContext' | 'onError';
|
|
54
54
|
type HookNameOldDesign = 'render' | 'prerender' | 'onBeforePrerender';
|
|
55
|
-
type ConfigNameBuiltIn = Exclude<keyof ConfigBuiltIn, keyof VikeVitePluginOptions | 'onBeforeRoute' | 'onPrerenderStart' | 'vite' | 'redirects'> | 'prerender' | 'hasServerOnlyHook' | 'isClientRuntimeLoaded' | 'onBeforeRenderEnv' | 'dataEnv' | 'hooksTimeout' | 'clientHooks' | 'middleware';
|
|
55
|
+
type ConfigNameBuiltIn = Exclude<keyof ConfigBuiltIn, keyof VikeVitePluginOptions | 'onBeforeRoute' | 'onPrerenderStart' | 'vite' | 'redirects'> | 'prerender' | 'hasServerOnlyHook' | 'isClientRuntimeLoaded' | 'onBeforeRenderEnv' | 'dataEnv' | 'guardEnv' | 'hooksTimeout' | 'clientHooks' | 'middleware';
|
|
56
56
|
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization' | 'vite';
|
|
57
57
|
type Config = ConfigBuiltIn & Vike.Config;
|
|
58
58
|
/** @deprecated This type is deprecated, see:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.247-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.247-commit-903de25";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.247-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.247-commit-903de25';
|