vike 0.4.229-commit-e27d672 → 0.4.229-commit-847f1b6
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/shared/getProxyForPublicUsage.js +4 -3
- package/dist/cjs/shared/hooks/execHook.js +10 -4
- package/dist/cjs/shared/preparePageContextForPublicUsage.js +10 -5
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +1 -3
- package/dist/esm/shared/getProxyForPublicUsage.d.ts +1 -1
- package/dist/esm/shared/getProxyForPublicUsage.js +4 -3
- package/dist/esm/shared/hooks/execHook.d.ts +1 -1
- package/dist/esm/shared/hooks/execHook.js +10 -4
- package/dist/esm/shared/preparePageContextForPublicUsage.d.ts +1 -3
- package/dist/esm/shared/preparePageContextForPublicUsage.js +11 -6
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/package.json +1 -1
|
@@ -18,13 +18,14 @@ function getProxyForPublicUsage(obj, objName, skipOnInternalProp, fallback) {
|
|
|
18
18
|
function getTrapGet(obj, objName, skipOnInternalProp, fallback) {
|
|
19
19
|
return function (_, prop) {
|
|
20
20
|
const propStr = String(prop);
|
|
21
|
+
if (prop === '_isProxyObject')
|
|
22
|
+
return true;
|
|
21
23
|
if (!skipOnInternalProp)
|
|
22
24
|
onInternalProp(propStr, objName);
|
|
23
|
-
if (fallback) {
|
|
25
|
+
if (fallback && !(prop in obj)) {
|
|
24
26
|
// Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
|
|
25
27
|
// Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
|
|
26
|
-
|
|
27
|
-
return fallback[prop];
|
|
28
|
+
return fallback(prop);
|
|
28
29
|
}
|
|
29
30
|
const val = obj[prop];
|
|
30
31
|
onNotSerializable(propStr, val, objName);
|
|
@@ -115,7 +115,7 @@ function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
|
115
115
|
}, timeoutErr);
|
|
116
116
|
(async () => {
|
|
117
117
|
try {
|
|
118
|
-
|
|
118
|
+
providePageContextInternal(pageContextForPublicUsage);
|
|
119
119
|
const ret = await hookFnCaller();
|
|
120
120
|
resolve(ret);
|
|
121
121
|
}
|
|
@@ -130,7 +130,7 @@ function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
|
130
130
|
}
|
|
131
131
|
function execHookSync(hook, pageContext, preparePageContextForPublicUsage) {
|
|
132
132
|
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
133
|
-
|
|
133
|
+
providePageContextInternal(pageContextForPublicUsage);
|
|
134
134
|
const hookReturn = hook.hookFn(pageContextForPublicUsage);
|
|
135
135
|
return { hookReturn };
|
|
136
136
|
}
|
|
@@ -145,8 +145,11 @@ function isNotDisabled(timeout) {
|
|
|
145
145
|
function getPageContext() {
|
|
146
146
|
const { pageContext } = globalObject;
|
|
147
147
|
if (!pageContext)
|
|
148
|
-
return
|
|
149
|
-
const pageContextForPublicUsage =
|
|
148
|
+
return null;
|
|
149
|
+
const pageContextForPublicUsage = pageContext._isProxyObject
|
|
150
|
+
? // providePageContext() is called on the user-land (e.g. it's called by `vike-{react,vue,solid}`) thus it's already a proxy
|
|
151
|
+
pageContext
|
|
152
|
+
: (0, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage)(pageContext);
|
|
150
153
|
return pageContextForPublicUsage;
|
|
151
154
|
}
|
|
152
155
|
/**
|
|
@@ -155,6 +158,9 @@ function getPageContext() {
|
|
|
155
158
|
* https://vike.dev/getPageContext
|
|
156
159
|
*/
|
|
157
160
|
function providePageContext(pageContext) {
|
|
161
|
+
providePageContextInternal(pageContext);
|
|
162
|
+
}
|
|
163
|
+
function providePageContextInternal(pageContext) {
|
|
158
164
|
globalObject.pageContext = pageContext;
|
|
159
165
|
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
160
166
|
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
@@ -7,12 +7,9 @@ const addIs404ToPageProps_js_1 = require("./addIs404ToPageProps.js");
|
|
|
7
7
|
const prepareGlobalContextForPublicUsage_js_1 = require("./prepareGlobalContextForPublicUsage.js");
|
|
8
8
|
const getProxyForPublicUsage_js_1 = require("./getProxyForPublicUsage.js");
|
|
9
9
|
function preparePageContextForPublicUsage(pageContext) {
|
|
10
|
+
(0, utils_js_1.assert)(!pageContext._isProxyObject);
|
|
10
11
|
(0, utils_js_1.assert)(!pageContext.globalContext); // pageContext.globalContext should only be available to users — Vike itself should use pageContext._globalContext instead
|
|
11
12
|
(0, utils_js_1.assert)(pageContext._isOriginalObject); // ensure we preserve the original object reference
|
|
12
|
-
const globalContextPublic = (0, prepareGlobalContextForPublicUsage_js_1.prepareGlobalContextForPublicUsage)(pageContext._globalContext);
|
|
13
|
-
(0, utils_js_1.objectAssign)(pageContext, {
|
|
14
|
-
globalContext: globalContextPublic
|
|
15
|
-
});
|
|
16
13
|
(0, addIs404ToPageProps_js_1.addIs404ToPageProps)(pageContext);
|
|
17
14
|
// TODO/next-major-release: remove
|
|
18
15
|
if (!('_pageId' in pageContext)) {
|
|
@@ -29,10 +26,18 @@ function preparePageContextForPublicUsage(pageContext) {
|
|
|
29
26
|
}
|
|
30
27
|
// For a more readable `console.log(pageContext)` output
|
|
31
28
|
sortPageContext(pageContext);
|
|
29
|
+
const globalContextPublic = (0, prepareGlobalContextForPublicUsage_js_1.prepareGlobalContextForPublicUsage)(pageContext._globalContext);
|
|
32
30
|
const pageContextPublic = (0, getProxyForPublicUsage_js_1.getProxyForPublicUsage)(pageContext, 'pageContext',
|
|
33
31
|
// We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
|
|
34
32
|
// - TODO/now: double check whether that's true
|
|
35
|
-
true,
|
|
33
|
+
true, (prop) => {
|
|
34
|
+
if (prop === 'globalContext') {
|
|
35
|
+
return globalContextPublic;
|
|
36
|
+
}
|
|
37
|
+
if (prop in globalContextPublic) {
|
|
38
|
+
return globalContextPublic[prop];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
36
41
|
return pageContextPublic;
|
|
37
42
|
}
|
|
38
43
|
// Sort `pageContext` keys alphabetically, in order to make reading the `console.log(pageContext)` output easier
|
|
@@ -8,6 +8,4 @@ type PageContextForPublicUsageClientShared = PageContextPrepareMinimum & PageCon
|
|
|
8
8
|
declare function preparePageContextForPublicUsageClientShared<PageContext extends PageContextForPublicUsageClientShared>(pageContext: PageContext): PageContext & {
|
|
9
9
|
Page: unknown;
|
|
10
10
|
};
|
|
11
|
-
declare function preparePageContextForPublicUsageClientMinimal<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext
|
|
12
|
-
globalContext: import("../../shared/prepareGlobalContextForPublicUsage.js").GlobalContextPrepareMinimum;
|
|
13
|
-
};
|
|
11
|
+
declare function preparePageContextForPublicUsageClientMinimal<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { getProxyForPublicUsage };
|
|
2
2
|
type Target = Record<string, unknown>;
|
|
3
|
-
type Fallback =
|
|
3
|
+
type Fallback = (prop: string | symbol) => unknown;
|
|
4
4
|
declare function getProxyForPublicUsage<Obj extends Target>(obj: Obj, objName: string, skipOnInternalProp?: true, fallback?: Fallback): Obj;
|
|
@@ -16,13 +16,14 @@ function getProxyForPublicUsage(obj, objName, skipOnInternalProp, fallback) {
|
|
|
16
16
|
function getTrapGet(obj, objName, skipOnInternalProp, fallback) {
|
|
17
17
|
return function (_, prop) {
|
|
18
18
|
const propStr = String(prop);
|
|
19
|
+
if (prop === '_isProxyObject')
|
|
20
|
+
return true;
|
|
19
21
|
if (!skipOnInternalProp)
|
|
20
22
|
onInternalProp(propStr, objName);
|
|
21
|
-
if (fallback) {
|
|
23
|
+
if (fallback && !(prop in obj)) {
|
|
22
24
|
// Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
|
|
23
25
|
// Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
|
|
24
|
-
|
|
25
|
-
return fallback[prop];
|
|
26
|
+
return fallback(prop);
|
|
26
27
|
}
|
|
27
28
|
const val = obj[prop];
|
|
28
29
|
onNotSerializable(propStr, val, objName);
|
|
@@ -60,4 +60,4 @@ declare function getPageContext<PageContext = PageContextClient | PageContextSer
|
|
|
60
60
|
*
|
|
61
61
|
* https://vike.dev/getPageContext
|
|
62
62
|
*/
|
|
63
|
-
declare function providePageContext(pageContext: null |
|
|
63
|
+
declare function providePageContext(pageContext: null | PageContextClient | PageContextServer): void;
|
|
@@ -113,7 +113,7 @@ function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
|
113
113
|
}, timeoutErr);
|
|
114
114
|
(async () => {
|
|
115
115
|
try {
|
|
116
|
-
|
|
116
|
+
providePageContextInternal(pageContextForPublicUsage);
|
|
117
117
|
const ret = await hookFnCaller();
|
|
118
118
|
resolve(ret);
|
|
119
119
|
}
|
|
@@ -128,7 +128,7 @@ function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
|
128
128
|
}
|
|
129
129
|
function execHookSync(hook, pageContext, preparePageContextForPublicUsage) {
|
|
130
130
|
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
131
|
-
|
|
131
|
+
providePageContextInternal(pageContextForPublicUsage);
|
|
132
132
|
const hookReturn = hook.hookFn(pageContextForPublicUsage);
|
|
133
133
|
return { hookReturn };
|
|
134
134
|
}
|
|
@@ -143,8 +143,11 @@ function isNotDisabled(timeout) {
|
|
|
143
143
|
function getPageContext() {
|
|
144
144
|
const { pageContext } = globalObject;
|
|
145
145
|
if (!pageContext)
|
|
146
|
-
return
|
|
147
|
-
const pageContextForPublicUsage =
|
|
146
|
+
return null;
|
|
147
|
+
const pageContextForPublicUsage = pageContext._isProxyObject
|
|
148
|
+
? // providePageContext() is called on the user-land (e.g. it's called by `vike-{react,vue,solid}`) thus it's already a proxy
|
|
149
|
+
pageContext
|
|
150
|
+
: preparePageContextForPublicUsage(pageContext);
|
|
148
151
|
return pageContextForPublicUsage;
|
|
149
152
|
}
|
|
150
153
|
/**
|
|
@@ -153,6 +156,9 @@ function getPageContext() {
|
|
|
153
156
|
* https://vike.dev/getPageContext
|
|
154
157
|
*/
|
|
155
158
|
function providePageContext(pageContext) {
|
|
159
|
+
providePageContextInternal(pageContext);
|
|
160
|
+
}
|
|
161
|
+
function providePageContextInternal(pageContext) {
|
|
156
162
|
globalObject.pageContext = pageContext;
|
|
157
163
|
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
158
164
|
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
@@ -7,7 +7,5 @@ type PageContextPrepareMinimum = {
|
|
|
7
7
|
isPageContext: true;
|
|
8
8
|
_globalContext: GlobalContextPrepareMinimum;
|
|
9
9
|
};
|
|
10
|
-
declare function preparePageContextForPublicUsage<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext
|
|
11
|
-
globalContext: GlobalContextPrepareMinimum;
|
|
12
|
-
};
|
|
10
|
+
declare function preparePageContextForPublicUsage<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext;
|
|
13
11
|
declare function assertPropertyGetters(pageContext: Record<string, unknown>): void;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
export { preparePageContextForPublicUsage };
|
|
2
2
|
export { assertPropertyGetters };
|
|
3
|
-
import { assert, assertWarning, compareString, isPropertyGetter
|
|
3
|
+
import { assert, assertWarning, compareString, isPropertyGetter } from './utils.js';
|
|
4
4
|
import { addIs404ToPageProps } from './addIs404ToPageProps.js';
|
|
5
5
|
import { prepareGlobalContextForPublicUsage } from './prepareGlobalContextForPublicUsage.js';
|
|
6
6
|
import { getProxyForPublicUsage } from './getProxyForPublicUsage.js';
|
|
7
7
|
function preparePageContextForPublicUsage(pageContext) {
|
|
8
|
+
assert(!pageContext._isProxyObject);
|
|
8
9
|
assert(!pageContext.globalContext); // pageContext.globalContext should only be available to users — Vike itself should use pageContext._globalContext instead
|
|
9
10
|
assert(pageContext._isOriginalObject); // ensure we preserve the original object reference
|
|
10
|
-
const globalContextPublic = prepareGlobalContextForPublicUsage(pageContext._globalContext);
|
|
11
|
-
objectAssign(pageContext, {
|
|
12
|
-
globalContext: globalContextPublic
|
|
13
|
-
});
|
|
14
11
|
addIs404ToPageProps(pageContext);
|
|
15
12
|
// TODO/next-major-release: remove
|
|
16
13
|
if (!('_pageId' in pageContext)) {
|
|
@@ -27,10 +24,18 @@ function preparePageContextForPublicUsage(pageContext) {
|
|
|
27
24
|
}
|
|
28
25
|
// For a more readable `console.log(pageContext)` output
|
|
29
26
|
sortPageContext(pageContext);
|
|
27
|
+
const globalContextPublic = prepareGlobalContextForPublicUsage(pageContext._globalContext);
|
|
30
28
|
const pageContextPublic = getProxyForPublicUsage(pageContext, 'pageContext',
|
|
31
29
|
// We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
|
|
32
30
|
// - TODO/now: double check whether that's true
|
|
33
|
-
true,
|
|
31
|
+
true, (prop) => {
|
|
32
|
+
if (prop === 'globalContext') {
|
|
33
|
+
return globalContextPublic;
|
|
34
|
+
}
|
|
35
|
+
if (prop in globalContextPublic) {
|
|
36
|
+
return globalContextPublic[prop];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
34
39
|
return pageContextPublic;
|
|
35
40
|
}
|
|
36
41
|
// Sort `pageContext` keys alphabetically, in order to make reading the `console.log(pageContext)` output easier
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.229-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.229-commit-847f1b6";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.229-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.229-commit-847f1b6';
|