vike 0.4.147-commit-f9a91f3 → 0.4.148-commit-7596dcd
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/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +17 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +12 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +28 -10
- package/dist/cjs/node/prerender/runPrerender.js +20 -22
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderHook.js +1 -1
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -3
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +21 -18
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +3 -3
- package/dist/cjs/shared/hooks/executeHook.js +18 -29
- package/dist/cjs/shared/hooks/getHook.js +104 -3
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +1 -1
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +4 -4
- package/dist/cjs/shared/route/loadPageRoutes.js +10 -15
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +18 -12
- package/dist/esm/client/shared/executeOnRenderClientHook.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +17 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +12 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +28 -10
- package/dist/esm/node/prerender/runPrerender.js +22 -24
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderHook.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -3
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +7 -7
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +22 -19
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +1 -1
- package/dist/esm/shared/hooks/executeHook.d.ts +2 -2
- package/dist/esm/shared/hooks/executeHook.js +18 -29
- package/dist/esm/shared/hooks/getHook.d.ts +17 -7
- package/dist/esm/shared/hooks/getHook.js +103 -3
- package/dist/esm/shared/page-configs/Config.d.ts +21 -13
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +1 -1
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +1 -1
- package/dist/esm/shared/route/executeGuardHook.js +4 -3
- package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +1 -8
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +6 -6
- package/dist/esm/shared/route/index.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +11 -16
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +1 -1
- /package/dist/cjs/shared/page-configs/serialize/{assertPageConfigs.js → assertPageConfigsSerialized.js} +0 -0
- /package/dist/esm/shared/page-configs/serialize/{assertPageConfigs.d.ts → assertPageConfigsSerialized.d.ts} +0 -0
- /package/dist/esm/shared/page-configs/serialize/{assertPageConfigs.js → assertPageConfigsSerialized.js} +0 -0
|
@@ -12,8 +12,8 @@ function isUserHookError(err) {
|
|
|
12
12
|
return false;
|
|
13
13
|
return globalObject.userHookErrors.get(err) ?? false;
|
|
14
14
|
}
|
|
15
|
-
function executeHook(
|
|
16
|
-
const { timeoutErr, timeoutWarn } =
|
|
15
|
+
function executeHook(hookFnCaller, hook) {
|
|
16
|
+
const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn } } = hook;
|
|
17
17
|
let resolve;
|
|
18
18
|
let reject;
|
|
19
19
|
const promise = new Promise((resolve_, reject_) => {
|
|
@@ -27,19 +27,23 @@ function executeHook(hookFn, hookName, hookFilePath) {
|
|
|
27
27
|
};
|
|
28
28
|
});
|
|
29
29
|
const clearTimeouts = () => {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
if (currentTimeoutWarn)
|
|
31
|
+
clearTimeout(currentTimeoutWarn);
|
|
32
|
+
if (currentTimeoutErr)
|
|
33
|
+
clearTimeout(currentTimeoutErr);
|
|
32
34
|
};
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const currentTimeoutWarn = isNotDisabled(timeoutWarn) &&
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
assertWarning(false, `The ${hookName}() hook defined by ${hookFilePath} is slow: it's taking more than ${humanizeTime(timeoutWarn)} (https://vike.dev/hooksTimeout)`, { onlyOnce: false });
|
|
38
|
+
}, timeoutWarn);
|
|
39
|
+
const currentTimeoutErr = isNotDisabled(timeoutErr) &&
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
const err = getProjectError(`The ${hookName}() hook defined by ${hookFilePath} timed out: it didn't finish after ${humanizeTime(timeoutErr)} (https://vike.dev/hooksTimeout)`);
|
|
42
|
+
reject(err);
|
|
43
|
+
}, timeoutErr);
|
|
40
44
|
(async () => {
|
|
41
45
|
try {
|
|
42
|
-
const ret = await
|
|
46
|
+
const ret = await hookFnCaller();
|
|
43
47
|
resolve(ret);
|
|
44
48
|
}
|
|
45
49
|
catch (err) {
|
|
@@ -51,21 +55,6 @@ function executeHook(hookFn, hookName, hookFilePath) {
|
|
|
51
55
|
})();
|
|
52
56
|
return promise;
|
|
53
57
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
timeoutErr: 5 * 1000,
|
|
58
|
-
timeoutWarn: 1 * 1000
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if (hookName === 'onBeforePrerender') {
|
|
62
|
-
return {
|
|
63
|
-
timeoutErr: 10 * 60 * 1000,
|
|
64
|
-
timeoutWarn: 30 * 1000
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
timeoutErr: 40 * 1000,
|
|
69
|
-
timeoutWarn: 4 * 1000
|
|
70
|
-
};
|
|
58
|
+
function isNotDisabled(timeout) {
|
|
59
|
+
return !!timeout && timeout !== Infinity;
|
|
71
60
|
}
|
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
export { getHook };
|
|
2
|
+
export { getHookFromPageConfig };
|
|
3
|
+
export { getHookFromPageConfigGlobal };
|
|
2
4
|
export { assertHook };
|
|
3
|
-
export { assertHookFn };
|
|
4
5
|
export type { Hook };
|
|
5
6
|
export type { HookName };
|
|
6
7
|
export type { HookLoc };
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
export type { HookTimeout };
|
|
9
|
+
export type { HooksTimeoutProvidedByUser };
|
|
10
|
+
export { getHookTimeoutDefault };
|
|
11
|
+
import type { PageContextExports } from '../getPageFiles.js';
|
|
12
|
+
import type { HookName, HookNamePage, HookNameGlobal } from '../page-configs/Config.js';
|
|
13
|
+
import type { PageConfigBuildTime, PageConfigGlobalRuntime, PageConfigRuntime } from '../page-configs/PageConfig.js';
|
|
9
14
|
type Hook = HookLoc & {
|
|
10
15
|
hookFn: HookFn;
|
|
16
|
+
hookTimeout: HookTimeout;
|
|
11
17
|
};
|
|
12
18
|
type HookLoc = {
|
|
13
19
|
hookName: HookName;
|
|
14
20
|
hookFilePath: string;
|
|
15
21
|
};
|
|
16
22
|
type HookFn = (arg: unknown) => unknown;
|
|
23
|
+
type HookTimeout = {
|
|
24
|
+
error: number | false;
|
|
25
|
+
warning: number | false;
|
|
26
|
+
};
|
|
27
|
+
type HooksTimeoutProvidedByUser = false | Partial<Record<HookName, false | Partial<HookTimeout>>>;
|
|
17
28
|
declare function getHook(pageContext: PageContextExports, hookName: HookName): null | Hook;
|
|
29
|
+
declare function getHookFromPageConfig(pageConfig: PageConfigRuntime | PageConfigBuildTime, hookName: HookNamePage): null | Hook;
|
|
30
|
+
declare function getHookFromPageConfigGlobal(pageConfigGlobal: PageConfigGlobalRuntime, hookName: HookNameGlobal): null | Hook;
|
|
18
31
|
declare function assertHook<TPageContext extends PageContextExports, THookName extends PropertyKey & HookName>(pageContext: TPageContext, hookName: THookName): asserts pageContext is TPageContext & {
|
|
19
32
|
exports: Record<THookName, Function | undefined>;
|
|
20
33
|
};
|
|
21
|
-
declare function
|
|
22
|
-
hookName: HookName;
|
|
23
|
-
hookFilePath: string;
|
|
24
|
-
}): asserts hookFn is HookFn;
|
|
34
|
+
declare function getHookTimeoutDefault(hookName: HookName): HookTimeout;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
export { getHook };
|
|
2
|
+
export { getHookFromPageConfig };
|
|
3
|
+
export { getHookFromPageConfigGlobal };
|
|
2
4
|
export { assertHook };
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
// TODO/v1-release: remove
|
|
6
|
+
// We export for old V0.4 design which doesn't support config.hooksTimeout
|
|
7
|
+
export { getHookTimeoutDefault };
|
|
8
|
+
import { getConfigValue, getHookFilePathToShowToUser } from '../page-configs/helpers.js';
|
|
9
|
+
import { assert, assertUsage, checkType, isCallable, isObject } from '../utils.js';
|
|
10
|
+
import pc from '@brillout/picocolors';
|
|
5
11
|
function getHook(pageContext, hookName) {
|
|
6
12
|
if (!(hookName in pageContext.exports)) {
|
|
7
13
|
return null;
|
|
8
14
|
}
|
|
15
|
+
const { hooksTimeout } = pageContext.config;
|
|
16
|
+
const hookTimeout = getHookTimeout(hooksTimeout, hookName);
|
|
9
17
|
const hookFn = pageContext.exports[hookName];
|
|
10
18
|
const file = pageContext.exportsAll[hookName][0];
|
|
11
19
|
assert(file.exportValue === hookFn);
|
|
@@ -15,7 +23,37 @@ function getHook(pageContext, hookName) {
|
|
|
15
23
|
assert(hookFilePath);
|
|
16
24
|
assert(!hookFilePath.endsWith(' '));
|
|
17
25
|
assertHookFn(hookFn, { hookName, hookFilePath });
|
|
18
|
-
return { hookFn, hookName, hookFilePath };
|
|
26
|
+
return { hookFn, hookName, hookFilePath, hookTimeout };
|
|
27
|
+
}
|
|
28
|
+
function getHookFromPageConfig(pageConfig, hookName) {
|
|
29
|
+
const configValue = getConfigValue(pageConfig, hookName);
|
|
30
|
+
const hooksTimeout = getConfigValue(pageConfig, 'hooksTimeout')?.value;
|
|
31
|
+
if (!configValue)
|
|
32
|
+
return null;
|
|
33
|
+
const hookFn = configValue.value;
|
|
34
|
+
if (!hookFn)
|
|
35
|
+
return null;
|
|
36
|
+
const hookFilePath = getHookFilePathToShowToUser(configValue);
|
|
37
|
+
// hook isn't a computed nor a cumulative config => definedAt should always be defined
|
|
38
|
+
assert(hookFilePath);
|
|
39
|
+
assertHookFn(hookFn, { hookName, hookFilePath });
|
|
40
|
+
const hookTimeout = getHookTimeout(hooksTimeout, hookName);
|
|
41
|
+
return { hookFn, hookName, hookFilePath, hookTimeout };
|
|
42
|
+
}
|
|
43
|
+
function getHookFromPageConfigGlobal(pageConfigGlobal, hookName) {
|
|
44
|
+
const configValue = pageConfigGlobal.configValues[hookName];
|
|
45
|
+
if (!configValue)
|
|
46
|
+
return null;
|
|
47
|
+
const hookFn = configValue.value;
|
|
48
|
+
if (!hookFn)
|
|
49
|
+
return null;
|
|
50
|
+
const hookFilePath = getHookFilePathToShowToUser(configValue);
|
|
51
|
+
// hook isn't a computed nor a cumulative config => definedAt should always be defined
|
|
52
|
+
assert(hookFilePath);
|
|
53
|
+
assertHookFn(hookFn, { hookName, hookFilePath });
|
|
54
|
+
// We could use the global value of config.hooksTimeout but it requires some non-trivial refactoring
|
|
55
|
+
const hookTimeout = getHookTimeoutDefault(hookName);
|
|
56
|
+
return { hookFn, hookName, hookFilePath, hookTimeout };
|
|
19
57
|
}
|
|
20
58
|
function assertHook(pageContext, hookName) {
|
|
21
59
|
getHook(pageContext, hookName);
|
|
@@ -26,3 +64,65 @@ function assertHookFn(hookFn, { hookName, hookFilePath }) {
|
|
|
26
64
|
assertUsage(isCallable(hookFn), `Hook ${hookName}() defined by ${hookFilePath} should be a function`);
|
|
27
65
|
checkType(hookFn);
|
|
28
66
|
}
|
|
67
|
+
function getHookTimeout(hooksTimeoutProvidedByUser, hookName) {
|
|
68
|
+
const hooksTimeoutProvidedbyUserNormalized = getHooksTimeoutProvidedByUserNormalized(hooksTimeoutProvidedByUser);
|
|
69
|
+
if (hooksTimeoutProvidedbyUserNormalized === false)
|
|
70
|
+
return { error: false, warning: false };
|
|
71
|
+
const providedbyUser = hooksTimeoutProvidedbyUserNormalized[hookName];
|
|
72
|
+
const hookTimeout = getHookTimeoutDefault(hookName);
|
|
73
|
+
if (providedbyUser?.error !== undefined)
|
|
74
|
+
hookTimeout.error = providedbyUser.error;
|
|
75
|
+
if (providedbyUser?.warning !== undefined)
|
|
76
|
+
hookTimeout.warning = providedbyUser.warning;
|
|
77
|
+
return hookTimeout;
|
|
78
|
+
}
|
|
79
|
+
// Ideally this should be called only once and at build-time (to avoid bloating the client-side bundle), but we didn't implement any mechanism to valide config values at build-time yet
|
|
80
|
+
function getHooksTimeoutProvidedByUserNormalized(hooksTimeoutProvidedByUser) {
|
|
81
|
+
if (hooksTimeoutProvidedByUser === undefined)
|
|
82
|
+
return {};
|
|
83
|
+
if (hooksTimeoutProvidedByUser === false)
|
|
84
|
+
return false;
|
|
85
|
+
assertUsage(isObject(hooksTimeoutProvidedByUser), `Setting ${pc.cyan('hooksTimeout')} should be ${pc.cyan('false')} or an object`);
|
|
86
|
+
const hooksTimeoutProvidedByUserNormalized = {};
|
|
87
|
+
Object.entries(hooksTimeoutProvidedByUser).forEach(([hookName, hookTimeoutProvidedbyUser]) => {
|
|
88
|
+
if (hookTimeoutProvidedbyUser === false) {
|
|
89
|
+
hooksTimeoutProvidedByUserNormalized[hookName] = { error: false, warning: false };
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
assertUsage(isObject(hookTimeoutProvidedbyUser), `Setting ${pc.cyan(`hooksTimeout.${hookName}`)} should be ${pc.cyan('false')} or an object`);
|
|
93
|
+
const [error, warning] = ['error', 'warning'].map((timeoutName) => {
|
|
94
|
+
const timeoutVal = hookTimeoutProvidedbyUser[timeoutName];
|
|
95
|
+
if (timeoutVal === undefined || timeoutVal === false)
|
|
96
|
+
return timeoutVal;
|
|
97
|
+
const errPrefix = `Setting ${pc.cyan(`hooksTimeout.${hookName}.${timeoutName}`)} should be`;
|
|
98
|
+
assertUsage(typeof timeoutVal === 'number', `${errPrefix} ${pc.cyan('false')} or a number`);
|
|
99
|
+
assertUsage(timeoutVal > 0, `${errPrefix} a positive number`);
|
|
100
|
+
return timeoutVal;
|
|
101
|
+
});
|
|
102
|
+
hooksTimeoutProvidedByUserNormalized[hookName] = { error, warning };
|
|
103
|
+
});
|
|
104
|
+
return hooksTimeoutProvidedByUserNormalized;
|
|
105
|
+
}
|
|
106
|
+
function getHookTimeoutDefault(hookName) {
|
|
107
|
+
if (hookName === 'onBeforeRoute') {
|
|
108
|
+
return {
|
|
109
|
+
error: 5 * 1000,
|
|
110
|
+
warning: 1 * 1000
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (hookName === 'onPrerenderStart' ||
|
|
114
|
+
hookName === 'onBeforePrerenderStart' ||
|
|
115
|
+
// TODO/v1-release: remove
|
|
116
|
+
// Old V0.4 design hooks (https://vike.dev/migration/v1-design#renamed-hooks)
|
|
117
|
+
hookName === 'onBeforePrerender' ||
|
|
118
|
+
hookName === 'prerender') {
|
|
119
|
+
return {
|
|
120
|
+
error: 10 * 60 * 1000,
|
|
121
|
+
warning: 30 * 1000
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
error: 30 * 1000,
|
|
126
|
+
warning: 4 * 1000
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -3,6 +3,8 @@ export type { ConfigBuiltIn };
|
|
|
3
3
|
export type { ConfigNameBuiltIn };
|
|
4
4
|
export type { ConfigMeta };
|
|
5
5
|
export type { HookName };
|
|
6
|
+
export type { HookNamePage };
|
|
7
|
+
export type { HookNameGlobal };
|
|
6
8
|
export type { GuardAsync };
|
|
7
9
|
export type { GuardSync };
|
|
8
10
|
export type { OnBeforePrerenderStartAsync };
|
|
@@ -30,9 +32,13 @@ import type { ConfigDefinition } from '../../node/plugin/plugins/importUserCode/
|
|
|
30
32
|
import type { DocumentHtml } from '../../node/runtime/html/renderHtml.js';
|
|
31
33
|
import type { ConfigVikeUserProvided } from '../ConfigVike.js';
|
|
32
34
|
import type { Vike, VikePackages } from '../VikeNamespace.js';
|
|
35
|
+
import type { HooksTimeoutProvidedByUser } from '../hooks/getHook.js';
|
|
33
36
|
import type { PageContextClient, PageContextServer } from '../types.js';
|
|
34
|
-
type HookName =
|
|
35
|
-
type
|
|
37
|
+
type HookName = HookNamePage | HookNameGlobal | HookNameOldDesign;
|
|
38
|
+
type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard';
|
|
39
|
+
type HookNameGlobal = 'onBeforePrerender' | 'onBeforeRoute' | 'onPrerenderStart';
|
|
40
|
+
type HookNameOldDesign = 'render' | 'prerender';
|
|
41
|
+
type ConfigNameBuiltIn = Exclude<keyof Config, keyof ConfigVikeUserProvided | 'onBeforeRoute' | 'onPrerenderStart'> | 'prerender' | 'isClientSideRenderable' | 'onBeforeRenderEnv' | 'hooksTimeout';
|
|
36
42
|
type Config = ConfigBuiltIn & Vike.Config & (VikePackages.ConfigVikeReact | VikePackages.ConfigVikeVue | VikePackages.ConfigVikeSolid | VikePackages.ConfigVikeSvelte);
|
|
37
43
|
/** Protect page(s), e.g. forbid unauthorized access.
|
|
38
44
|
*
|
|
@@ -102,32 +108,32 @@ type OnBeforeRouteSync = (pageContext: PageContextServer) => {
|
|
|
102
108
|
};
|
|
103
109
|
/** Hook called after the page is hydrated.
|
|
104
110
|
*
|
|
105
|
-
* https://vike.dev/
|
|
111
|
+
* https://vike.dev/onHydrationEnd
|
|
106
112
|
*/
|
|
107
113
|
type OnHydrationEndAsync = (pageContext: PageContextClient) => Promise<void>;
|
|
108
114
|
/** Hook called after the page is hydrated.
|
|
109
115
|
*
|
|
110
|
-
* https://vike.dev/
|
|
116
|
+
* https://vike.dev/onHydrationEnd
|
|
111
117
|
*/
|
|
112
118
|
type OnHydrationEndSync = (pageContext: PageContextClient) => void;
|
|
113
119
|
/** Hook called after the user navigates to a new page.
|
|
114
120
|
*
|
|
115
|
-
* https://vike.dev/
|
|
121
|
+
* https://vike.dev/onPageTransitionEnd
|
|
116
122
|
*/
|
|
117
123
|
type OnPageTransitionEndAsync = (pageContext: PageContextClient) => Promise<void>;
|
|
118
124
|
/** Hook called after the user navigates to a new page.
|
|
119
125
|
*
|
|
120
|
-
* https://vike.dev/
|
|
126
|
+
* https://vike.dev/onPageTransitionEnd
|
|
121
127
|
*/
|
|
122
128
|
type OnPageTransitionEndSync = (pageContext: PageContextClient) => void;
|
|
123
129
|
/** Hook called before the user navigates to a new page.
|
|
124
130
|
*
|
|
125
|
-
* https://vike.dev/
|
|
131
|
+
* https://vike.dev/onPageTransitionStart
|
|
126
132
|
*/
|
|
127
133
|
type OnPageTransitionStartAsync = (pageContext: PageContextClient) => Promise<void>;
|
|
128
134
|
/** Hook called before the user navigates to a new page.
|
|
129
135
|
*
|
|
130
|
-
* https://vike.dev/
|
|
136
|
+
* https://vike.dev/onPageTransitionStart
|
|
131
137
|
*/
|
|
132
138
|
type OnPageTransitionStartSync = (pageContext: PageContextClient) => void;
|
|
133
139
|
/** Page Hook called when pre-rendering starts.
|
|
@@ -275,22 +281,22 @@ type ConfigBuiltIn = {
|
|
|
275
281
|
onBeforeRoute?: OnBeforeRouteAsync | OnBeforeRouteSync | ImportString;
|
|
276
282
|
/** Hook called after the page is hydrated.
|
|
277
283
|
*
|
|
278
|
-
* https://vike.dev/
|
|
284
|
+
* https://vike.dev/onHydrationEnd
|
|
279
285
|
*/
|
|
280
286
|
onHydrationEnd?: OnHydrationEndAsync | OnHydrationEndSync | ImportString;
|
|
281
287
|
/** Hook called before the user navigates to a new page.
|
|
282
288
|
*
|
|
283
|
-
* https://vike.dev/
|
|
289
|
+
* https://vike.dev/onPageTransitionStart
|
|
284
290
|
*/
|
|
285
291
|
onPageTransitionStart?: OnPageTransitionStartAsync | OnPageTransitionStartSync | ImportString;
|
|
286
292
|
/** Hook called after the user navigates to a new page.
|
|
287
293
|
*
|
|
288
|
-
* https://vike.dev/
|
|
294
|
+
* https://vike.dev/onPageTransitionEnd
|
|
289
295
|
*/
|
|
290
296
|
onPageTransitionEnd?: OnPageTransitionEndAsync | OnPageTransitionEndSync | ImportString;
|
|
291
297
|
/** Whether the UI framework (React/Vue/Solid/...) allows the page's hydration to be aborted.
|
|
292
298
|
*
|
|
293
|
-
* https://vike.dev/
|
|
299
|
+
* https://vike.dev/hydrationCanBeAborted
|
|
294
300
|
*/
|
|
295
301
|
hydrationCanBeAborted?: boolean | ImportString;
|
|
296
302
|
/** Additional client code.
|
|
@@ -310,9 +316,11 @@ type ConfigBuiltIn = {
|
|
|
310
316
|
meta?: ConfigMeta | ImportString;
|
|
311
317
|
/** Prefetch links.
|
|
312
318
|
*
|
|
313
|
-
* https://vike.dev/
|
|
319
|
+
* https://vike.dev/prefetchStaticAssets
|
|
314
320
|
*/
|
|
315
321
|
prefetchStaticAssets?: PrefetchStaticAssets | ImportString;
|
|
322
|
+
/** Modify the tiemouts of hooks. */
|
|
323
|
+
hooksTimeout?: HooksTimeoutProvidedByUser;
|
|
316
324
|
};
|
|
317
325
|
type ConfigMeta = Record<string, ConfigDefinition>;
|
|
318
326
|
type ImportString = `import:${string}`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { getConfigDefinedAtString };
|
|
2
2
|
export { getDefinedAtString };
|
|
3
3
|
import type { DefinedAt } from '../PageConfig.js';
|
|
4
|
-
declare function getConfigDefinedAtString<ConfigName extends string, SentenceBegin extends 'Config' | 'config'
|
|
4
|
+
declare function getConfigDefinedAtString<ConfigName extends string, SentenceBegin extends 'Config' | 'config'>(sentenceBegin: SentenceBegin, configName: ConfigName, { definedAt }: {
|
|
5
5
|
definedAt: DefinedAt;
|
|
6
6
|
}): `${SentenceBegin} ${ConfigName}${string} defined ${'internally' | `at ${string}`}`;
|
|
7
7
|
declare function getDefinedAtString(definedAt: DefinedAt, configName: string): string;
|
|
@@ -6,7 +6,7 @@ import { getExportPath } from '../getExportPath.js';
|
|
|
6
6
|
function getConfigDefinedAtString(sentenceBegin, configName, { definedAt }) {
|
|
7
7
|
const definedAtString = getDefinedAtString(definedAt, configName);
|
|
8
8
|
const definedAtStr = definedAtString === 'internally' ? definedAtString : `at ${definedAtString}`;
|
|
9
|
-
let configNameStr = `${configName}${sentenceBegin === 'Hook' ? '()'
|
|
9
|
+
let configNameStr = `${configName}${ /*sentenceBegin === 'Hook' ? '()' :*/''}`;
|
|
10
10
|
const configDefinedAt = `${sentenceBegin} ${pc.cyan(configNameStr)} defined ${definedAtStr}`;
|
|
11
11
|
return configDefinedAt;
|
|
12
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { executeGuardHook };
|
|
2
|
-
import { getHook } from '../hooks/getHook.js';
|
|
2
|
+
import { getHook, getHookTimeoutDefault } from '../hooks/getHook.js';
|
|
3
3
|
import { assert, assertUsage, executeHook, isCallable } from './utils.js';
|
|
4
4
|
async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
5
5
|
let hook;
|
|
@@ -19,7 +19,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
19
19
|
const res = prepareForUserConsumption(pageContext);
|
|
20
20
|
if (res)
|
|
21
21
|
pageContextForUserConsumption = res;
|
|
22
|
-
const hookResult = await executeHook(() => guard(pageContextForUserConsumption),
|
|
22
|
+
const hookResult = await executeHook(() => guard(pageContextForUserConsumption), hook);
|
|
23
23
|
assertUsage(hookResult === undefined, `The guard() hook of ${hook.hookFilePath} returns a value, but guard() doesn't accept any return value`);
|
|
24
24
|
}
|
|
25
25
|
function findPageGuard(pageId, pageFilesAll) {
|
|
@@ -32,6 +32,7 @@ function findPageGuard(pageId, pageFilesAll) {
|
|
|
32
32
|
if (!hookFn)
|
|
33
33
|
return null;
|
|
34
34
|
const hookFilePath = filePath;
|
|
35
|
+
const hookTimeout = getHookTimeoutDefault('guard');
|
|
35
36
|
assertUsage(isCallable(hookFn), `guard() defined by ${hookFilePath} should be a function`);
|
|
36
|
-
return { hookFn, hookName: 'guard', hookFilePath };
|
|
37
|
+
return { hookFn, hookName: 'guard', hookFilePath, hookTimeout };
|
|
37
38
|
}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import type { PageContextForRoute, PageContextFromRoute } from './index.js';
|
|
2
1
|
export { executeOnBeforeRouteHook };
|
|
3
|
-
|
|
4
|
-
type OnBeforeRouteHook = {
|
|
5
|
-
hookFilePath: string;
|
|
6
|
-
onBeforeRoute: (pageContext: {
|
|
7
|
-
urlOriginal: string;
|
|
8
|
-
} & Record<string, unknown>) => unknown;
|
|
9
|
-
};
|
|
2
|
+
import type { PageContextForRoute, PageContextFromRoute } from './index.js';
|
|
10
3
|
declare function executeOnBeforeRouteHook(pageContext: PageContextForRoute): Promise<null | ({
|
|
11
4
|
_routingProvidedByOnBeforeRouteHook: true;
|
|
12
5
|
} & PageContextFromRoute) | {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
export { executeOnBeforeRouteHook };
|
|
1
2
|
import { assertPageContextProvidedByUser } from '../assertPageContextProvidedByUser.js';
|
|
2
|
-
import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrl, joinEnglish, assert } from './utils.js';
|
|
3
|
+
import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrl, joinEnglish, assert, executeHook } from './utils.js';
|
|
3
4
|
import { assertRouteParams, assertSyncRouting } from './resolveRouteFunction.js';
|
|
4
5
|
import pc from '@brillout/picocolors';
|
|
5
|
-
export { executeOnBeforeRouteHook };
|
|
6
6
|
async function executeOnBeforeRouteHook(pageContext) {
|
|
7
7
|
const pageContextFromOnBeforeRouteHook = {};
|
|
8
8
|
if (!pageContext._onBeforeRouteHook)
|
|
9
9
|
return null;
|
|
10
|
-
const pageContextFromHook = await
|
|
10
|
+
const pageContextFromHook = await getPageContextFromHook(pageContext._onBeforeRouteHook, pageContext);
|
|
11
11
|
if (pageContextFromHook) {
|
|
12
12
|
objectAssign(pageContextFromOnBeforeRouteHook, pageContextFromHook);
|
|
13
13
|
if (hasProp(pageContextFromOnBeforeRouteHook, '_pageId', 'string') ||
|
|
@@ -31,11 +31,11 @@ async function executeOnBeforeRouteHook(pageContext) {
|
|
|
31
31
|
});
|
|
32
32
|
return pageContextFromOnBeforeRouteHook;
|
|
33
33
|
}
|
|
34
|
-
async function
|
|
35
|
-
let hookReturn = onBeforeRouteHook.
|
|
34
|
+
async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
35
|
+
let hookReturn = onBeforeRouteHook.hookFn(pageContext);
|
|
36
36
|
assertSyncRouting(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
|
|
37
37
|
// TODO/v1-release: make executeOnBeforeRouteHook() and route() sync
|
|
38
|
-
hookReturn = await hookReturn;
|
|
38
|
+
hookReturn = await executeHook(() => hookReturn, onBeforeRouteHook);
|
|
39
39
|
const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
|
|
40
40
|
assertUsage(hookReturn === null ||
|
|
41
41
|
hookReturn === undefined ||
|
|
@@ -5,16 +5,16 @@ export type { PageRoutes };
|
|
|
5
5
|
export type { RouteMatches };
|
|
6
6
|
import type { PageFile } from '../getPageFiles.js';
|
|
7
7
|
import { PageContextUrlComputedPropsInternal, PageContextUrlSources } from '../addUrlComputedProps.js';
|
|
8
|
-
import { type OnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
|
|
9
8
|
import type { PageRoutes, RouteType } from './loadPageRoutes.js';
|
|
10
9
|
import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../page-configs/PageConfig.js';
|
|
10
|
+
import type { Hook } from '../hooks/getHook.js';
|
|
11
11
|
type PageContextForRoute = PageContextUrlComputedPropsInternal & {
|
|
12
12
|
_pageFilesAll: PageFile[];
|
|
13
13
|
_pageConfigs: PageConfigRuntime[];
|
|
14
14
|
_allPageIds: string[];
|
|
15
15
|
_pageConfigGlobal: PageConfigGlobalRuntime;
|
|
16
16
|
_pageRoutes: PageRoutes;
|
|
17
|
-
_onBeforeRouteHook:
|
|
17
|
+
_onBeforeRouteHook: Hook | null;
|
|
18
18
|
} & PageContextUrlSources;
|
|
19
19
|
type PageContextFromRoute = {
|
|
20
20
|
_pageId: string | null;
|
|
@@ -2,8 +2,8 @@ export { loadPageRoutes };
|
|
|
2
2
|
export type { PageRoutes };
|
|
3
3
|
export type { RouteType };
|
|
4
4
|
import type { PageFile } from '../getPageFiles.js';
|
|
5
|
-
import type { OnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
|
|
6
5
|
import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../page-configs/PageConfig.js';
|
|
6
|
+
import { type Hook } from '../hooks/getHook.js';
|
|
7
7
|
type PageRoute = {
|
|
8
8
|
pageId: string;
|
|
9
9
|
comesFromV1PageConfig: boolean;
|
|
@@ -25,5 +25,5 @@ type PageRoutes = PageRoute[];
|
|
|
25
25
|
type RouteType = 'STRING' | 'FUNCTION' | 'FILESYSTEM';
|
|
26
26
|
declare function loadPageRoutes(pageFilesAll: PageFile[], pageConfigs: PageConfigRuntime[], pageConfigGlobal: PageConfigGlobalRuntime, allPageIds: string[]): Promise<{
|
|
27
27
|
pageRoutes: PageRoutes;
|
|
28
|
-
onBeforeRouteHook: null |
|
|
28
|
+
onBeforeRouteHook: null | Hook;
|
|
29
29
|
}>;
|
|
@@ -3,8 +3,9 @@ import { isErrorPageId } from '../error-page.js';
|
|
|
3
3
|
import { assert, assertUsage, hasProp, slice } from './utils.js';
|
|
4
4
|
import { deduceRouteStringFromFilesystemPath } from './deduceRouteStringFromFilesystemPath.js';
|
|
5
5
|
import { isCallable } from '../utils.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getConfigValue, getDefinedAtString } from '../page-configs/helpers.js';
|
|
7
7
|
import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
|
|
8
|
+
import { getHookFromPageConfigGlobal, getHookTimeoutDefault } from '../hooks/getHook.js';
|
|
8
9
|
async function loadPageRoutes(
|
|
9
10
|
// Remove all arguments and use GlobalContext instead?
|
|
10
11
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
@@ -136,20 +137,8 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
136
137
|
function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
|
|
137
138
|
// V1 Design
|
|
138
139
|
if (pageConfigs.length > 0) {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
const configValue = pageConfigGlobal.configValues[hookName];
|
|
142
|
-
const { value: hookFn } = configValue;
|
|
143
|
-
const hookFilePath = getHookFilePathToShowToUser(configValue);
|
|
144
|
-
const hookDefinedAt = getConfigDefinedAtString('Hook', hookName, configValue);
|
|
145
|
-
assertUsage(isCallable(hookFn), `${hookDefinedAt} should be a function.`);
|
|
146
|
-
const onBeforeRouteHook = {
|
|
147
|
-
hookFilePath: hookFilePath,
|
|
148
|
-
onBeforeRoute: hookFn
|
|
149
|
-
};
|
|
150
|
-
return { onBeforeRouteHook, filesystemRoots: null };
|
|
151
|
-
}
|
|
152
|
-
return { onBeforeRouteHook: null, filesystemRoots: null };
|
|
140
|
+
const hook = getHookFromPageConfigGlobal(pageConfigGlobal, 'onBeforeRoute');
|
|
141
|
+
return { onBeforeRouteHook: hook, filesystemRoots: null };
|
|
153
142
|
}
|
|
154
143
|
// Old design
|
|
155
144
|
// TODO/v1-release: remove
|
|
@@ -162,7 +151,13 @@ function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
|
|
|
162
151
|
if ('onBeforeRoute' in fileExports) {
|
|
163
152
|
assertUsage(hasProp(fileExports, 'onBeforeRoute', 'function'), `\`export { onBeforeRoute }\` of ${filePath} should be a function.`);
|
|
164
153
|
const { onBeforeRoute } = fileExports;
|
|
165
|
-
|
|
154
|
+
const hookName = 'onBeforeRoute';
|
|
155
|
+
onBeforeRouteHook = {
|
|
156
|
+
hookFilePath: filePath,
|
|
157
|
+
hookFn: onBeforeRoute,
|
|
158
|
+
hookName,
|
|
159
|
+
hookTimeout: getHookTimeoutDefault(hookName)
|
|
160
|
+
};
|
|
166
161
|
}
|
|
167
162
|
if ('filesystemRoutingRoot' in fileExports) {
|
|
168
163
|
assertUsage(hasProp(fileExports, 'filesystemRoutingRoot', 'string'), `\`export { filesystemRoutingRoot }\` of ${filePath} should be a string.`);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export type { ProjectTag };
|
|
3
3
|
export { PROJECT_VERSION };
|
|
4
|
-
declare const PROJECT_VERSION: "0.4.
|
|
4
|
+
declare const PROJECT_VERSION: "0.4.148-commit-7596dcd";
|
|
5
5
|
type PackageName = typeof projectInfo.npmPackageName;
|
|
6
6
|
type ProjectVersion = typeof projectInfo.projectVersion;
|
|
7
7
|
type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
|
|
8
8
|
declare const projectInfo: {
|
|
9
9
|
projectName: "Vike";
|
|
10
|
-
projectVersion: "0.4.
|
|
10
|
+
projectVersion: "0.4.148-commit-7596dcd";
|
|
11
11
|
npmPackageName: "vike";
|
|
12
12
|
githubRepository: "https://github.com/vikejs/vike";
|
|
13
13
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
3
|
import { onProjectInfo } from './assertSingleInstance.js';
|
|
4
|
-
const PROJECT_VERSION = '0.4.
|
|
4
|
+
const PROJECT_VERSION = '0.4.148-commit-7596dcd';
|
|
5
5
|
const projectInfo = {
|
|
6
6
|
projectName: 'Vike',
|
|
7
7
|
projectVersion: PROJECT_VERSION,
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|