vike 0.4.235-commit-9b9289b → 0.4.235-commit-d2ac38a

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.
@@ -378,14 +378,17 @@ async function setGlobalContext(virtualFileExports) {
378
378
  globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
379
379
  assertGlobalContextIsDefined();
380
380
  (0, utils_js_1.onSetupRuntime)();
381
+ debug('setGlobalContext() - done');
381
382
  // Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
382
383
  return globalContext;
383
384
  }
384
385
  async function addGlobalContextAsync(globalContext) {
386
+ debug('addGlobalContextAsync()');
385
387
  const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
386
388
  return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
387
389
  }
388
390
  function addGlobalContextSync(globalContext) {
391
+ debug('addGlobalContextSync()');
389
392
  const { pageRoutes, onBeforeRouteHook } = (0, loadPageRoutes_js_1.loadPageRoutesSync)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
390
393
  return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
391
394
  }
@@ -32,20 +32,41 @@ const passToClientBuiltInPageContext = [
32
32
  const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError_js_1.isServerSideError];
33
33
  function getPageContextClientSerialized(pageContext) {
34
34
  const passToClientPageContext = getPassToClientPageContext(pageContext);
35
- const pageContextClient = applyPassToClient(passToClientPageContext, pageContext);
36
- if (passToClientPageContext.some((prop) => (0, propKeys_js_1.getPropVal)(pageContext._pageContextInit, prop))) {
35
+ const getObj = (passToClientEntry) => {
36
+ if (passToClientEntry.once)
37
+ return undefined; // pass it to client-side globalContext
38
+ return { obj: pageContext, objName: 'pageContext' };
39
+ };
40
+ const res = applyPassToClient(passToClientPageContext, getObj);
41
+ const pageContextClient = res.objClient;
42
+ const pageContextClientProps = res.objClientProps;
43
+ if (pageContextClientProps.some((prop) => (0, propKeys_js_1.getPropVal)(pageContext._pageContextInit, prop))) {
37
44
  pageContextClient[pageContextInitIsPassedToClient_js_1.pageContextInitIsPassedToClient] = true;
38
45
  }
39
- const pageContextClientSerialized = serializeObject(pageContextClient, 'pageContext', passToClientPageContext);
46
+ const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, getObj);
40
47
  return pageContextClientSerialized;
41
48
  }
42
49
  function getGlobalContextClientSerialized(pageContext) {
43
50
  const passToClient = pageContext._passToClient;
44
- const globalContextClient = applyPassToClient(passToClient, pageContext._globalContext);
45
- const globalContextClientSerialized = serializeObject(globalContextClient, 'globalContext', passToClient);
51
+ const globalContext = pageContext._globalContext;
52
+ const getObj = ({ prop, once }) => {
53
+ if (once && (0, propKeys_js_1.getPropVal)(pageContext, prop)) {
54
+ (0, utils_js_1.assert)(typeof pageContext.isClientSideNavigation === 'boolean');
55
+ if (!pageContext.isClientSideNavigation) {
56
+ return { obj: pageContext, objName: 'pageContext' }; // pass it to client-side globalContext
57
+ }
58
+ else {
59
+ return undefined; // already passed to client-side
60
+ }
61
+ }
62
+ return { obj: globalContext, objName: 'globalContext' };
63
+ };
64
+ const res = applyPassToClient(passToClient, getObj);
65
+ const globalContextClient = res.objClient;
66
+ const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, getObj);
46
67
  return globalContextClientSerialized;
47
68
  }
