vike 0.4.229-commit-e27d672 → 0.4.229-commit-c3526d6
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 -2
- package/dist/cjs/shared/hooks/execHook.js +3 -0
- 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 -2
- package/dist/esm/shared/hooks/execHook.js +3 -0
- package/dist/esm/shared/preparePageContextForPublicUsage.d.ts +4 -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,15 @@ 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 { target: obj };
|
|
21
23
|
if (!skipOnInternalProp)
|
|
22
24
|
onInternalProp(propStr, objName);
|
|
23
25
|
if (fallback) {
|
|
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
|
-
if (!(prop in obj)
|
|
27
|
-
return fallback
|
|
28
|
+
if (!(prop in obj))
|
|
29
|
+
return fallback(prop);
|
|
28
30
|
}
|
|
29
31
|
const val = obj[prop];
|
|
30
32
|
onNotSerializable(propStr, val, objName);
|
|
@@ -155,6 +155,9 @@ function getPageContext() {
|
|
|
155
155
|
* https://vike.dev/getPageContext
|
|
156
156
|
*/
|
|
157
157
|
function providePageContext(pageContext) {
|
|
158
|
+
// providePageContext() can be called in the user-land (e.g. it's called by `vike-{react,vue,solid}`) thus we need to unwrap the proxy.
|
|
159
|
+
if (pageContext?._isProxyObject)
|
|
160
|
+
pageContext = pageContext._isProxyObject.target;
|
|
158
161
|
globalObject.pageContext = pageContext;
|
|
159
162
|
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
160
163
|
// 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,15 @@ 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 { target: obj };
|
|
19
21
|
if (!skipOnInternalProp)
|
|
20
22
|
onInternalProp(propStr, objName);
|
|
21
23
|
if (fallback) {
|
|
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
|
-
if (!(prop in obj)
|
|
25
|
-
return fallback
|
|
26
|
+
if (!(prop in obj))
|
|
27
|
+
return fallback(prop);
|
|
26
28
|
}
|
|
27
29
|
const val = obj[prop];
|
|
28
30
|
onNotSerializable(propStr, val, objName);
|
|
@@ -153,6 +153,9 @@ function getPageContext() {
|
|
|
153
153
|
* https://vike.dev/getPageContext
|
|
154
154
|
*/
|
|
155
155
|
function providePageContext(pageContext) {
|
|
156
|
+
// providePageContext() can be called in the user-land (e.g. it's called by `vike-{react,vue,solid}`) thus we need to unwrap the proxy.
|
|
157
|
+
if (pageContext?._isProxyObject)
|
|
158
|
+
pageContext = pageContext._isProxyObject.target;
|
|
156
159
|
globalObject.pageContext = pageContext;
|
|
157
160
|
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
158
161
|
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
@@ -6,8 +6,9 @@ type PageContextPrepareMinimum = {
|
|
|
6
6
|
_isOriginalObject: true;
|
|
7
7
|
isPageContext: true;
|
|
8
8
|
_globalContext: GlobalContextPrepareMinimum;
|
|
9
|
+
_isProxyObject?: {
|
|
10
|
+
target: PageContextPrepareMinimum;
|
|
11
|
+
};
|
|
9
12
|
};
|
|
10
|
-
declare function preparePageContextForPublicUsage<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext
|
|
11
|
-
globalContext: GlobalContextPrepareMinimum;
|
|
12
|
-
};
|
|
13
|
+
declare function preparePageContextForPublicUsage<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext;
|
|
13
14
|
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-c3526d6";
|
|
@@ -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-c3526d6';
|