vike-lite-react 1.0.15 → 1.0.17

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,6 +1,6 @@
1
- import { t as PageContextReactContext } from "./globalContext-6JEqyfKe.mjs";
1
+ import { t as PageContextReactContext } from "./globalContext-CuAgMUAs.mjs";
2
2
  import { jsx } from "react/jsx-runtime";
3
- //#region src/hooks/PageContextProvider.tsx
3
+ //#region src/__internal/shared/PageContextProvider.tsx
4
4
  function PageContextProvider({ value, children }) {
5
5
  return /* @__PURE__ */ jsx(PageContextReactContext.Provider, {
6
6
  value,
@@ -1,8 +1,8 @@
1
- import { t as PageContextProvider } from "../../PageContextProvider-DfE3nMiU.mjs";
1
+ import { t as PageContextProvider } from "../../PageContextProvider-CTiW2Vsa.mjs";
2
2
  import { Component, useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { createRoot, hydrateRoot } from "react-dom/client";
4
4
  import { matchRoute, stripBase } from "vike-lite/__internal/shared";
5
- import { buildPageContextJsonUrl, createLinkClickHandler, createLinkPrefetchHandler, createRoutePrefetcher, fetchPageContextJson, finalizeNavigation, loadViewModules, tryRecoverFromStaleModuleGraph } from "vike-lite/__internal/client";
5
+ import { buildInitialClientContext, buildPageContextJsonUrl, consumeMatchingInitialContext, createLinkClickHandler, createLinkPrefetchHandler, createRoutePrefetcher, fetchPageContextJson, finalizeNavigation, loadViewModules, resolveHydrationView, tryRecoverFromStaleModuleGraph } from "vike-lite/__internal/client";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
7
  //#region src/__internal/client/onRenderClient.tsx
8
8
  var RootErrorBoundary = class extends Component {
@@ -74,9 +74,8 @@ function RouterApp(props) {
74
74
  useEffect(() => {
75
75
  const pathname = currentPathname;
76
76
  const isReload = reloadTick > 0;
77
- if (!isReload && isFirstRun.current && globalThis.__PAGE_CONTEXT__?.urlPathname === pathname) {
77
+ if (!isReload && isFirstRun.current && consumeMatchingInitialContext(pathname)) {
78
78
  isFirstRun.current = false;
79
- globalThis.__PAGE_CONTEXT__.urlPathname = void 0;
80
79
  return;
81
80
  }
82
81
  isFirstRun.current = false;
@@ -101,7 +100,7 @@ function RouterApp(props) {
101
100
  }));
102
101
  setView(errorView);
103
102
  document.title = is404 ? "Not Found" : "Server Error";
104
- finalizeNavigation(shouldScrollToTop.current);
103
+ finalizeNavigation(shouldScrollToTop);
105
104
  };
106
105
  const loadRoute = async () => {
107
106
  const contextOverride = pendingContextOverride.current;
@@ -148,7 +147,7 @@ function RouterApp(props) {
148
147
  if (globalThis.location.hash) return;
149
148
  document.querySelector("#root")?.focus({ preventScroll: true });
150
149
  });
151
- finalizeNavigation(shouldScrollToTop.current);
150
+ finalizeNavigation(shouldScrollToTop);
152
151
  } catch (error) {
153
152
  if (error.name === "AbortError") return;
154
153
  const message = error.message || "";
@@ -181,22 +180,9 @@ function RouterApp(props) {
181
180
  }
182
181
  async function onRenderClient(clientOptions) {
183
182
  const container = document.querySelector("#root");
184
- const rawContext = globalThis.__PAGE_CONTEXT__ ?? {};
185
183
  const isHydration = clientOptions.hydration && !!globalThis.__PAGE_CONTEXT__;
186
- const initialContext = {
187
- ...rawContext,
188
- isClientSide: true,
189
- isHydration
190
- };
191
- let initialView = {
192
- Page: null,
193
- Layout: null,
194
- Head: null
195
- };
196
- if (isHydration) {
197
- const matched = matchRoute(initialContext.urlPathname ?? globalThis.location.pathname, clientOptions.routes);
198
- if (matched) initialView = await loadViewModules(matched.route);
199
- }
184
+ const initialContext = buildInitialClientContext(globalThis.__PAGE_CONTEXT__, isHydration);
185
+ const initialView = await resolveHydrationView(initialContext, isHydration, clientOptions.routes, clientOptions.errorRoute);
200
186
  const app = /* @__PURE__ */ jsx(RouterApp, {
201
187
  ...clientOptions,
202
188
  initialView,
@@ -9,6 +9,6 @@ interface ReactRenderContext extends RenderContext {
9
9
  }>;
10
10
  hydration: boolean;
11
11
  }
12
- declare function onRenderHtml({ pageContext, Page, Head, Layout, pageTitleTag, serializedContext, assets, hydration }: ReactRenderContext): string;
12
+ declare function onRenderHtml({ pageContext, Page, Head, Layout, pageTitleTag, serializedContext, assets, hydration, nonce }: ReactRenderContext): string;
13
13
  //#endregion
14
14
  export { ReactRenderContext, onRenderHtml };
@@ -1,9 +1,10 @@
1
- import { t as PageContextProvider } from "../../PageContextProvider-DfE3nMiU.mjs";
1
+ import { t as PageContextProvider } from "../../PageContextProvider-CTiW2Vsa.mjs";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { renderToString } from "react-dom/server";
4
4
  //#region src/__internal/server/onRenderHtml.tsx
5
- function onRenderHtml({ pageContext, Page, Head, Layout, pageTitleTag, serializedContext, assets, hydration }) {
5
+ function onRenderHtml({ pageContext, Page, Head, Layout, pageTitleTag, serializedContext, assets, hydration, nonce }) {
6
6
  const { cssLinks, jsPreloads, entryClient } = assets;
7
+ const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
7
8
  const providerValue = {
8
9
  pageContext,
9
10
  setPageContext: () => {}
@@ -20,14 +21,14 @@ ${Head ? renderToString(/* @__PURE__ */ jsx(PageContextProvider, {
20
21
  value: providerValue,
21
22
  children: /* @__PURE__ */ jsx(Head, {})
22
23
  })) : ""}
23
- <script>window.__PAGE_CONTEXT__=${serializedContext}<\/script>
24
+ <script${nonceAttr}>window.__PAGE_CONTEXT__=${serializedContext}<\/script>
24
25
  </head>
25
26
  <body>
26
27
  <div id="root" tabindex="-1">${hydration ? renderToString(/* @__PURE__ */ jsx(PageContextProvider, {
27
28
  value: providerValue,
28
29
  children: Layout ? /* @__PURE__ */ jsx(Layout, { children: /* @__PURE__ */ jsx(Page, {}) }) : /* @__PURE__ */ jsx(Page, {})
29
30
  })) : ""}</div>
30
- <script type="module" src="${entryClient}"><\/script>
31
+ <script type="module" src="${entryClient}"${nonceAttr}><\/script>
31
32
  </body>
32
33
  </html>`;
33
34
  }
@@ -1,5 +1,5 @@
1
1
  import { createContext } from "react";
2
- //#region src/hooks/globalContext.tsx
2
+ //#region src/shared/globalContext.tsx
3
3
  const KEY = Symbol.for("vike-lite-react:context");
4
4
  const PageContextReactContext = globalThis[KEY] ??= createContext(null);
5
5
  //#endregion
package/dist/index.d.mts CHANGED
@@ -12,7 +12,7 @@ declare function useHydrated(): boolean;
12
12
  //#region src/hooks/useUrl.d.ts
13
13
  declare function useUrl(): URL;
14
14
  //#endregion
15
- //#region src/hooks/globalContext.d.ts
15
+ //#region src/shared/globalContext.d.ts
16
16
  interface PageContextValue {
17
17
  pageContext: PageContextClient;
18
18
  setPageContext: (updater: (prev: PageContextClient) => PageContextClient) => void;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PageContextReactContext } from "./globalContext-6JEqyfKe.mjs";
1
+ import { t as PageContextReactContext } from "./globalContext-CuAgMUAs.mjs";
2
2
  import { useCallback, useContext, useEffect, useMemo, useState } from "react";
3
3
  //#region src/hooks/useData.tsx
4
4
  function useData() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite-react",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -56,15 +56,20 @@
56
56
  "build": "tsdown"
57
57
  },
58
58
  "devDependencies": {
59
+ "@testing-library/dom": "^10.4.1",
60
+ "@testing-library/jest-dom": "^6.9.1",
61
+ "@testing-library/react": "^16.3.2",
59
62
  "@types/node": "^26.1.1",
60
63
  "@types/react": "^19.2.17",
61
64
  "@types/react-dom": "^19.2.3",
62
65
  "@vitejs/plugin-react": "^6.0.3",
66
+ "jsdom": "^29.1.1",
63
67
  "react": "^19.2.7",
64
68
  "react-dom": "^19.2.7",
65
69
  "tsdown": "^0.22.9",
66
- "vike-lite": "1.15.13",
67
- "vite": "^8.1.5"
70
+ "vike-lite": "1.15.15",
71
+ "vite": "^8.1.5",
72
+ "vitest": "^4.1.10"
68
73
  },
69
74
  "peerDependencies": {
70
75
  "@vitejs/plugin-react": ">=6",