vike 0.4.229-commit-5da80bf → 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/client/shared/preparePageContextForPublicUsageClientShared.js +0 -1
- package/dist/cjs/node/runtime/renderPage.js +1 -3
- package/dist/cjs/shared/createPageContextShared.js +1 -3
- package/dist/cjs/shared/getProxyForPublicUsage.js +11 -60
- package/dist/cjs/shared/hooks/execHook.js +3 -0
- package/dist/cjs/shared/preparePageContextForPublicUsage.js +12 -7
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +1 -1
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.js +0 -1
- package/dist/esm/node/runtime/renderPage.js +1 -3
- package/dist/esm/shared/createPageContextShared.js +1 -3
- package/dist/esm/shared/getProxyForPublicUsage.d.ts +3 -11
- package/dist/esm/shared/getProxyForPublicUsage.js +12 -61
- package/dist/esm/shared/hooks/execHook.js +3 -0
- package/dist/esm/shared/preparePageContextForPublicUsage.d.ts +4 -2
- package/dist/esm/shared/preparePageContextForPublicUsage.js +14 -9
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -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
|
@@ -34,7 +34,6 @@ function supportVueReactiviy(pageContext) {
|
|
|
34
34
|
// Remove propery descriptor getters because they break Vue's reactivity.
|
|
35
35
|
// E.g. resolve the `pageContext.urlPathname` getter.
|
|
36
36
|
function resolveGetters(pageContext) {
|
|
37
|
-
return;
|
|
38
37
|
Object.entries(pageContext).forEach(([key, val]) => {
|
|
39
38
|
delete pageContext[key];
|
|
40
39
|
pageContext[key] = val;
|
|
@@ -24,7 +24,6 @@ const error_page_js_1 = require("../../shared/error-page.js");
|
|
|
24
24
|
const handleErrorWithoutErrorPage_js_1 = require("./renderPage/handleErrorWithoutErrorPage.js");
|
|
25
25
|
const loadPageConfigsLazyServerSide_js_1 = require("./renderPage/loadPageConfigsLazyServerSide.js");
|
|
26
26
|
const resolveRedirects_js_1 = require("./renderPage/resolveRedirects.js");
|
|
27
|
-
const getProxyForPublicUsage_js_1 = require("../../shared/getProxyForPublicUsage.js");
|
|
28
27
|
const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
|
|
29
28
|
httpRequestsCount: 0
|
|
30
29
|
});
|
|
@@ -489,6 +488,5 @@ function getPageContextInvalidVikeConfig(err, pageContextInit, httpRequestId) {
|
|
|
489
488
|
function forkPageContext(pageContextBegin) {
|
|
490
489
|
const pageContext = {};
|
|
491
490
|
(0, utils_js_1.objectAssign)(pageContext, pageContextBegin, true);
|
|
492
|
-
|
|
493
|
-
return pageContextWithProxy;
|
|
491
|
+
return pageContext;
|
|
494
492
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPageContextShared = createPageContextShared;
|
|
4
4
|
exports.createPageContextObject = createPageContextObject;
|
|
5
|
-
const getProxyForPublicUsage_js_1 = require("./getProxyForPublicUsage.js");
|
|
6
5
|
const execHook_js_1 = require("./hooks/execHook.js");
|
|
7
6
|
const preparePageContextForPublicUsage_js_1 = require("./preparePageContextForPublicUsage.js");
|
|
8
7
|
const utils_js_1 = require("./utils.js");
|
|
@@ -17,6 +16,5 @@ function createPageContextObject() {
|
|
|
17
16
|
isPageContext: true
|
|
18
17
|
};
|
|
19
18
|
(0, utils_js_1.changeEnumerable)(pageContext, '_isOriginalObject', false);
|
|
20
|
-
|
|
21
|
-
return pageContextWithProxy;
|
|
19
|
+
return pageContext;
|
|
22
20
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getProxyForPublicUsage = getProxyForPublicUsage;
|
|
4
|
-
exports.getProxyForPublicUsageFlat = getProxyForPublicUsageFlat;
|
|
5
|
-
exports.getProxyForMutationTracking = getProxyForMutationTracking;
|
|
6
4
|
// We use a proxy instead of property getters.
|
|
7
5
|
// - The issue with property getters is that they can't be `writable: true` but we do want the user to be able to modify the value of internal properties.
|
|
8
6
|
// ```console
|
|
@@ -12,76 +10,29 @@ exports.getProxyForMutationTracking = getProxyForMutationTracking;
|
|
|
12
10
|
// Show warning when user is accessing internal `_` properties.
|
|
13
11
|
const NOT_SERIALIZABLE_js_1 = require("./NOT_SERIALIZABLE.js");
|
|
14
12
|
const utils_js_1 = require("./utils.js");
|
|
15
|
-
function getProxyForPublicUsage(obj, objName, skipOnInternalProp) {
|
|
13
|
+
function getProxyForPublicUsage(obj, objName, skipOnInternalProp, fallback) {
|
|
16
14
|
return new Proxy(obj, {
|
|
17
|
-
get: getTrapGet(obj, objName, skipOnInternalProp)
|
|
15
|
+
get: getTrapGet(obj, objName, skipOnInternalProp, fallback)
|
|
18
16
|
});
|
|
19
17
|
}
|
|
20
|
-
function
|
|
21
|
-
(0, utils_js_1.assert)(obj._isOriginalObject);
|
|
22
|
-
(0, utils_js_1.assert)(obj._proxyTarget);
|
|
23
|
-
obj._proxyTargetPublic ?? (obj._proxyTargetPublic = {});
|
|
24
|
-
const target = obj._proxyTargetPublic;
|
|
25
|
-
obj._userMods ?? (obj._userMods = {});
|
|
26
|
-
const objUserMods = obj._userMods;
|
|
27
|
-
const update = () => {
|
|
28
|
-
(0, utils_js_1.assert)(obj._proxyTarget);
|
|
29
|
-
(0, utils_js_1.objectReplace)(target, obj._proxyTarget);
|
|
30
|
-
(0, utils_js_1.objectAssign)(target, objUserMods);
|
|
31
|
-
};
|
|
32
|
-
obj._onChange = () => {
|
|
33
|
-
update();
|
|
34
|
-
};
|
|
35
|
-
update();
|
|
36
|
-
return new Proxy(target, {
|
|
37
|
-
// get: getTrapGet(target, objName, skipOnInternalProp),
|
|
38
|
-
set(_, prop, val) {
|
|
39
|
-
const ret = Reflect.set(objUserMods, prop, val);
|
|
40
|
-
update();
|
|
41
|
-
return ret;
|
|
42
|
-
},
|
|
43
|
-
defineProperty(_, ...args) {
|
|
44
|
-
const ret = Reflect.defineProperty(objUserMods, ...args);
|
|
45
|
-
update();
|
|
46
|
-
return ret;
|
|
47
|
-
},
|
|
48
|
-
deleteProperty(_, ...args) {
|
|
49
|
-
const ret = Reflect.deleteProperty(objUserMods, ...args);
|
|
50
|
-
update();
|
|
51
|
-
return ret;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function getTrapGet(obj, objName, skipOnInternalProp) {
|
|
18
|
+
function getTrapGet(obj, objName, skipOnInternalProp, fallback) {
|
|
56
19
|
return function (_, prop) {
|
|
57
20
|
const propStr = String(prop);
|
|
21
|
+
if (prop === '_isProxyObject')
|
|
22
|
+
return { target: obj };
|
|
58
23
|
if (!skipOnInternalProp)
|
|
59
24
|
onInternalProp(propStr, objName);
|
|
25
|
+
if (fallback) {
|
|
26
|
+
// Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
|
|
27
|
+
// Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
|
|
28
|
+
if (!(prop in obj))
|
|
29
|
+
return fallback(prop);
|
|
30
|
+
}
|
|
60
31
|
const val = obj[prop];
|
|
61
32
|
onNotSerializable(propStr, val, objName);
|
|
62
33
|
return val;
|
|
63
34
|
};
|
|
64
35
|
}
|
|
65
|
-
function getProxyForMutationTracking(obj) {
|
|
66
|
-
(0, utils_js_1.objectAssign)(obj, { _proxyTarget: obj });
|
|
67
|
-
return new Proxy(obj, {
|
|
68
|
-
set(...args) {
|
|
69
|
-
const ret = Reflect.set(...args);
|
|
70
|
-
obj._onChange?.();
|
|
71
|
-
return ret;
|
|
72
|
-
},
|
|
73
|
-
defineProperty(...args) {
|
|
74
|
-
const ret = Reflect.defineProperty(...args);
|
|
75
|
-
obj._onChange?.();
|
|
76
|
-
return ret;
|
|
77
|
-
},
|
|
78
|
-
deleteProperty(...args) {
|
|
79
|
-
const ret = Reflect.deleteProperty(...args);
|
|
80
|
-
obj._onChange?.();
|
|
81
|
-
return ret;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
36
|
function onNotSerializable(propStr, val, objName) {
|
|
86
37
|
if (val !== NOT_SERIALIZABLE_js_1.NOT_SERIALIZABLE)
|
|
87
38
|
return;
|
|
@@ -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,11 +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);
|
|
11
|
+
(0, utils_js_1.assert)(!pageContext.globalContext); // pageContext.globalContext should only be available to users — Vike itself should use pageContext._globalContext instead
|
|
10
12
|
(0, utils_js_1.assert)(pageContext._isOriginalObject); // ensure we preserve the original object reference
|
|
11
|
-
const globalContextPublic = (0, prepareGlobalContextForPublicUsage_js_1.prepareGlobalContextForPublicUsage)(pageContext._globalContext);
|
|
12
|
-
(0, utils_js_1.objectAssign)(pageContext, {
|
|
13
|
-
globalContext: globalContextPublic
|
|
14
|
-
});
|
|
15
13
|
(0, addIs404ToPageProps_js_1.addIs404ToPageProps)(pageContext);
|
|
16
14
|
// TODO/next-major-release: remove
|
|
17
15
|
if (!('_pageId' in pageContext)) {
|
|
@@ -28,15 +26,22 @@ function preparePageContextForPublicUsage(pageContext) {
|
|
|
28
26
|
}
|
|
29
27
|
// For a more readable `console.log(pageContext)` output
|
|
30
28
|
sortPageContext(pageContext);
|
|
31
|
-
const
|
|
29
|
+
const globalContextPublic = (0, prepareGlobalContextForPublicUsage_js_1.prepareGlobalContextForPublicUsage)(pageContext._globalContext);
|
|
30
|
+
const pageContextPublic = (0, getProxyForPublicUsage_js_1.getProxyForPublicUsage)(pageContext, 'pageContext',
|
|
32
31
|
// We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
|
|
33
32
|
// - TODO/now: double check whether that's true
|
|
34
|
-
true)
|
|
33
|
+
true, (prop) => {
|
|
34
|
+
if (prop === 'globalContext') {
|
|
35
|
+
return globalContextPublic;
|
|
36
|
+
}
|
|
37
|
+
if (prop in globalContextPublic) {
|
|
38
|
+
return globalContextPublic[prop];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
35
41
|
return pageContextPublic;
|
|
36
42
|
}
|
|
37
43
|
// Sort `pageContext` keys alphabetically, in order to make reading the `console.log(pageContext)` output easier
|
|
38
44
|
function sortPageContext(pageContext) {
|
|
39
|
-
return;
|
|
40
45
|
let descriptors = Object.getOwnPropertyDescriptors(pageContext);
|
|
41
46
|
for (const key of Object.keys(pageContext))
|
|
42
47
|
delete pageContext[key];
|
package/dist/cjs/shared/utils.js
CHANGED
|
@@ -44,4 +44,3 @@ __exportStar(require("../utils/objectDefineProperty.js"), exports);
|
|
|
44
44
|
__exportStar(require("../utils/isScriptFile.js"), exports);
|
|
45
45
|
__exportStar(require("../utils/objectFilter.js"), exports);
|
|
46
46
|
__exportStar(require("../utils/getPropAccessNotation.js"), exports);
|
|
47
|
-
__exportStar(require("../utils/objectReplace.js"), exports);
|
|
@@ -8,4 +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):
|
|
11
|
+
declare function preparePageContextForPublicUsageClientMinimal<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext;
|
|
@@ -32,7 +32,6 @@ function supportVueReactiviy(pageContext) {
|
|
|
32
32
|
// Remove propery descriptor getters because they break Vue's reactivity.
|
|
33
33
|
// E.g. resolve the `pageContext.urlPathname` getter.
|
|
34
34
|
function resolveGetters(pageContext) {
|
|
35
|
-
return;
|
|
36
35
|
Object.entries(pageContext).forEach(([key, val]) => {
|
|
37
36
|
delete pageContext[key];
|
|
38
37
|
pageContext[key] = val;
|
|
@@ -19,7 +19,6 @@ import { getErrorPageId } from '../../shared/error-page.js';
|
|
|
19
19
|
import { handleErrorWithoutErrorPage } from './renderPage/handleErrorWithoutErrorPage.js';
|
|
20
20
|
import { loadPageConfigsLazyServerSide } from './renderPage/loadPageConfigsLazyServerSide.js';
|
|
21
21
|
import { resolveRedirects } from './renderPage/resolveRedirects.js';
|
|
22
|
-
import { getProxyForMutationTracking } from '../../shared/getProxyForPublicUsage.js';
|
|
23
22
|
const globalObject = getGlobalObject('runtime/renderPage.ts', {
|
|
24
23
|
httpRequestsCount: 0
|
|
25
24
|
});
|
|
@@ -484,6 +483,5 @@ function getPageContextInvalidVikeConfig(err, pageContextInit, httpRequestId) {
|
|
|
484
483
|
function forkPageContext(pageContextBegin) {
|
|
485
484
|
const pageContext = {};
|
|
486
485
|
objectAssign(pageContext, pageContextBegin, true);
|
|
487
|
-
|
|
488
|
-
return pageContextWithProxy;
|
|
486
|
+
return pageContext;
|
|
489
487
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { createPageContextShared };
|
|
2
2
|
export { createPageContextObject };
|
|
3
|
-
import { getProxyForMutationTracking } from './getProxyForPublicUsage.js';
|
|
4
3
|
import { execHookGlobal } from './hooks/execHook.js';
|
|
5
4
|
import { preparePageContextForPublicUsage } from './preparePageContextForPublicUsage.js';
|
|
6
5
|
import { changeEnumerable, objectAssign } from './utils.js';
|
|
@@ -15,6 +14,5 @@ function createPageContextObject() {
|
|
|
15
14
|
isPageContext: true
|
|
16
15
|
};
|
|
17
16
|
changeEnumerable(pageContext, '_isOriginalObject', false);
|
|
18
|
-
|
|
19
|
-
return pageContextWithProxy;
|
|
17
|
+
return pageContext;
|
|
20
18
|
}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
export { getProxyForPublicUsage };
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
_onChange?: () => void;
|
|
6
|
-
_proxyTarget?: any;
|
|
7
|
-
_userMods?: any;
|
|
8
|
-
_proxyTargetPublic?: any;
|
|
9
|
-
};
|
|
10
|
-
declare function getProxyForPublicUsage<Obj extends Target>(obj: Obj, objName: string, skipOnInternalProp?: true): Obj;
|
|
11
|
-
declare function getProxyForPublicUsageFlat<Obj extends Target>(obj: Obj, objName: string, skipOnInternalProp?: true): Obj;
|
|
12
|
-
declare function getProxyForMutationTracking<Obj extends Target>(obj: Obj): Obj;
|
|
2
|
+
type Target = Record<string, unknown>;
|
|
3
|
+
type Fallback = (prop: string | symbol) => unknown;
|
|
4
|
+
declare function getProxyForPublicUsage<Obj extends Target>(obj: Obj, objName: string, skipOnInternalProp?: true, fallback?: Fallback): Obj;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export { getProxyForPublicUsage };
|
|
2
|
-
export { getProxyForPublicUsageFlat };
|
|
3
|
-
export { getProxyForMutationTracking };
|
|
4
2
|
// We use a proxy instead of property getters.
|
|
5
3
|
// - The issue with property getters is that they can't be `writable: true` but we do want the user to be able to modify the value of internal properties.
|
|
6
4
|
// ```console
|
|
@@ -9,77 +7,30 @@ export { getProxyForMutationTracking };
|
|
|
9
7
|
// - Previous implementation using property getters: https://github.com/vikejs/vike/blob/main/vike/utils/makePublicCopy.ts
|
|
10
8
|
// Show warning when user is accessing internal `_` properties.
|
|
11
9
|
import { NOT_SERIALIZABLE } from './NOT_SERIALIZABLE.js';
|
|
12
|
-
import { assert, assertUsage, assertWarning, getPropAccessNotation, isBrowser
|
|
13
|
-
function getProxyForPublicUsage(obj, objName, skipOnInternalProp) {
|
|
10
|
+
import { assert, assertUsage, assertWarning, getPropAccessNotation, isBrowser } from './utils.js';
|
|
11
|
+
function getProxyForPublicUsage(obj, objName, skipOnInternalProp, fallback) {
|
|
14
12
|
return new Proxy(obj, {
|
|
15
|
-
get: getTrapGet(obj, objName, skipOnInternalProp)
|
|
13
|
+
get: getTrapGet(obj, objName, skipOnInternalProp, fallback)
|
|
16
14
|
});
|
|
17
15
|
}
|
|
18
|
-
function
|
|
19
|
-
assert(obj._isOriginalObject);
|
|
20
|
-
assert(obj._proxyTarget);
|
|
21
|
-
obj._proxyTargetPublic ?? (obj._proxyTargetPublic = {});
|
|
22
|
-
const target = obj._proxyTargetPublic;
|
|
23
|
-
obj._userMods ?? (obj._userMods = {});
|
|
24
|
-
const objUserMods = obj._userMods;
|
|
25
|
-
const update = () => {
|
|
26
|
-
assert(obj._proxyTarget);
|
|
27
|
-
objectReplace(target, obj._proxyTarget);
|
|
28
|
-
objectAssign(target, objUserMods);
|
|
29
|
-
};
|
|
30
|
-
obj._onChange = () => {
|
|
31
|
-
update();
|
|
32
|
-
};
|
|
33
|
-
update();
|
|
34
|
-
return new Proxy(target, {
|
|
35
|
-
// get: getTrapGet(target, objName, skipOnInternalProp),
|
|
36
|
-
set(_, prop, val) {
|
|
37
|
-
const ret = Reflect.set(objUserMods, prop, val);
|
|
38
|
-
update();
|
|
39
|
-
return ret;
|
|
40
|
-
},
|
|
41
|
-
defineProperty(_, ...args) {
|
|
42
|
-
const ret = Reflect.defineProperty(objUserMods, ...args);
|
|
43
|
-
update();
|
|
44
|
-
return ret;
|
|
45
|
-
},
|
|
46
|
-
deleteProperty(_, ...args) {
|
|
47
|
-
const ret = Reflect.deleteProperty(objUserMods, ...args);
|
|
48
|
-
update();
|
|
49
|
-
return ret;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function getTrapGet(obj, objName, skipOnInternalProp) {
|
|
16
|
+
function getTrapGet(obj, objName, skipOnInternalProp, fallback) {
|
|
54
17
|
return function (_, prop) {
|
|
55
18
|
const propStr = String(prop);
|
|
19
|
+
if (prop === '_isProxyObject')
|
|
20
|
+
return { target: obj };
|
|
56
21
|
if (!skipOnInternalProp)
|
|
57
22
|
onInternalProp(propStr, objName);
|
|
23
|
+
if (fallback) {
|
|
24
|
+
// Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
|
|
25
|
+
// Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
|
|
26
|
+
if (!(prop in obj))
|
|
27
|
+
return fallback(prop);
|
|
28
|
+
}
|
|
58
29
|
const val = obj[prop];
|
|
59
30
|
onNotSerializable(propStr, val, objName);
|
|
60
31
|
return val;
|
|
61
32
|
};
|
|
62
33
|
}
|
|
63
|
-
function getProxyForMutationTracking(obj) {
|
|
64
|
-
objectAssign(obj, { _proxyTarget: obj });
|
|
65
|
-
return new Proxy(obj, {
|
|
66
|
-
set(...args) {
|
|
67
|
-
const ret = Reflect.set(...args);
|
|
68
|
-
obj._onChange?.();
|
|
69
|
-
return ret;
|
|
70
|
-
},
|
|
71
|
-
defineProperty(...args) {
|
|
72
|
-
const ret = Reflect.defineProperty(...args);
|
|
73
|
-
obj._onChange?.();
|
|
74
|
-
return ret;
|
|
75
|
-
},
|
|
76
|
-
deleteProperty(...args) {
|
|
77
|
-
const ret = Reflect.deleteProperty(...args);
|
|
78
|
-
obj._onChange?.();
|
|
79
|
-
return ret;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
34
|
function onNotSerializable(propStr, val, objName) {
|
|
84
35
|
if (val !== NOT_SERIALIZABLE)
|
|
85
36
|
return;
|
|
@@ -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,7 +6,9 @@ type PageContextPrepareMinimum = {
|
|
|
6
6
|
_isOriginalObject: true;
|
|
7
7
|
isPageContext: true;
|
|
8
8
|
_globalContext: GlobalContextPrepareMinimum;
|
|
9
|
-
|
|
9
|
+
_isProxyObject?: {
|
|
10
|
+
target: PageContextPrepareMinimum;
|
|
11
|
+
};
|
|
10
12
|
};
|
|
11
|
-
declare function preparePageContextForPublicUsage(pageContext:
|
|
13
|
+
declare function preparePageContextForPublicUsage<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext;
|
|
12
14
|
declare function assertPropertyGetters(pageContext: Record<string, unknown>): void;
|
|
@@ -1,15 +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
|
-
import {
|
|
6
|
+
import { getProxyForPublicUsage } from './getProxyForPublicUsage.js';
|
|
7
7
|
function preparePageContextForPublicUsage(pageContext) {
|
|
8
|
+
assert(!pageContext._isProxyObject);
|
|
9
|
+
assert(!pageContext.globalContext); // pageContext.globalContext should only be available to users — Vike itself should use pageContext._globalContext instead
|
|
8
10
|
assert(pageContext._isOriginalObject); // ensure we preserve the original object reference
|
|
9
|
-
const globalContextPublic = prepareGlobalContextForPublicUsage(pageContext._globalContext);
|
|
10
|
-
objectAssign(pageContext, {
|
|
11
|
-
globalContext: globalContextPublic
|
|
12
|
-
});
|
|
13
11
|
addIs404ToPageProps(pageContext);
|
|
14
12
|
// TODO/next-major-release: remove
|
|
15
13
|
if (!('_pageId' in pageContext)) {
|
|
@@ -26,15 +24,22 @@ function preparePageContextForPublicUsage(pageContext) {
|
|
|
26
24
|
}
|
|
27
25
|
// For a more readable `console.log(pageContext)` output
|
|
28
26
|
sortPageContext(pageContext);
|
|
29
|
-
const
|
|
27
|
+
const globalContextPublic = prepareGlobalContextForPublicUsage(pageContext._globalContext);
|
|
28
|
+
const pageContextPublic = getProxyForPublicUsage(pageContext, 'pageContext',
|
|
30
29
|
// We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
|
|
31
30
|
// - TODO/now: double check whether that's true
|
|
32
|
-
true)
|
|
31
|
+
true, (prop) => {
|
|
32
|
+
if (prop === 'globalContext') {
|
|
33
|
+
return globalContextPublic;
|
|
34
|
+
}
|
|
35
|
+
if (prop in globalContextPublic) {
|
|
36
|
+
return globalContextPublic[prop];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
33
39
|
return pageContextPublic;
|
|
34
40
|
}
|
|
35
41
|
// Sort `pageContext` keys alphabetically, in order to make reading the `console.log(pageContext)` output easier
|
|
36
42
|
function sortPageContext(pageContext) {
|
|
37
|
-
return;
|
|
38
43
|
let descriptors = Object.getOwnPropertyDescriptors(pageContext);
|
|
39
44
|
for (const key of Object.keys(pageContext))
|
|
40
45
|
delete pageContext[key];
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -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';
|