vike 0.4.229-commit-c3526d6 → 0.4.229-commit-e1ca16d

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.
@@ -19,14 +19,13 @@ function getTrapGet(obj, objName, skipOnInternalProp, fallback) {
19
19
  return function (_, prop) {
20
20
  const propStr = String(prop);
21
21
  if (prop === '_isProxyObject')
22
- return { target: obj };
22
+ return true;
23
23
  if (!skipOnInternalProp)
24
24
  onInternalProp(propStr, objName);
25
- if (fallback) {
25
+ if (fallback && !(prop in obj)) {
26
26
  // Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
27
27
  // Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
28
- if (!(prop in obj))
29
- return fallback(prop);
28
+ return fallback(prop);
30
29
  }
31
30
  const val = obj[prop];
32
31
  onNotSerializable(propStr, val, objName);
@@ -115,7 +115,7 @@ function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
115
115
  }, timeoutErr);
116
116
  (async () => {
117
117
  try {
118
- providePageContext(pageContextForPublicUsage);
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
- providePageContext(pageContextForPublicUsage);
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 pageContext;
149
- const pageContextForPublicUsage = (0, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage)(pageContext);
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,9 +158,9 @@ function getPageContext() {
155
158
  * https://vike.dev/getPageContext
156
159
  */
157
160
  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;
161
+ providePageContextInternal(pageContext);
162
+ }
163
+ function providePageContextInternal(pageContext) {
161
164
  globalObject.pageContext = pageContext;
162
165
  // Promise.resolve() is quicker than process.nextTick() and setImmediate()
163
166
  // https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.229-commit-c3526d6';
5
+ exports.PROJECT_VERSION = '0.4.229-commit-e1ca16d';
@@ -77,7 +77,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
77
77
  routeParams: Record<string, string>;
78
78
  } & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & import("../../shared/types.js").PageContextInternalClient & Omit<Partial<{
79
79
  isPageContext: true;
80
- Page: import("../../shared/page-configs/Config.js").Config["Page"];
80
+ Page: import("../../types/index.js").Config["Page"];
81
81
  routeParams: Record<string, string>;
82
82
  data: unknown;
83
83
  config: import("../../shared/page-configs/Config/PageContextConfig.js").PageContextConfig;
@@ -101,7 +101,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
101
101
  isBaseMissing?: true;
102
102
  }> & Pick<{
103
103
  isPageContext: true;
104
- Page: import("../../shared/page-configs/Config.js").Config["Page"];
104
+ Page: import("../../types/index.js").Config["Page"];
105
105
  routeParams: Record<string, string>;
106
106
  data: unknown;
107
107
  config: import("../../shared/page-configs/Config/PageContextConfig.js").PageContextConfig;
@@ -148,7 +148,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
148
148
  _hasPageContextFromServer: true;
149
149
  } & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & Omit<Partial<{
150
150
  isPageContext: true;
151
- Page: import("../../shared/page-configs/Config.js").Config["Page"];
151
+ Page: import("../../types/index.js").Config["Page"];
152
152
  routeParams: Record<string, string>;
153
153
  data: unknown;
154
154
  config: import("../../shared/page-configs/Config/PageContextConfig.js").PageContextConfig;
@@ -172,7 +172,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
172
172
  isBaseMissing?: true;
173
173
  }> & Pick<{
174
174
  isPageContext: true;
175
- Page: import("../../shared/page-configs/Config.js").Config["Page"];
175
+ Page: import("../../types/index.js").Config["Page"];
176
176
  routeParams: Record<string, string>;
177
177
  data: unknown;
178
178
  config: import("../../shared/page-configs/Config/PageContextConfig.js").PageContextConfig;
@@ -288,7 +288,7 @@ declare function getPageContextFromClientHooks(pageContext: {
288
288
  routeParams: Record<string, string>;
289
289
  } & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & import("../../shared/types.js").PageContextInternalClient & Omit<Partial<{
290
290
  isPageContext: true;
291
- Page: import("../../shared/page-configs/Config.js").Config["Page"];
291
+ Page: import("../../types/index.js").Config["Page"];
292
292
  routeParams: Record<string, string>;
293
293
  data: unknown;
294
294
  config: import("../../shared/page-configs/Config/PageContextConfig.js").PageContextConfig;
@@ -312,7 +312,7 @@ declare function getPageContextFromClientHooks(pageContext: {
312
312
  isBaseMissing?: true;
313
313
  }> & Pick<{
314
314
  isPageContext: true;
315
- Page: import("../../shared/page-configs/Config.js").Config["Page"];
315
+ Page: import("../../types/index.js").Config["Page"];
316
316
  routeParams: Record<string, string>;
317
317
  data: unknown;
318
318
  config: import("../../shared/page-configs/Config/PageContextConfig.js").PageContextConfig;
@@ -357,7 +357,7 @@ declare function getPageContextFromClientHooks(pageContext: {
357
357
  }) | null;
358
358
  } & PageConfigUserFriendlyOld & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & Omit<Partial<{
359
359
  isPageContext: true;
360
- Page: import("../../shared/page-configs/Config.js").Config["Page"];
360
+ Page: import("../../types/index.js").Config["Page"];
361
361
  routeParams: Record<string, string>;
362
362
  data: unknown;
363
363
  config: import("../../shared/page-configs/Config/PageContextConfig.js").PageContextConfig;
@@ -381,7 +381,7 @@ declare function getPageContextFromClientHooks(pageContext: {
381
381
  isBaseMissing?: true;
382
382
  }> & Pick<{
383
383
  isPageContext: true;
384
- Page: import("../../shared/page-configs/Config.js").Config["Page"];
384
+ Page: import("../../types/index.js").Config["Page"];
385
385
  routeParams: Record<string, string>;
386
386
  data: unknown;
387
387
  config: import("../../shared/page-configs/Config/PageContextConfig.js").PageContextConfig;
@@ -65,7 +65,7 @@ async function getPageContextFromServerHooks(pageContext, isErrorPage) {
65
65
  return { pageContextFromServerHooks };
66
66
  }
67
67
  async function getPageContextFromClientHooks(pageContext, isErrorPage) {
68
- let dataHookExists = false;
68
+ let dataHookExec = false;
69
69
  // At this point, we need to call the client-side guard(), data() and onBeforeRender() hooks, if they exist on client
70
70
  // env. However if we have fetched pageContext from the server, some of them might have run already on the
71
71
  // server-side, so we run only the client-only ones in this case.
@@ -82,16 +82,17 @@ async function getPageContextFromClientHooks(pageContext, isErrorPage) {
82
82
  }
83
83
  }
84
84
  else {
85
- if (hookName === 'data')
86
- dataHookExists = true;
87
85
  if (hookClientOnlyExists(hookName, pageContext) || !pageContext._hasPageContextFromServer) {
86
+ if (hookName === 'data')
87
+ dataHookExec = true;
88
88
  // This won't do anything if no hook has been defined or if the hook's env.client is false.
89
89
  await executeDataLikeHook(hookName, pageContext);
90
90
  }
91
91
  }
92
92
  }
93
93
  // Execute +onData
94
- if (dataHookExists) {
94
+ const dataHookEnv = getHookEnv('data', pageContext);
95
+ if ((dataHookExec && dataHookEnv.client) || (pageContext._hasPageContextFromServer && dataHookEnv.server)) {
95
96
  await execHookClient('onData', pageContext);
96
97
  }
97
98
  const pageContextFromClientHooks = pageContext;
@@ -188,23 +189,22 @@ async function hookServerOnlyExists(hookName, pageContext) {
188
189
  return hasOnBeforeRenderServerSideOnlyHook;
189
190
  }
190
191
  }
191
- /**
192
- * @param hookName
193
- * @param pageContext
194
- * @returns `true` if the given page has a `hookName` hook defined with a client-only env.
195
- */
196
192
  function hookClientOnlyExists(hookName, pageContext) {
193
+ const hookEnv = getHookEnv(hookName, pageContext);
194
+ return !!hookEnv.client && !hookEnv.server;
195
+ }
196
+ function getHookEnv(hookName, pageContext) {
197
197
  if (pageContext._pageConfigs.length > 0) {
198
198
  // V1
199
199
  const pageConfig = getPageConfig(pageContext.pageId, pageContext._pageConfigs);
200
- const hookEnv = getConfigValueRuntime(pageConfig, `${hookName}Env`)?.value ?? {};
201
- assert(isObject(hookEnv));
202
- return !!hookEnv.client && !hookEnv.server;
200
+ // No runtime validation to save client-side KBs
201
+ const hookEnv = (getConfigValueRuntime(pageConfig, `${hookName}Env`)?.value ?? {});
202
+ return hookEnv;
203
203
  }
204
204
  else {
205
205
  // TODO/v1-release: remove
206
206
  // Client-only onBeforeRender() or data() hooks were never supported for the V0.4 design
207
- return false;
207
+ return { client: false, server: true };
208
208
  }
209
209
  }
210
210
  async function fetchPageContextFromServer(pageContext) {
@@ -4,7 +4,7 @@ export { disableClientRouting };
4
4
  export { firstRenderStartPromise };
5
5
  export { getPageContextClient };
6
6
  import { assert, isSameErrorMessage, objectAssign, redirectHard, getGlobalObject, hasProp, augmentType, genPromise, isCallable, catchInfiniteLoop } from './utils.js';
7
- import { getPageContextFromClientHooks, getPageContextFromServerHooks, getPageContextFromHooks_isHydration, getPageContextFromHooks_serialized, setPageContextInitIsPassedToClient, execHookClient } from './getPageContextFromHooks.js';
7
+ import { getPageContextFromClientHooks, getPageContextFromServerHooks, getPageContextFromHooks_isHydration, getPageContextFromHooks_serialized, setPageContextInitIsPassedToClient } from './getPageContextFromHooks.js';
8
8
  import { createPageContextClientSide } from './createPageContextClientSide.js';
9
9
  import { addLinkPrefetchHandlers, addLinkPrefetchHandlers_unwatch, addLinkPrefetchHandlers_watch, getPageContextPrefetched, populatePageContextPrefetchCache } from './prefetch.js';
10
10
  import { assertInfo, assertWarning, isReact } from './utils.js';
@@ -203,16 +203,6 @@ async function renderPageClientSide(renderArgs) {
203
203
  // TO-DO/eventually: create helper assertPageContextFromHook()
204
204
  assert(!('urlOriginal' in pageContextFromServerHooks));
205
205
  objectAssign(pageContext, pageContextFromServerHooks);
206
- // Execute +onData
207
- try {
208
- await execHookClient('onData', pageContext);
209
- }
210
- catch (err) {
211
- await onError(err);
212
- return;
213
- }
214
- if (isRenderOutdated())
215
- return;
216
206
  // Get pageContext from client-side hooks
217
207
  let pageContextFromClientHooks;
218
208
  try {
@@ -17,14 +17,13 @@ function getTrapGet(obj, objName, skipOnInternalProp, fallback) {
17
17
  return function (_, prop) {
18
18
  const propStr = String(prop);
19
19
  if (prop === '_isProxyObject')
20
- return { target: obj };
20
+ return true;
21
21
  if (!skipOnInternalProp)
22
22
  onInternalProp(propStr, objName);
23
- if (fallback) {
23
+ if (fallback && !(prop in obj)) {
24
24
  // Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
25
25
  // Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
26
- if (!(prop in obj))
27
- return fallback(prop);
26
+ return fallback(prop);
28
27
  }
29
28
  const val = obj[prop];
30
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 | PageContextPrepareMinimum): void;
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
- providePageContext(pageContextForPublicUsage);
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
- providePageContext(pageContextForPublicUsage);
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 pageContext;
147
- const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
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,9 +156,9 @@ function getPageContext() {
153
156
  * https://vike.dev/getPageContext
154
157
  */
155
158
  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;
159
+ providePageContextInternal(pageContext);
160
+ }
161
+ function providePageContextInternal(pageContext) {
159
162
  globalObject.pageContext = pageContext;
160
163
  // Promise.resolve() is quicker than process.nextTick() and setImmediate()
161
164
  // https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
@@ -6,9 +6,6 @@ type PageContextPrepareMinimum = {
6
6
  _isOriginalObject: true;
7
7
  isPageContext: true;
8
8
  _globalContext: GlobalContextPrepareMinimum;
9
- _isProxyObject?: {
10
- target: PageContextPrepareMinimum;
11
- };
12
9
  };
13
10
  declare function preparePageContextForPublicUsage<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext;
14
11
  declare function assertPropertyGetters(pageContext: Record<string, unknown>): void;
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.229-commit-c3526d6";
1
+ export declare const PROJECT_VERSION: "0.4.229-commit-e1ca16d";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.229-commit-c3526d6';
2
+ export const PROJECT_VERSION = '0.4.229-commit-e1ca16d';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.229-commit-c3526d6",
3
+ "version": "0.4.229-commit-e1ca16d",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {