vike-lite-react 1.0.10 → 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 -61
- 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,19 +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
|
-
if (!(e.target instanceof Element)) return;
|
|
42
|
-
const target = e.target.closest("a");
|
|
43
|
-
if (!target?.href || target.target === "_blank" || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) return;
|
|
44
|
-
const url = new URL(target.href);
|
|
45
|
-
if (url.origin !== globalThis.location.origin) return;
|
|
46
|
-
if (url.pathname === globalThis.location.pathname && url.search === globalThis.location.search) return;
|
|
47
|
-
e.preventDefault();
|
|
48
|
-
globalThis.history.pushState({ triggeredBy: "vike-lite" }, "", url.href);
|
|
41
|
+
const handleLinkClick = createLinkClickHandler((url) => {
|
|
49
42
|
if (!url.hash) shouldScrollToTop.current = true;
|
|
50
43
|
setCurrentUrl(url.href);
|
|
51
44
|
setCurrentPathname(stripBase(url.pathname));
|
|
52
|
-
};
|
|
45
|
+
});
|
|
53
46
|
const prefetchedModules = /* @__PURE__ */ new Set();
|
|
54
47
|
function prefetchRoute(route) {
|
|
55
48
|
const modules = [
|
|
@@ -65,19 +58,10 @@ function RouterApp(props) {
|
|
|
65
58
|
});
|
|
66
59
|
}
|
|
67
60
|
}
|
|
68
|
-
const handleLinkPrefetch = (
|
|
69
|
-
if (!(e.target instanceof Element)) return;
|
|
70
|
-
const target = e.target.closest("a");
|
|
71
|
-
if (!target?.href) return;
|
|
72
|
-
if (target.target && target.target !== "_self") return;
|
|
73
|
-
if (target.hasAttribute("download")) return;
|
|
74
|
-
const url = new URL(target.href);
|
|
75
|
-
if (url.origin !== globalThis.location.origin) return;
|
|
76
|
-
if (url.pathname === globalThis.location.pathname && url.search === globalThis.location.search) return;
|
|
61
|
+
const handleLinkPrefetch = createLinkPrefetchHandler((url) => {
|
|
77
62
|
const matched = matchRoute(stripBase(url.pathname), props.routes);
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
};
|
|
63
|
+
if (matched) prefetchRoute(matched.route);
|
|
64
|
+
});
|
|
81
65
|
const handlePopState = () => {
|
|
82
66
|
setCurrentUrl(globalThis.location.href);
|
|
83
67
|
setCurrentPathname(stripBase(globalThis.location.pathname));
|
|
@@ -112,7 +96,7 @@ function RouterApp(props) {
|
|
|
112
96
|
useEffect(() => {
|
|
113
97
|
const pathname = currentPathname;
|
|
114
98
|
const isReload = reloadTick > 0;
|
|
115
|
-
if (isFirstRun.current &&
|
|
99
|
+
if (!isReload && isFirstRun.current && globalThis.__PAGE_CONTEXT__?.urlPathname === pathname) {
|
|
116
100
|
isFirstRun.current = false;
|
|
117
101
|
globalThis.__PAGE_CONTEXT__.urlPathname = void 0;
|
|
118
102
|
return;
|
|
@@ -122,45 +106,36 @@ function RouterApp(props) {
|
|
|
122
106
|
const signal = controller.signal;
|
|
123
107
|
const urlFull = currentUrl;
|
|
124
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
|
+
};
|
|
125
136
|
const loadRoute = async () => {
|
|
126
137
|
const contextOverride = pendingContextOverride.current;
|
|
127
138
|
pendingContextOverride.current = null;
|
|
128
|
-
function finalizeNavigation() {
|
|
129
|
-
if (shouldScrollToTop.current) {
|
|
130
|
-
globalThis.scrollTo(0, 0);
|
|
131
|
-
shouldScrollToTop.current = false;
|
|
132
|
-
} else if (globalThis.location.hash) requestAnimationFrame(() => {
|
|
133
|
-
try {
|
|
134
|
-
document.querySelector(decodeURIComponent(globalThis.location.hash))?.scrollIntoView();
|
|
135
|
-
} catch {}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
const renderErrorPage = async (is404, message) => {
|
|
139
|
-
if (!props.errorRoute) return;
|
|
140
|
-
const [ErrorPageMod, ErrorLayoutMod, ErrorHeadMod] = await Promise.all([
|
|
141
|
-
props.errorRoute.Page(),
|
|
142
|
-
props.errorRoute.Layout?.() ?? null,
|
|
143
|
-
props.errorRoute.Head?.() ?? null
|
|
144
|
-
]);
|
|
145
|
-
if (signal.aborted) return;
|
|
146
|
-
setPageContext(() => ({
|
|
147
|
-
urlOriginal: urlFull,
|
|
148
|
-
urlPathname: pathname,
|
|
149
|
-
routeParams: {},
|
|
150
|
-
is404,
|
|
151
|
-
is500: !is404,
|
|
152
|
-
errorMessage: message,
|
|
153
|
-
isClientSide: true,
|
|
154
|
-
isHydration: false
|
|
155
|
-
}));
|
|
156
|
-
setView({
|
|
157
|
-
Page: ErrorPageMod.Page ?? ErrorPageMod.default,
|
|
158
|
-
Layout: ErrorLayoutMod?.Layout ?? ErrorLayoutMod?.default ?? null,
|
|
159
|
-
Head: ErrorHeadMod?.Head ?? ErrorHeadMod?.default ?? null
|
|
160
|
-
});
|
|
161
|
-
document.title = is404 ? "Not Found" : "Server Error";
|
|
162
|
-
finalizeNavigation();
|
|
163
|
-
};
|
|
164
139
|
if (!matched) return renderErrorPage(true);
|
|
165
140
|
const { route, routeParams } = matched;
|
|
166
141
|
try {
|
|
@@ -219,7 +194,7 @@ function RouterApp(props) {
|
|
|
219
194
|
if (globalThis.location.hash) return;
|
|
220
195
|
document.querySelector("#root")?.focus({ preventScroll: true });
|
|
221
196
|
});
|
|
222
|
-
finalizeNavigation();
|
|
197
|
+
finalizeNavigation(shouldScrollToTop.current);
|
|
223
198
|
} catch (error) {
|
|
224
199
|
if (error.name === "AbortError") return;
|
|
225
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 };
|