vike-lite-react 1.0.9 → 1.0.11
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/{PageContextProvider-C21BRCMp.mjs → PageContextProvider-DfE3nMiU.mjs} +1 -1
- package/dist/__internal/client/onRenderClient.mjs +36 -59
- package/dist/__internal/server/onRenderHtml.mjs +1 -1
- package/dist/globalContext-6JEqyfKe.mjs +6 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
- package/dist/globalContext-BIY5-Fdk.mjs +0 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PageContextReactContext } from "./globalContext-
|
|
1
|
+
import { t as PageContextReactContext } from "./globalContext-6JEqyfKe.mjs";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
//#region src/hooks/PageContextProvider.tsx
|
|
4
4
|
function PageContextProvider({ value, children }) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { t as PageContextProvider } from "../../PageContextProvider-
|
|
1
|
+
import { t as PageContextProvider } from "../../PageContextProvider-DfE3nMiU.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 } from "vike-lite/__internal/shared";
|
|
5
|
+
import { createLinkClickHandler, createLinkPrefetchHandler, finalizeNavigation } from "vike-lite/__internal/client";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
//#region src/__internal/shared/stripBase.ts
|
|
7
8
|
function stripBase(pathname) {
|
|
@@ -37,18 +38,11 @@ function RouterApp(props) {
|
|
|
37
38
|
}, []);
|
|
38
39
|
const matchedRoute = useMemo(() => matchRoute(currentPathname, props.routes), [currentPathname, props.routes]);
|
|
39
40
|
useEffect(() => {
|
|
40
|
-
const handleLinkClick = (
|
|
41
|
-
const target = e.target.closest("a");
|
|
42
|
-
if (!target?.href || target.target === "_blank" || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) return;
|
|
43
|
-
const url = new URL(target.href);
|
|
44
|
-
if (url.origin !== globalThis.location.origin) return;
|
|
45
|
-
if (url.pathname === globalThis.location.pathname && url.search === globalThis.location.search) return;
|
|
46
|
-
e.preventDefault();
|
|
47
|
-
globalThis.history.pushState({ triggeredBy: "vike-lite" }, "", url.href);
|
|
41
|
+
const handleLinkClick = createLinkClickHandler((url) => {
|
|
48
42
|
if (!url.hash) shouldScrollToTop.current = true;
|
|
49
43
|
setCurrentUrl(url.href);
|
|
50
44
|
setCurrentPathname(stripBase(url.pathname));
|
|
51
|
-
};
|
|
45
|
+
});
|
|
52
46
|
const prefetchedModules = /* @__PURE__ */ new Set();
|
|
53
47
|
function prefetchRoute(route) {
|
|
54
48
|
const modules = [
|
|
@@ -64,18 +58,10 @@ function RouterApp(props) {
|
|
|
64
58
|
});
|
|
65
59
|
}
|
|
66
60
|
}
|
|
67
|
-
const handleLinkPrefetch = (
|
|
68
|
-
const target = e.target.closest("a");
|
|
69
|
-
if (!target?.href) return;
|
|
70
|
-
if (target.target && target.target !== "_self") return;
|
|
71
|
-
if (target.hasAttribute("download")) return;
|
|
72
|
-
const url = new URL(target.href);
|
|
73
|
-
if (url.origin !== globalThis.location.origin) return;
|
|
74
|
-
if (url.pathname === globalThis.location.pathname && url.search === globalThis.location.search) return;
|
|
61
|
+
const handleLinkPrefetch = createLinkPrefetchHandler((url) => {
|
|
75
62
|
const matched = matchRoute(stripBase(url.pathname), props.routes);
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
};
|
|
63
|
+
if (matched) prefetchRoute(matched.route);
|
|
64
|
+
});
|
|
79
65
|
const handlePopState = () => {
|
|
80
66
|
setCurrentUrl(globalThis.location.href);
|
|
81
67
|
setCurrentPathname(stripBase(globalThis.location.pathname));
|
|
@@ -110,7 +96,7 @@ function RouterApp(props) {
|
|
|
110
96
|
useEffect(() => {
|
|
111
97
|
const pathname = currentPathname;
|
|
112
98
|
const isReload = reloadTick > 0;
|
|
113
|
-
if (isFirstRun.current &&
|
|
99
|
+
if (!isReload && isFirstRun.current && globalThis.__PAGE_CONTEXT__?.urlPathname === pathname) {
|
|
114
100
|
isFirstRun.current = false;
|
|
115
101
|
globalThis.__PAGE_CONTEXT__.urlPathname = void 0;
|
|
116
102
|
return;
|
|
@@ -120,45 +106,36 @@ function RouterApp(props) {
|
|
|
120
106
|
const signal = controller.signal;
|
|
121
107
|
const urlFull = currentUrl;
|
|
122
108
|
const matched = matchedRoute;
|
|
109
|
+
const renderErrorPage = async (is404, message) => {
|
|
110
|
+
if (!props.errorRoute) return;
|
|
111
|
+
const [ErrorPageMod, ErrorLayoutMod, ErrorHeadMod] = await Promise.all([
|
|
112
|
+
props.errorRoute.Page(),
|
|
113
|
+
props.errorRoute.Layout?.() ?? null,
|
|
114
|
+
props.errorRoute.Head?.() ?? null
|
|
115
|
+
]);
|
|
116
|
+
if (signal.aborted) return;
|
|
117
|
+
setPageContext(() => ({
|
|
118
|
+
...pageContext,
|
|
119
|
+
urlOriginal: urlFull,
|
|
120
|
+
urlPathname: pathname,
|
|
121
|
+
routeParams: {},
|
|
122
|
+
is404,
|
|
123
|
+
is500: !is404,
|
|
124
|
+
errorMessage: message,
|
|
125
|
+
isClientSide: true,
|
|
126
|
+
isHydration: false
|
|
127
|
+
}));
|
|
128
|
+
setView({
|
|
129
|
+
Page: ErrorPageMod.Page ?? ErrorPageMod.default,
|
|
130
|
+
Layout: ErrorLayoutMod?.Layout ?? ErrorLayoutMod?.default ?? null,
|
|
131
|
+
Head: ErrorHeadMod?.Head ?? ErrorHeadMod?.default ?? null
|
|
132
|
+
});
|
|
133
|
+
document.title = is404 ? "Not Found" : "Server Error";
|
|
134
|
+
finalizeNavigation(shouldScrollToTop.current);
|
|
135
|
+
};
|
|
123
136
|
const loadRoute = async () => {
|
|
124
137
|
const contextOverride = pendingContextOverride.current;
|
|
125
138
|
pendingContextOverride.current = null;
|
|
126
|
-
function finalizeNavigation() {
|
|
127
|
-
if (shouldScrollToTop.current) {
|
|
128
|
-
globalThis.scrollTo(0, 0);
|
|
129
|
-
shouldScrollToTop.current = false;
|
|
130
|
-
} else if (globalThis.location.hash) requestAnimationFrame(() => {
|
|
131
|
-
try {
|
|
132
|
-
document.querySelector(decodeURIComponent(globalThis.location.hash))?.scrollIntoView();
|
|
133
|
-
} catch {}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
const renderErrorPage = async (is404, message) => {
|
|
137
|
-
if (!props.errorRoute) return;
|
|
138
|
-
const [ErrorPageMod, ErrorLayoutMod, ErrorHeadMod] = await Promise.all([
|
|
139
|
-
props.errorRoute.Page(),
|
|
140
|
-
props.errorRoute.Layout?.() ?? null,
|
|
141
|
-
props.errorRoute.Head?.() ?? null
|
|
142
|
-
]);
|
|
143
|
-
if (signal.aborted) return;
|
|
144
|
-
setPageContext(() => ({
|
|
145
|
-
urlOriginal: urlFull,
|
|
146
|
-
urlPathname: pathname,
|
|
147
|
-
routeParams: {},
|
|
148
|
-
is404,
|
|
149
|
-
is500: !is404,
|
|
150
|
-
errorMessage: message,
|
|
151
|
-
isClientSide: true,
|
|
152
|
-
isHydration: false
|
|
153
|
-
}));
|
|
154
|
-
setView({
|
|
155
|
-
Page: ErrorPageMod.Page ?? ErrorPageMod.default,
|
|
156
|
-
Layout: ErrorLayoutMod?.Layout ?? ErrorLayoutMod?.default ?? null,
|
|
157
|
-
Head: ErrorHeadMod?.Head ?? ErrorHeadMod?.default ?? null
|
|
158
|
-
});
|
|
159
|
-
document.title = is404 ? "Not Found" : "Server Error";
|
|
160
|
-
finalizeNavigation();
|
|
161
|
-
};
|
|
162
139
|
if (!matched) return renderErrorPage(true);
|
|
163
140
|
const { route, routeParams } = matched;
|
|
164
141
|
try {
|
|
@@ -217,7 +194,7 @@ function RouterApp(props) {
|
|
|
217
194
|
if (globalThis.location.hash) return;
|
|
218
195
|
document.querySelector("#root")?.focus({ preventScroll: true });
|
|
219
196
|
});
|
|
220
|
-
finalizeNavigation();
|
|
197
|
+
finalizeNavigation(shouldScrollToTop.current);
|
|
221
198
|
} catch (error) {
|
|
222
199
|
if (error.name === "AbortError") return;
|
|
223
200
|
const message = error.message || "";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PageContextProvider } from "../../PageContextProvider-
|
|
1
|
+
import { t as PageContextProvider } from "../../PageContextProvider-DfE3nMiU.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
|
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PageContextReactContext } from "./globalContext-
|
|
1
|
+
import { t as PageContextReactContext } from "./globalContext-6JEqyfKe.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.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"@vitejs/plugin-react": "^6.0.3",
|
|
63
63
|
"react": "^19.2.7",
|
|
64
64
|
"react-dom": "^19.2.7",
|
|
65
|
-
"tsdown": "^0.22.
|
|
66
|
-
"vike-lite": "1.15.
|
|
65
|
+
"tsdown": "^0.22.9",
|
|
66
|
+
"vike-lite": "1.15.8",
|
|
67
67
|
"vite": "^8.1.5"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createContext } from "react";
|
|
2
|
-
//#region src/hooks/globalContext.tsx
|
|
3
|
-
const KEY = "__vike_lite_react_context__";
|
|
4
|
-
const g = globalThis;
|
|
5
|
-
if (!Object.hasOwn(g, KEY)) g[KEY] = createContext(null);
|
|
6
|
-
const PageContextReactContext = g[KEY];
|
|
7
|
-
//#endregion
|
|
8
|
-
export { PageContextReactContext as t };
|