eddev 2.0.0-beta.85 → 2.0.0-beta.86
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/app/lib/routing/components/BrowserRouter.js +16 -8
- package/dist/app/lib/routing/components/Link.js +1 -1
- package/dist/app/lib/routing/components/ScrollRestoration.js +4 -1
- package/dist/app/lib/routing/loader.js +5 -1
- package/dist/app/lib/routing/types.d.ts +1 -1
- package/dist/app/lib/routing/utils.d.ts +1 -1
- package/dist/app/lib/routing/utils.js +17 -2
- package/dist/app/server/render-ssr-page.d.ts +1 -0
- package/dist/app/server/render-ssr-page.js +16 -8
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/vinxi-app.js +0 -2
- package/package.json +1 -1
|
@@ -133,7 +133,6 @@ export function BrowserRouter(props) {
|
|
|
133
133
|
}
|
|
134
134
|
internals.poppedState = (href, data) => {
|
|
135
135
|
const stack = state.history;
|
|
136
|
-
// console.log("Popped state", stack)
|
|
137
136
|
// Is the route in our history stack? (going back)
|
|
138
137
|
const index = stack.findIndex((item) => item.id === data.id);
|
|
139
138
|
if (index >= 0) {
|
|
@@ -199,11 +198,20 @@ export function BrowserRouter(props) {
|
|
|
199
198
|
});
|
|
200
199
|
if (cancelled)
|
|
201
200
|
return;
|
|
202
|
-
const data = await loader.loadRouteData(parseHrefPath(args.url))
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
201
|
+
const data = await loader.loadRouteData(parseHrefPath(args.url)).catch((err) => {
|
|
202
|
+
emitEvent({ type: "error", error: err, critical: true });
|
|
203
|
+
return {
|
|
204
|
+
view: "_error",
|
|
205
|
+
viewType: "react",
|
|
206
|
+
appData: loader.appData,
|
|
207
|
+
viewData: {
|
|
208
|
+
data: {
|
|
209
|
+
code: 500,
|
|
210
|
+
error: err,
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
});
|
|
207
215
|
const lazyComponent = loader.getRouteComponent(data.view);
|
|
208
216
|
if (!lazyComponent) {
|
|
209
217
|
console.error(`No component found for view: ${data.view}`);
|
|
@@ -289,7 +297,7 @@ export function BrowserRouter(props) {
|
|
|
289
297
|
if (loader.hasRouteData(link.pathname))
|
|
290
298
|
return;
|
|
291
299
|
emitEvent({ type: "preload:start", currentRoute: getActiveRoute(), link });
|
|
292
|
-
|
|
300
|
+
await loader.loadRouteData(link.pathname).then((data) => {
|
|
293
301
|
emitEvent({ type: "preload:data-ready", currentRoute: getActiveRoute(), link, data });
|
|
294
302
|
});
|
|
295
303
|
}
|
|
@@ -322,7 +330,7 @@ export function BrowserRouter(props) {
|
|
|
322
330
|
};
|
|
323
331
|
},
|
|
324
332
|
handleClickEvent(e, originalHref, preferBack) {
|
|
325
|
-
const { mode, href } = getLinkHandlerMode(e, originalHref);
|
|
333
|
+
const { mode, href } = getLinkHandlerMode(e, originalHref, state.activeRoute);
|
|
326
334
|
if (mode === "ignore") {
|
|
327
335
|
e.preventDefault();
|
|
328
336
|
return;
|
|
@@ -17,7 +17,7 @@ export const Link = forwardRef(({ preferBack, as, ...props }, ref) => {
|
|
|
17
17
|
else {
|
|
18
18
|
const router = useRouter();
|
|
19
19
|
const state = useLinkState(props.href ?? "");
|
|
20
|
-
return (_jsx(Comp, { ref: ref, "data-active": state.active ?? undefined, "data-child-active": state.childActive ?? undefined, "data-pending": state.pending ?? undefined, ...props, href: withTrailingSlash(props.href ?? undefined), onMouseEnter: (e) => {
|
|
20
|
+
return (_jsx(Comp, { ref: ref, "data-active": state.active ?? undefined, "data-child-active": state.childActive ?? undefined, "data-pending": state.pending ?? undefined, ...props, href: withTrailingSlash(props.href ?? undefined, true), onMouseEnter: (e) => {
|
|
21
21
|
if (props.onMouseEnter) {
|
|
22
22
|
props.onMouseEnter(e);
|
|
23
23
|
}
|
|
@@ -11,7 +11,10 @@ export function ScrollRestoration(props) {
|
|
|
11
11
|
}));
|
|
12
12
|
useRouterEvents((event) => {
|
|
13
13
|
if (event.type === "navigate:changed") {
|
|
14
|
-
//
|
|
14
|
+
// If the pathname and search term are the same, then we're on the same page
|
|
15
|
+
const isSameRoute = event.currentRoute.pathname === event.lastRoute.pathname && event.currentRoute.search === event.lastRoute.search;
|
|
16
|
+
if (isSameRoute)
|
|
17
|
+
return;
|
|
15
18
|
if (event.currentRoute.returnState) {
|
|
16
19
|
restore({
|
|
17
20
|
top: event.currentRoute.returnState.scrollTop ?? 0,
|
|
@@ -76,7 +76,11 @@ export class RouteLoader {
|
|
|
76
76
|
text = this.processProps(text);
|
|
77
77
|
}
|
|
78
78
|
try {
|
|
79
|
-
|
|
79
|
+
const payload = JSON.parse(text);
|
|
80
|
+
if (!payload.view) {
|
|
81
|
+
throw new RouteError(`Invalid route data for '${pathname}'`, 500);
|
|
82
|
+
}
|
|
83
|
+
return payload;
|
|
80
84
|
}
|
|
81
85
|
catch (err) {
|
|
82
86
|
throw new RouteError(`JSON parse error for route '${pathname}':\n${err?.message}`, 500);
|
|
@@ -7,7 +7,7 @@ export type LinkHandlerMode = {
|
|
|
7
7
|
mode: "ignore" | "navigate" | "native";
|
|
8
8
|
href?: string;
|
|
9
9
|
};
|
|
10
|
-
export declare function getLinkHandlerMode(e?: PointerOrMouseEvent, href?: string): LinkHandlerMode;
|
|
10
|
+
export declare function getLinkHandlerMode(e?: PointerOrMouseEvent, href?: string, currentRoute?: RouteState): LinkHandlerMode;
|
|
11
11
|
type Partialize<T, TKeys extends keyof T> = Partial<Pick<T, TKeys>> & Omit<T, TKeys>;
|
|
12
12
|
export declare function normalizeRoute(route: Partialize<RouteState, "uri" | "returnState" | "key">): RouteState;
|
|
13
13
|
export declare function stringifyRouteLink(route: RouteLink): string;
|
|
@@ -15,7 +15,7 @@ export function isSamePathname(a, b) {
|
|
|
15
15
|
const right = parseURL(b).pathname.replace(/\/$/, "").toLocaleLowerCase();
|
|
16
16
|
return left === right;
|
|
17
17
|
}
|
|
18
|
-
export function getLinkHandlerMode(e, href) {
|
|
18
|
+
export function getLinkHandlerMode(e, href, currentRoute) {
|
|
19
19
|
try {
|
|
20
20
|
// Attempt to get the link element, if there is one
|
|
21
21
|
let eventTarget = null;
|
|
@@ -36,7 +36,11 @@ export function getLinkHandlerMode(e, href) {
|
|
|
36
36
|
if (!href)
|
|
37
37
|
return { mode: "native", href };
|
|
38
38
|
// Resolve the URL and check if it's the same origin
|
|
39
|
-
const resolved = href.startsWith("http")
|
|
39
|
+
const resolved = href.startsWith("http")
|
|
40
|
+
? href
|
|
41
|
+
: href.startsWith("/")
|
|
42
|
+
? resolveURL(document.location.origin, href)
|
|
43
|
+
: resolveURL(document.location.href, href);
|
|
40
44
|
const parsed = parseURL(resolved);
|
|
41
45
|
const isSameOrigin = parsed.host?.replace(/:.+/, "") === document.location.host.replace(/:.+/, "");
|
|
42
46
|
// External links should be handled natively
|
|
@@ -57,6 +61,17 @@ export function getLinkHandlerMode(e, href) {
|
|
|
57
61
|
// Starts with /wp-, use native (wp-content, wp-admin etc)
|
|
58
62
|
if (parsed.pathname.startsWith("/wp-"))
|
|
59
63
|
return { mode: "native", href };
|
|
64
|
+
// If pathname+query are identical, but the hash is different, then allow the browser to handle it
|
|
65
|
+
if (currentRoute &&
|
|
66
|
+
isSamePathname(currentRoute.pathname, parsed.pathname) &&
|
|
67
|
+
currentRoute.search === parsed.search) {
|
|
68
|
+
if (currentRoute.hash !== parsed.hash) {
|
|
69
|
+
return { mode: "native", href };
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return { mode: "ignore", href };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
60
75
|
return { mode: "navigate", href };
|
|
61
76
|
}
|
|
62
77
|
catch (err) {
|
|
@@ -68,15 +68,14 @@ export async function renderPage(args) {
|
|
|
68
68
|
responseInit.status = response.status;
|
|
69
69
|
}
|
|
70
70
|
catch (err) {
|
|
71
|
-
data = {
|
|
72
|
-
view: "_error",
|
|
73
|
-
viewType: "react",
|
|
74
|
-
viewData: {},
|
|
75
|
-
appData: appData,
|
|
76
|
-
trackers: trackers,
|
|
77
|
-
};
|
|
78
71
|
console.error(err);
|
|
79
|
-
|
|
72
|
+
return renderErrorPage({
|
|
73
|
+
pathname: args.pathname,
|
|
74
|
+
code: 500,
|
|
75
|
+
newOrigin: args.newOrigin,
|
|
76
|
+
realError: err,
|
|
77
|
+
title: "Internal Server Error",
|
|
78
|
+
});
|
|
80
79
|
}
|
|
81
80
|
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
82
81
|
const stream = await getSsrStream({
|
|
@@ -87,6 +86,15 @@ export async function renderPage(args) {
|
|
|
87
86
|
}
|
|
88
87
|
catch (err) {
|
|
89
88
|
console.error(err);
|
|
89
|
+
if (args.statusCode !== 500) {
|
|
90
|
+
return renderErrorPage({
|
|
91
|
+
pathname: args.pathname,
|
|
92
|
+
code: 500,
|
|
93
|
+
newOrigin: args.newOrigin,
|
|
94
|
+
realError: err,
|
|
95
|
+
title: "Internal Server Error",
|
|
96
|
+
});
|
|
97
|
+
}
|
|
90
98
|
return new Response('<!DOCTYPE html><html><head><title>500 Internal Server Error</title></head><body><h1>500 Internal Server Error</h1><p>"' +
|
|
91
99
|
String(err) +
|
|
92
100
|
'"</p></body></html>', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.86";
|
package/dist/node/cli/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "2.0.0-beta.
|
|
1
|
+
export const VERSION = "2.0.0-beta.86";
|