vike-react 0.6.11 → 0.6.13

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.
@@ -1,3 +1,3 @@
1
1
  export { Config };
2
- import type { ConfigFromHook } from '../../types/Config.js';
3
- declare function Config(props: ConfigFromHook): null;
2
+ import type { ConfigViaHook } from '../../types/Config.js';
3
+ declare function Config(props: ConfigViaHook): null;
@@ -1,8 +1,8 @@
1
1
  export { Config };
2
- import type { ConfigFromHook } from '../../types/Config.js';
2
+ import type { ConfigViaHook } from '../../types/Config.js';
3
3
  /**
4
4
  * Set configurations inside React components.
5
5
  *
6
6
  * https://vike.dev/useConfig
7
7
  */
8
- declare function Config(props: ConfigFromHook): null;
8
+ declare function Config(props: ConfigViaHook): null;
package/dist/config.js CHANGED
@@ -5,7 +5,7 @@ const config = {
5
5
  // @eject-remove start
6
6
  name: 'vike-react',
7
7
  require: {
8
- vike: '>=0.4.182',
8
+ vike: '>=0.4.242',
9
9
  },
10
10
  Loading: 'import:vike-react/__internal/integration/Loading:default',
11
11
  // https://vike.dev/onRenderHtml
@@ -14,7 +14,7 @@ const config = {
14
14
  onRenderClient: 'import:vike-react/__internal/integration/onRenderClient:onRenderClient',
15
15
  // @eject-remove end
16
16
  passToClient: [
17
- '_configFromHook',
17
+ '_configViaHook',
18
18
  // https://github.com/vikejs/vike-react/issues/25
19
19
  process.env.NODE_ENV !== 'production' && '$$typeof',
20
20
  ].filter(isNotFalse),
@@ -1,12 +1,7 @@
1
1
  export { clientOnly };
2
2
  import React, { Suspense, forwardRef, lazy, useEffect, useState, } from 'react';
3
3
  function clientOnly(load) {
4
- var _a;
5
- // Client side: always bundled by Vite, import.meta.env.SSR === false
6
- // Server side: may or may not be bundled by Vite, import.meta.env.SSR === true || import.meta.env === undefined
7
- //@ts-expect-error
8
- (_a = import.meta).env ?? (_a.env = { SSR: true });
9
- if (import.meta.env.SSR) {
4
+ if (!globalThis.__VIKE__IS_CLIENT) {
10
5
  return (props) => React.createElement(React.Fragment, null, props.fallback);
11
6
  }
12
7
  else {
@@ -1,3 +1,3 @@
1
1
  export { useConfig };
2
- import type { ConfigFromHook } from '../../types/Config.js';
3
- declare function useConfig(): (config: ConfigFromHook) => void;
2
+ import type { ConfigViaHook } from '../../types/Config.js';
3
+ declare function useConfig(): (config: ConfigViaHook) => void;
@@ -6,21 +6,21 @@ function useConfig() {
6
6
  // Vike hook
7
7
  let pageContext = getPageContext();
8
8
  if (pageContext)
9
- return (config) => setPageContextConfigFromHook(config, pageContext);
9
+ return (config) => setPageContextConfigViaHook(config, pageContext);
10
10
  // Component
11
11
  pageContext = usePageContext();
12
12
  return (config) => {
13
13
  if (!('_headAlreadySet' in pageContext)) {
14
- setPageContextConfigFromHook(config, pageContext);
14
+ setPageContextConfigViaHook(config, pageContext);
15
15
  }
16
16
  else {
17
17
  applyHead(config);
18
18
  }
19
19
  };
20
20
  }
21
- function setPageContextConfigFromHook(config, pageContext) {
22
- pageContext._configFromHook ?? (pageContext._configFromHook = {});
23
- Object.assign(pageContext._configFromHook, config);
21
+ function setPageContextConfigViaHook(config, pageContext) {
22
+ pageContext._configViaHook ?? (pageContext._configViaHook = {});
23
+ Object.assign(pageContext._configViaHook, config);
24
24
  }
25
25
  function applyHead(config) {
26
26
  const { title, lang } = config;
@@ -1,8 +1,8 @@
1
1
  export { useConfig };
2
- import type { ConfigFromHook } from '../../types/Config.js';
2
+ import type { ConfigViaHook } from '../../types/Config.js';
3
3
  /**
4
4
  * Set configurations inside components and Vike hooks.
5
5
  *
6
6
  * https://vike.dev/useConfig
7
7
  */
8
- declare function useConfig(): (config: ConfigFromHook) => void;
8
+ declare function useConfig(): (config: ConfigViaHook) => void;
@@ -15,13 +15,13 @@ function useConfig() {
15
15
  // Vike hook
16
16
  let pageContext = getPageContext();
17
17
  if (pageContext)
18
- return (config) => setPageContextConfigFromHook(config, pageContext);
18
+ return (config) => setPageContextConfigViaHook(config, pageContext);
19
19
  // Component
20
20
  pageContext = usePageContext();
21
21
  const stream = useStreamOptional();
22
22
  return (config) => {
23
23
  if (!pageContext._headAlreadySet) {
24
- setPageContextConfigFromHook(config, pageContext);
24
+ setPageContextConfigViaHook(config, pageContext);
25
25
  }
26
26
  else {
27
27
  assert(stream);
@@ -31,8 +31,8 @@ function useConfig() {
31
31
  };
32
32
  }
33
33
  const configsClientSide = ['title'];
34
- function setPageContextConfigFromHook(config, pageContext) {
35
- pageContext._configFromHook ?? (pageContext._configFromHook = {});
34
+ function setPageContextConfigViaHook(config, pageContext) {
35
+ pageContext._configViaHook ?? (pageContext._configViaHook = {});
36
36
  objectKeys(config).forEach((configName) => {
37
37
  var _a;
38
38
  // Skip HTML only configs which the client-side doesn't need, saving KBs sent to the client as well as avoiding serialization errors.
@@ -43,15 +43,15 @@ function setPageContextConfigFromHook(config, pageContext) {
43
43
  const configValue = config[configName];
44
44
  if (configValue === undefined)
45
45
  return;
46
- pageContext._configFromHook[configName] = configValue;
46
+ pageContext._configViaHook[configName] = configValue;
47
47
  }
48
48
  else {
49
49
  // Cumulative config
50
50
  const configValue = config[configName];
51
51
  if (!configValue)
52
52
  return;
53
- (_a = pageContext._configFromHook)[configName] ?? (_a[configName] = []);
54
- pageContext._configFromHook[configName].push(configValue);
53
+ (_a = pageContext._configViaHook)[configName] ?? (_a[configName] = []);
54
+ pageContext._configViaHook[configName].push(configValue);
55
55
  }
56
56
  });
57
57
  }
@@ -1,5 +1,5 @@
1
1
  export { getHeadSetting };
2
2
  import type { PageContext } from 'vike/types';
3
3
  import type { PageContextInternal } from '../types/PageContext.js';
4
- import type { ConfigFromHookResolved } from '../types/Config.js';
5
- declare function getHeadSetting<T>(configName: keyof ConfigFromHookResolved, pageContext: PageContext & PageContextInternal): undefined | T;
4
+ import type { ConfigViaHookResolved } from '../types/Config.js';
5
+ declare function getHeadSetting<T>(configName: keyof ConfigViaHookResolved, pageContext: PageContext & PageContextInternal): undefined | T;
@@ -5,20 +5,20 @@ import { includes } from '../utils/includes.js';
5
5
  // We use `any` instead of doing proper validation in order to save KBs sent to the client-side.
6
6
  function getHeadSetting(configName, pageContext) {
7
7
  // Set by useConfig()
8
- const valFromUseConfig = pageContext._configFromHook?.[configName];
8
+ const valFromHook = pageContext._configViaHook?.[configName];
9
9
  // Set by +configName.js
10
10
  const valFromConfig = pageContext.config[configName];
11
11
  const getCallable = (val) => (isCallable(val) ? val(pageContext) : val);
12
12
  if (!includes(configsCumulative, configName)) {
13
- if (valFromUseConfig !== undefined)
14
- return valFromUseConfig;
13
+ if (valFromHook !== undefined)
14
+ return valFromHook;
15
15
  return getCallable(valFromConfig);
16
16
  }
17
17
  else {
18
18
  return [
19
19
  //
20
20
  ...(valFromConfig ?? []).map(getCallable),
21
- ...(valFromUseConfig ?? []),
21
+ ...(valFromHook ?? []),
22
22
  ];
23
23
  }
24
24
  }
@@ -22,7 +22,7 @@ async function onRenderHtml(pageContext) {
22
22
  const { headHtmlBegin, headHtmlEnd, bodyHtmlBegin, bodyHtmlEnd } = await getHtmlInjections(pageContext);
23
23
  const { htmlAttributesString, bodyAttributesString } = getTagAttributes(pageContext);
24
24
  // Not needed on the client-side, thus we remove it to save KBs sent to the client
25
- delete pageContext._configFromHook;
25
+ delete pageContext._configViaHook;
26
26
  // pageContext.{pageHtmlString,pageHtmlStream} is set by renderPageToHtml() and can be overridden by user at onAfterRenderHtml()
27
27
  let pageHtmlStringOrStream =
28
28
  // Set to empty string if SSR is disabled
@@ -109,7 +109,7 @@ function getHeadHtml(pageContext) {
109
109
  // Added by +Head
110
110
  ...(pageContext.config.Head ?? []),
111
111
  // Added by useConfig()
112
- ...(pageContext._configFromHook?.Head ?? []),
112
+ ...(pageContext._configViaHook?.Head ?? []),
113
113
  ]
114
114
  .filter((Head) => Head !== null && Head !== undefined)
115
115
  .map((Head) => getHeadElementHtml(Head, pageContext))
@@ -259,8 +259,8 @@ type Loading = {
259
259
  type PickWithoutGetter<T, K extends keyof T> = {
260
260
  [P in K]: Exclude<T[P], Function>;
261
261
  };
262
- export type ConfigFromHook = PickWithoutGetter<Vike.Config, 'Head' | 'title' | 'description' | 'image' | 'favicon' | 'lang' | 'viewport' | 'bodyAttributes' | 'htmlAttributes'>;
263
- export type ConfigFromHookResolved = Omit<ConfigFromHook, ConfigsCumulative> & Pick<Vike.ConfigResolved, ConfigsCumulative>;
262
+ export type ConfigViaHook = PickWithoutGetter<Vike.Config, 'Head' | 'title' | 'description' | 'image' | 'favicon' | 'lang' | 'viewport' | 'bodyAttributes' | 'htmlAttributes'>;
263
+ export type ConfigViaHookResolved = Omit<ConfigViaHook, ConfigsCumulative> & Pick<Vike.ConfigResolved, ConfigsCumulative>;
264
264
  export type ReactOptions = {
265
265
  hydrateRootOptions?: HydrationOptions;
266
266
  createRootOptions?: RootOptions;
@@ -1,6 +1,6 @@
1
1
  import type React from 'react';
2
2
  import type ReactDOM from 'react-dom/client';
3
- import type { ConfigFromHookResolved } from './Config.js';
3
+ import type { ConfigViaHookResolved } from './Config.js';
4
4
  import type { PageHtmlStream } from '../integration/onRenderHtml.js';
5
5
  declare global {
6
6
  namespace Vike {
@@ -19,6 +19,6 @@ declare global {
19
19
  }
20
20
  }
21
21
  export type PageContextInternal = {
22
- _configFromHook?: ConfigFromHookResolved;
22
+ _configViaHook?: ConfigViaHookResolved;
23
23
  _headAlreadySet?: boolean;
24
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-react",
3
- "version": "0.6.11",
3
+ "version": "0.6.13",
4
4
  "repository": "https://github.com/vikejs/vike-react",
5
5
  "type": "module",
6
6
  "exports": {
@@ -32,7 +32,7 @@
32
32
  "peerDependencies": {
33
33
  "react": ">=19",
34
34
  "react-dom": ">=19",
35
- "vike": ">=0.4.182"
35
+ "vike": ">=0.4.242"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@biomejs/biome": "^1.9.4",