48
- function serializeObject(obj, objName, passToClient) {
69
+ function serializeObject(obj, passToClient, getObj) {
49
70
  let serialized;
50
71
  try {
51
72
  serialized = serializeValue(obj);
@@ -54,11 +75,15 @@ function serializeObject(obj, objName, passToClient) {
54
75
  const h = (s) => picocolors_1.default.cyan(s);
55
76
  let hasWarned = false;
56
77
  const propsNonSerializable = [];
57
- passToClient.forEach((prop) => {
78
+ passToClient.forEach((entry) => {
79
+ const entryNormalized = normalizePassToClientEntry(entry);
80
+ const { prop } = entryNormalized;
58
81
  const res = (0, propKeys_js_1.getPropVal)(obj, prop);
59
82
  if (!res)
60
83
  return;
61
84
  const { value } = res;
85
+ const { objName } = getObj(entryNormalized) ?? {};
86
+ (0, utils_js_1.assert)(objName);
62
87
  const varName = `${objName}${(0, propKeys_js_1.getPropKeys)(prop).map(utils_js_1.getPropAccessNotation).join('')}`;
63
88
  try {
64
89
  serializeValue(value, varName);
@@ -168,16 +193,36 @@ function getPageContextClientSerializedAbort(pageContext) {
168
193
  }
169
194
  return serializeValue(pageContext);
170
195
  }
171
- function applyPassToClient(passToClient, pageContext) {
172
- const pageContextClient = {};
173
- passToClient.forEach((prop) => {
196
+ function applyPassToClient(passToClient, getObj) {
197
+ const objClient = {};
198
+ const objClientProps = [];
199
+ passToClient.forEach((entry) => {
200
+ const entryNormalized = normalizePassToClientEntry(entry);
201
+ const { prop } = entryNormalized;
202
+ const { obj } = getObj(entryNormalized) ?? {};
203
+ if (!obj)
204
+ return;
174
205
  // Get value from pageContext
175
- const res = (0, propKeys_js_1.getPropVal)(pageContext, prop);
206
+ const res = (0, propKeys_js_1.getPropVal)(obj, prop);
176
207
  if (!res)
177
208
  return;
178
209
  const { value } = res;
179
210
  // Set value to pageContextClient
180
- (0, propKeys_js_1.setPropVal)(pageContextClient, prop, value);
211
+ (0, propKeys_js_1.setPropVal)(objClient, prop, value);
212
+ objClientProps.push(prop);
181
213
  });
182
- return pageContextClient;
214
+ return { objClient, objClientProps };
215
+ }
216
+ function normalizePassToClientEntry(entry) {
217
+ let once;
218
+ let prop;
219
+ if (typeof entry === 'string') {
220
+ prop = entry;
221
+ once = false;
222
+ }
223
+ else {
224
+ prop = entry.prop;
225
+ once = entry.once ?? false;
226
+ }
227
+ return { prop, once };
183
228
  }
@@ -41,8 +41,9 @@ async function loadPageConfigsLazyServerSide(pageContext) {
41
41
  }
42
42
  else {
43
43
  configPublicPageLazy.from.configsCumulative.passToClient?.values.forEach((v) => {
44
- const { value, definedAt } = v;
45
- (0, utils_js_1.assertUsage)((0, utils_js_1.isArrayOfStrings)(value), `+passToClient value defined at ${definedAt}${errMsg}`);
44
+ const { value } = v;
45
+ // const { definedAt } = v
46
+ // assertUsage(isArrayOfStrings(value), `+passToClient value defined at ${definedAt}${errMsg}`)
46
47
  passToClient.push(...value);
47
48
  });
48
49
  }
@@ -20,7 +20,9 @@ async function createGlobalContextShared(virtualFileExports, globalObject, addGl
20
20
  else {
21
21
  isNewGlobalContext = true;
22
22
  }
23
- if (addGlobalContextSync && globalContext._pageConfigs.length > 0) {
23
+ if (addGlobalContextSync &&
24
+ // TODO/next-major-release: remove
25
+ globalContext._pageConfigs.length > 0) {
24
26
  const globalContextAddendum = addGlobalContextSync?.(globalContext);
25
27
  (0, utils_js_1.objectAssign)(globalContext, globalContextAddendum);
26
28
  }
@@ -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.235-commit-9b9289b';
5
+ exports.PROJECT_VERSION = '0.4.235-commit-d2ac38a';
@@ -559,7 +559,7 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
559
559
  })) & import("../../shared/getPageFiles.js").VikeConfigPublicPageLazy) & {
560
560
  Page: unknown;
561
561
  _isHtmlOnly: boolean;
562
- _passToClient: string[];
562
+ _passToClient: import("../runtime/html/serializeContext.js").PassToClient;
563
563
  _pageFilePathsLoaded: string[];
564
564
  headersResponse: Headers;
565
565
  } & {
@@ -374,14 +374,17 @@ async function setGlobalContext(virtualFileExports) {
374
374
  globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
375
375
  assertGlobalContextIsDefined();
376
376
  onSetupRuntime();
377
+ debug('setGlobalContext() - done');
377
378
  // Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
378
379
  return globalContext;
379
380
  }
380
381
  async function addGlobalContextAsync(globalContext) {
382
+ debug('addGlobalContextAsync()');
381
383
  const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
382
384
  return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
383
385
  }
384
386
  function addGlobalContextSync(globalContext) {
387
+ debug('addGlobalContextSync()');
385
388
  const { pageRoutes, onBeforeRouteHook } = loadPageRoutesSync(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
386
389
  return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
387
390
  }
@@ -2,19 +2,25 @@ export { getPageContextClientSerialized };
2
2
  export { getPageContextClientSerializedAbort };
3
3
  export { getGlobalContextClientSerialized };
4
4
  export type { PageContextSerialization };
5
+ export type { PassToClient };
5
6
  import type { UrlRedirect } from '../../../shared/route/abort.js';
6
7
  import type { GlobalContextServerInternal } from '../globalContext.js';
7
8
  type PageContextSerialization = {
8
9
  pageId: string;
9
10
  routeParams: Record<string, string>;
10
- _passToClient: string[];
11
+ _passToClient: PassToClient;
11
12
  is404: null | boolean;
12
13
  pageProps?: Record<string, unknown>;
13
14
  _pageContextInit: Record<string, unknown>;
14
15
  _globalContext: GlobalContextServerInternal;
16
+ isClientSideNavigation: boolean;
15
17
  };
16
18
  declare function getPageContextClientSerialized(pageContext: PageContextSerialization): string;
17
19
  declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization): string;
20
+ type PassToClient = (string | {
21
+ prop: string;
22
+ once?: boolean;
23
+ })[];
18
24
  declare function getPageContextClientSerializedAbort(pageContext: Record<string, unknown> & ({
19
25
  _urlRedirect: UrlRedirect;
20
26
  } | {
@@ -27,20 +27,41 @@ const passToClientBuiltInPageContext = [
27
27
  const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError];
28
28
  function getPageContextClientSerialized(pageContext) {
29
29
  const passToClientPageContext = getPassToClientPageContext(pageContext);
30
- const pageContextClient = applyPassToClient(passToClientPageContext, pageContext);
31
- if (passToClientPageContext.some((prop) => getPropVal(pageContext._pageContextInit, prop))) {
30
+ const getObj = (passToClientEntry) => {
31
+ if (passToClientEntry.once)
32
+ return undefined; // pass it to client-side globalContext
33
+ return { obj: pageContext, objName: 'pageContext' };
34
+ };
35
+ const res = applyPassToClient(passToClientPageContext, getObj);
36
+ const pageContextClient = res.objClient;
37
+ const pageContextClientProps = res.objClientProps;
38
+ if (pageContextClientProps.some((prop) => getPropVal(pageContext._pageContextInit, prop))) {
32
39
  pageContextClient[pageContextInitIsPassedToClient] = true;
33
40
  }
34
- const pageContextClientSerialized = serializeObject(pageContextClient, 'pageContext', passToClientPageContext);
41
+ const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, getObj);
35
42
  return pageContextClientSerialized;
36
43
  }
37
44
  function getGlobalContextClientSerialized(pageContext) {
38
45
  const passToClient = pageContext._passToClient;
39
- const globalContextClient = applyPassToClient(passToClient, pageContext._globalContext);
40
- const globalContextClientSerialized = serializeObject(globalContextClient, 'globalContext', passToClient);
46
+ const globalContext = pageContext._globalContext;
47
+ const getObj = ({ prop, once }) => {
48
+ if (once && getPropVal(pageContext, prop)) {
49
+ assert(typeof pageContext.isClientSideNavigation === 'boolean');
50
+ if (!pageContext.isClientSideNavigation) {
51
+ return { obj: pageContext, objName: 'pageContext' }; // pass it to client-side globalContext
52
+ }
53
+ else {
54
+ return undefined; // already passed to client-side
55
+ }
56
+ }
57
+ return { obj: globalContext, objName: 'globalContext' };
58
+ };
59
+ const res = applyPassToClient(passToClient, getObj);
60
+ const globalContextClient = res.objClient;
61
+ const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, getObj);
41
62
  return globalContextClientSerialized;
42
63
  }
43
- function serializeObject(obj, objName, passToClient) {
64
+ function serializeObject(obj, passToClient, getObj) {
44
65
  let serialized;
45
66
  try {
46
67
  serialized = serializeValue(obj);
@@ -49,11 +70,15 @@ function serializeObject(obj, objName, passToClient) {
49
70
  const h = (s) => pc.cyan(s);
50
71
  let hasWarned = false;
51
72
  const propsNonSerializable = [];
52
- passToClient.forEach((prop) => {
73
+ passToClient.forEach((entry) => {
74
+ const entryNormalized = normalizePassToClientEntry(entry);
75
+ const { prop } = entryNormalized;
53
76
  const res = getPropVal(obj, prop);
54
77
  if (!res)
55
78
  return;
56
79
  const { value } = res;
80
+ const { objName } = getObj(entryNormalized) ?? {};
81
+ assert(objName);
57
82
  const varName = `${objName}${getPropKeys(prop).map(getPropAccessNotation).join('')}`;
58
83
  try {
59
84
  serializeValue(value, varName);
@@ -163,16 +188,36 @@ function getPageContextClientSerializedAbort(pageContext) {
163
188
  }
164
189
  return serializeValue(pageContext);
165
190
  }
166
- function applyPassToClient(passToClient, pageContext) {
167
- const pageContextClient = {};
168
- passToClient.forEach((prop) => {
191
+ function applyPassToClient(passToClient, getObj) {
192
+ const objClient = {};
193
+ const objClientProps = [];
194
+ passToClient.forEach((entry) => {
195
+ const entryNormalized = normalizePassToClientEntry(entry);
196
+ const { prop } = entryNormalized;
197
+ const { obj } = getObj(entryNormalized) ?? {};
198
+ if (!obj)
199
+ return;
169
200
  // Get value from pageContext
170
- const res = getPropVal(pageContext, prop);
201
+ const res = getPropVal(obj, prop);
171
202
  if (!res)
172
203
  return;
173
204
  const { value } = res;
174
205
  // Set value to pageContextClient
175
- setPropVal(pageContextClient, prop, value);
206
+ setPropVal(objClient, prop, value);
207
+ objClientProps.push(prop);
176
208
  });
177
- return pageContextClient;
209
+ return { objClient, objClientProps };
210
+ }
211
+ function normalizePassToClientEntry(entry) {
212
+ let once;
213
+ let prop;
214
+ if (typeof entry === 'string') {
215
+ prop = entry;
216
+ once = false;
217
+ }
218
+ else {
219
+ prop = entry.prop;
220
+ once = entry.once ?? false;
221
+ }
222
+ return { prop, once };
178
223
  }
@@ -7,6 +7,7 @@ import { PageContextGetPageAssets, type PageAsset } from './getPageAssets.js';
7
7
  import { type PageContextDebugRouteMatches } from './debugPageFiles.js';
8
8
  import type { GlobalContextServerInternal } from '../globalContext.js';
9
9
  import { type PageContextExecHookServer } from './execHookServer.js';
10
+ import type { PassToClient } from '../html/serializeContext.js';
10
11
  type PageContextExecuteHook = Omit<PageContextExecHookServer, keyof Awaited<ReturnType<typeof loadPageConfigsLazyServerSide>>>;
11
12
  type PageContext_loadPageConfigsLazyServerSide = PageContextGetPageAssets & PageContextDebugRouteMatches & {
12
13
  pageId: string;
@@ -17,7 +18,7 @@ type PageConfigsLazy = PromiseType<ReturnType<typeof loadPageConfigsLazyServerSi
17
18
  declare function loadPageConfigsLazyServerSideAndExecHook<PageContext extends PageContext_loadPageConfigsLazyServerSide & PageContextExecuteHook>(pageContext: PageContext): Promise<PageContext & VikeConfigPublicPageLazy & {
18
19
  Page: unknown;
19
20
  _isHtmlOnly: boolean;
20
- _passToClient: string[];
21
+ _passToClient: PassToClient;
21
22
  _pageFilePathsLoaded: string[];
22
23
  headersResponse: Headers;
23
24
  } & {
@@ -26,7 +27,7 @@ declare function loadPageConfigsLazyServerSideAndExecHook<PageContext extends Pa
26
27
  declare function loadPageConfigsLazyServerSide(pageContext: PageContext_loadPageConfigsLazyServerSide): Promise<VikeConfigPublicPageLazy & {
27
28
  Page: unknown;
28
29
  _isHtmlOnly: boolean;
29
- _passToClient: string[];
30
+ _passToClient: PassToClient;
30
31
  _pageFilePathsLoaded: string[];
31
32
  headersResponse: Headers;
32
33
  } & {
@@ -2,7 +2,7 @@ export { loadPageConfigsLazyServerSideAndExecHook };
2
2
  import { getPageFilesServerSide } from '../../../shared/getPageFiles.js';
3
3
  import { resolveVikeConfigPublicPageLazy } from '../../../shared/page-configs/resolveVikeConfigPublic.js';
4
4
  import { analyzePageClientSideInit } from '../../../shared/getPageFiles/analyzePageClientSide.js';
5
- import { assertUsage, assertWarning, hasProp, objectAssign, isArrayOfStrings } from '../utils.js';
5
+ import { assertUsage, assertWarning, hasProp, objectAssign } from '../utils.js';
6
6
  import { getPageAssets } from './getPageAssets.js';
7
7
  import { debugPageFiles } from './debugPageFiles.js';
8
8
  import { findPageConfig } from '../../../shared/page-configs/findPageConfig.js';
@@ -39,8 +39,9 @@ async function loadPageConfigsLazyServerSide(pageContext) {
39
39
  }
40
40
  else {
41
41
  configPublicPageLazy.from.configsCumulative.passToClient?.values.forEach((v) => {
42
- const { value, definedAt } = v;
43
- assertUsage(isArrayOfStrings(value), `+passToClient value defined at ${definedAt}${errMsg}`);
42
+ const { value } = v;
43
+ // const { definedAt } = v
44
+ // assertUsage(isArrayOfStrings(value), `+passToClient value defined at ${definedAt}${errMsg}`)
44
45
  passToClient.push(...value);
45
46
  });
46
47
  }
@@ -143,7 +143,7 @@ declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy
143
143
  } & import("../../../shared/getPageFiles.js").VikeConfigPublicPageLazy & {
144
144
  Page: unknown;
145
145
  _isHtmlOnly: boolean;
146
- _passToClient: string[];
146
+ _passToClient: import("../html/serializeContext.js").PassToClient;
147
147
  _pageFilePathsLoaded: string[];
148
148
  headersResponse: Headers;
149
149
  } & {
@@ -278,7 +278,7 @@ declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy
278
278
  } & import("../../../shared/getPageFiles.js").VikeConfigPublicPageLazy & {
279
279
  Page: unknown;
280
280
  _isHtmlOnly: boolean;
281
- _passToClient: string[];
281
+ _passToClient: import("../html/serializeContext.js").PassToClient;
282
282
  _pageFilePathsLoaded: string[];
283
283
  headersResponse: Headers;
284
284
  } & {
@@ -17,7 +17,9 @@ async function createGlobalContextShared(virtualFileExports, globalObject, addGl
17
17
  else {
18
18
  isNewGlobalContext = true;
19
19
  }
20
- if (addGlobalContextSync && globalContext._pageConfigs.length > 0) {
20
+ if (addGlobalContextSync &&
21
+ // TODO/next-major-release: remove
22
+ globalContext._pageConfigs.length > 0) {
21
23
  const globalContextAddendum = addGlobalContextSync?.(globalContext);
22
24
  objectAssign(globalContext, globalContextAddendum);
23
25
  }
@@ -44,6 +44,7 @@ import type { Vike, VikePackages } from './VikeNamespace.js';
44
44
  import type { HooksTimeoutProvidedByUser } from '../shared/hooks/getHook.js';
45
45
  import type { GlobalContext, PageContextClient, PageContextServer } from './PageContext.js';
46
46
  import type { InlineConfig } from 'vite';
47
+ import type { PassToClient } from '../node/runtime/html/serializeContext.js';
47
48
  type HookNameOld = HookName | HookNameOldDesign;
48
49
  type HookName = HookNamePage | HookNameGlobal;
49
50
  type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data' | 'onData' | 'route';
@@ -362,7 +363,7 @@ type ConfigBuiltIn = {
362
363
  *
363
364
  * https://vike.dev/passToClient
364
365
  */
365
- passToClient?: string[] | ImportString;
366
+ passToClient?: PassToClient | ImportString;
366
367
  /** Hook called when page is rendered on the client-side.
367
368
  *
368
369
  * https://vike.dev/onRenderClient
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.235-commit-9b9289b";
1
+ export declare const PROJECT_VERSION: "0.4.235-commit-d2ac38a";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.235-commit-9b9289b';
2
+ export const PROJECT_VERSION = '0.4.235-commit-d2ac38a';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.235-commit-9b9289b",
3
+ "version": "0.4.235-commit-d2ac38a",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {