@modern-js/runtime 2.10.0 → 2.11.0
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/CHANGELOG.md +27 -0
- package/dist/cjs/core/compatible.js +7 -3
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +1 -1
- package/dist/cjs/router/runtime/PrefetchLink.js +205 -0
- package/dist/cjs/router/runtime/index.js +6 -1
- package/dist/cjs/router/runtime/plugin.js +12 -1
- package/dist/cjs/router/runtime/plugin.node.js +7 -2
- package/dist/cjs/router/runtime/utils.js +19 -9
- package/dist/cjs/ssr/index.js +3 -0
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +1 -1
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +2 -2
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +1 -1
- package/dist/esm/core/compatible.js +3 -2
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +1 -1
- package/dist/esm/router/runtime/PrefetchLink.js +446 -0
- package/dist/esm/router/runtime/index.js +3 -2
- package/dist/esm/router/runtime/plugin.js +10 -1
- package/dist/esm/router/runtime/plugin.node.js +5 -2
- package/dist/esm/router/runtime/utils.js +12 -9
- package/dist/esm/ssr/index.js +3 -0
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +2 -2
- package/dist/esm/ssr/serverRender/renderToString/entry.js +1 -1
- package/dist/esm-node/core/compatible.js +7 -3
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +1 -1
- package/dist/esm-node/router/runtime/PrefetchLink.js +177 -0
- package/dist/esm-node/router/runtime/index.js +4 -1
- package/dist/esm-node/router/runtime/plugin.js +12 -1
- package/dist/esm-node/router/runtime/plugin.node.js +7 -2
- package/dist/esm-node/router/runtime/utils.js +19 -9
- package/dist/esm-node/ssr/index.js +3 -0
- package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +2 -2
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +1 -1
- package/dist/types/router/runtime/PrefetchLink.d.ts +30 -0
- package/dist/types/router/runtime/index.d.ts +3 -1
- package/dist/types/router/runtime/types.d.ts +10 -1
- package/dist/types/router/runtime/utils.d.ts +13 -3
- package/dist/types/runtimeContext.d.ts +3 -1
- package/package.json +9 -9
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useContext, useMemo } from "react";
|
|
3
|
+
import {
|
|
4
|
+
Link as RouterLink,
|
|
5
|
+
matchRoutes,
|
|
6
|
+
useResolvedPath,
|
|
7
|
+
useHref,
|
|
8
|
+
useMatches,
|
|
9
|
+
NavLink as RouterNavLink
|
|
10
|
+
} from "react-router-dom";
|
|
11
|
+
import { RuntimeReactContext } from "../../core";
|
|
12
|
+
function composeEventHandlers(theirHandler, ourHandler) {
|
|
13
|
+
return (event) => {
|
|
14
|
+
theirHandler == null ? void 0 : theirHandler(event);
|
|
15
|
+
if (!event.defaultPrevented) {
|
|
16
|
+
ourHandler(event);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
|
21
|
+
function usePrefetchBehavior(prefetch, theirElementProps) {
|
|
22
|
+
const [maybePrefetch, setMaybePrefetch] = React.useState(false);
|
|
23
|
+
const [shouldPrefetch, setShouldPrefetch] = React.useState(false);
|
|
24
|
+
const { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
|
|
25
|
+
React.useEffect(() => {
|
|
26
|
+
if (prefetch === "render") {
|
|
27
|
+
setShouldPrefetch(true);
|
|
28
|
+
}
|
|
29
|
+
}, [prefetch]);
|
|
30
|
+
const setIntent = () => {
|
|
31
|
+
if (prefetch === "intent") {
|
|
32
|
+
setMaybePrefetch(true);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const cancelIntent = () => {
|
|
36
|
+
if (prefetch === "intent") {
|
|
37
|
+
setMaybePrefetch(false);
|
|
38
|
+
setShouldPrefetch(false);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
if (maybePrefetch) {
|
|
43
|
+
const id = setTimeout(() => {
|
|
44
|
+
setShouldPrefetch(true);
|
|
45
|
+
}, 100);
|
|
46
|
+
return () => {
|
|
47
|
+
clearTimeout(id);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}, [maybePrefetch]);
|
|
51
|
+
return [
|
|
52
|
+
shouldPrefetch,
|
|
53
|
+
{
|
|
54
|
+
onFocus: composeEventHandlers(onFocus, setIntent),
|
|
55
|
+
onBlur: composeEventHandlers(onBlur, cancelIntent),
|
|
56
|
+
onMouseEnter: composeEventHandlers(onMouseEnter, setIntent),
|
|
57
|
+
onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
|
|
58
|
+
onTouchStart: composeEventHandlers(onTouchStart, setIntent)
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
async function loadRouteModule(route, routeAssets) {
|
|
63
|
+
const routeId = route.id;
|
|
64
|
+
if (!routeId) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!routeAssets[routeId]) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const { chunkIds } = routeAssets[routeId];
|
|
71
|
+
if (!chunkIds) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
await Promise.all(
|
|
76
|
+
chunkIds.map((chunkId) => {
|
|
77
|
+
return __webpack_chunk_load__ == null ? void 0 : __webpack_chunk_load__(String(chunkId));
|
|
78
|
+
})
|
|
79
|
+
);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const getRequestUrl = (pathname, routeId) => {
|
|
85
|
+
const LOADER_ID_PARAM = "__loader";
|
|
86
|
+
const DIRECT_PARAM = "__ssrDirect";
|
|
87
|
+
const { protocol, host } = window.location;
|
|
88
|
+
const url = new URL(pathname, `${protocol}//${host}`);
|
|
89
|
+
url.searchParams.append(LOADER_ID_PARAM, routeId);
|
|
90
|
+
url.searchParams.append(DIRECT_PARAM, "true");
|
|
91
|
+
return url;
|
|
92
|
+
};
|
|
93
|
+
const createDataHref = (href) => {
|
|
94
|
+
return /* @__PURE__ */ jsx("link", { rel: "prefetch", as: "fetch", href }, href);
|
|
95
|
+
};
|
|
96
|
+
const getDataHref = (route, pathname, basename) => {
|
|
97
|
+
const { id } = route;
|
|
98
|
+
const path = basename === "/" ? pathname : `${basename}${pathname}`;
|
|
99
|
+
const url = getRequestUrl(path, id);
|
|
100
|
+
return createDataHref(url.toString());
|
|
101
|
+
};
|
|
102
|
+
const PrefetchPageLinks = ({ pathname }) => {
|
|
103
|
+
const context = useContext(RuntimeReactContext);
|
|
104
|
+
const { routeManifest, routes } = context;
|
|
105
|
+
const { routeAssets } = routeManifest;
|
|
106
|
+
const matches = Array.isArray(routes) ? matchRoutes(routes, pathname) : [];
|
|
107
|
+
if (Array.isArray(matches)) {
|
|
108
|
+
matches == null ? void 0 : matches.forEach((match) => loadRouteModule(match.route, routeAssets));
|
|
109
|
+
}
|
|
110
|
+
if (!window._SSR_DATA) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return /* @__PURE__ */ jsx(
|
|
114
|
+
PrefetchDataLinks,
|
|
115
|
+
{
|
|
116
|
+
matches,
|
|
117
|
+
pathname,
|
|
118
|
+
routeManifest
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
const PrefetchDataLinks = ({ matches, pathname, routeManifest }) => {
|
|
123
|
+
const currentMatches = useMatches();
|
|
124
|
+
const basename = useHref("/");
|
|
125
|
+
const dataHrefs = useMemo(() => {
|
|
126
|
+
return matches == null ? void 0 : matches.filter(
|
|
127
|
+
(match) => match.route.loader && typeof match.route.loader === "function" && match.route.loader.length > 0
|
|
128
|
+
).filter((match, index) => {
|
|
129
|
+
const currentMatch = currentMatches[index];
|
|
130
|
+
if (!currentMatch || currentMatch.id !== match.route.id) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
if (currentMatch.pathname !== match.pathname) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if (currentMatch.pathname.endsWith("*") && currentMatch.params["*"] !== match.params["*"]) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
}).map((match) => getDataHref(match.route, pathname, basename));
|
|
141
|
+
}, [matches, pathname, routeManifest]);
|
|
142
|
+
return /* @__PURE__ */ jsx(Fragment, { children: dataHrefs });
|
|
143
|
+
};
|
|
144
|
+
const createPrefetchLink = (Link2) => {
|
|
145
|
+
return React.forwardRef(
|
|
146
|
+
({ to, prefetch = "none", ...props }, forwardedRef) => {
|
|
147
|
+
const isAbsolute = typeof to === "string" && ABSOLUTE_URL_REGEX.test(to);
|
|
148
|
+
const [shouldPrefetch, prefetchHandlers] = usePrefetchBehavior(
|
|
149
|
+
prefetch,
|
|
150
|
+
props
|
|
151
|
+
);
|
|
152
|
+
const resolvedPath = useResolvedPath(to);
|
|
153
|
+
const { pathname } = resolvedPath;
|
|
154
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
155
|
+
/* @__PURE__ */ jsx(
|
|
156
|
+
Link2,
|
|
157
|
+
{
|
|
158
|
+
ref: forwardedRef,
|
|
159
|
+
to,
|
|
160
|
+
...props,
|
|
161
|
+
...prefetchHandlers
|
|
162
|
+
}
|
|
163
|
+
),
|
|
164
|
+
shouldPrefetch && __webpack_chunk_load__ && !isAbsolute ? /* @__PURE__ */ jsx(PrefetchPageLinks, { pathname }) : null
|
|
165
|
+
] });
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
};
|
|
169
|
+
const Link = createPrefetchLink(RouterLink);
|
|
170
|
+
Link.displayName = "Link";
|
|
171
|
+
const NavLink = createPrefetchLink(RouterNavLink);
|
|
172
|
+
NavLink.displayName = "NavLink";
|
|
173
|
+
export {
|
|
174
|
+
Link as PrefetchLink,
|
|
175
|
+
NavLink as PrefetchNavLink,
|
|
176
|
+
composeEventHandlers
|
|
177
|
+
};
|
|
@@ -2,6 +2,7 @@ import { routerPlugin } from "./plugin";
|
|
|
2
2
|
var runtime_default = routerPlugin;
|
|
3
3
|
import { modifyRoutes } from "./plugin";
|
|
4
4
|
export * from "./withRouter";
|
|
5
|
+
import { PrefetchLink, PrefetchNavLink } from "./PrefetchLink";
|
|
5
6
|
import {
|
|
6
7
|
createBrowserRouter,
|
|
7
8
|
createHashRouter,
|
|
@@ -57,7 +58,7 @@ import {
|
|
|
57
58
|
renderMatches,
|
|
58
59
|
resolvePath
|
|
59
60
|
} from "react-router-dom";
|
|
60
|
-
import { defer, json, redirect } from "@modern-js/utils/remix-router";
|
|
61
|
+
import { defer, json, redirect } from "@modern-js/utils/universal/remix-router";
|
|
61
62
|
export {
|
|
62
63
|
Await,
|
|
63
64
|
BrowserRouter,
|
|
@@ -68,6 +69,8 @@ export {
|
|
|
68
69
|
NavLink,
|
|
69
70
|
Navigate,
|
|
70
71
|
Outlet,
|
|
72
|
+
PrefetchLink,
|
|
73
|
+
PrefetchNavLink,
|
|
71
74
|
Route,
|
|
72
75
|
Router,
|
|
73
76
|
RouterProvider,
|
|
@@ -32,6 +32,7 @@ const routerPlugin = ({
|
|
|
32
32
|
createRoutes
|
|
33
33
|
}) => {
|
|
34
34
|
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
35
|
+
let routes = [];
|
|
35
36
|
finalRouteConfig = routesConfig;
|
|
36
37
|
return {
|
|
37
38
|
name: "@modern-js/plugin-router",
|
|
@@ -42,6 +43,11 @@ const routerPlugin = ({
|
|
|
42
43
|
useMatches,
|
|
43
44
|
useLocation
|
|
44
45
|
};
|
|
46
|
+
Object.defineProperty(context, "routes", {
|
|
47
|
+
get() {
|
|
48
|
+
return routes;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
45
51
|
return next({ context });
|
|
46
52
|
},
|
|
47
53
|
hoc: ({ App }, next) => {
|
|
@@ -52,7 +58,12 @@ const routerPlugin = ({
|
|
|
52
58
|
return (props) => {
|
|
53
59
|
var _a;
|
|
54
60
|
beforeCreateRouter = true;
|
|
55
|
-
|
|
61
|
+
routes = createRoutes ? createRoutes() : createRoutesFromElements(
|
|
62
|
+
renderRoutes({
|
|
63
|
+
routesConfig: finalRouteConfig,
|
|
64
|
+
props
|
|
65
|
+
})
|
|
66
|
+
);
|
|
56
67
|
const baseUrl = ((_a = window._SERVER_DATA) == null ? void 0 : _a.router.baseUrl) || select(location.pathname);
|
|
57
68
|
const _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
|
|
58
69
|
let hydrationData = window._ROUTER_DATA;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import { createStaticHandler } from "@modern-js/utils/remix-router";
|
|
3
|
+
import { createStaticHandler } from "@modern-js/utils/universal/remix-router";
|
|
4
4
|
import {
|
|
5
5
|
createStaticRouter,
|
|
6
6
|
StaticRouterProvider
|
|
@@ -53,7 +53,12 @@ const routerPlugin = ({
|
|
|
53
53
|
const { request, mode: ssrMode } = context.ssrContext;
|
|
54
54
|
const baseUrl = request.baseUrl;
|
|
55
55
|
const _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
|
|
56
|
-
const routes = createRoutes ? createRoutes() : createRoutesFromElements(
|
|
56
|
+
const routes = createRoutes ? createRoutes() : createRoutesFromElements(
|
|
57
|
+
renderRoutes({
|
|
58
|
+
routesConfig,
|
|
59
|
+
ssrMode
|
|
60
|
+
})
|
|
61
|
+
);
|
|
57
62
|
const { query } = createStaticHandler(routes, {
|
|
58
63
|
basename: _basename
|
|
59
64
|
});
|
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Route } from "react-router-dom";
|
|
3
|
-
import { renderNestedRoute } from "@modern-js/utils/nestedRoutes";
|
|
4
3
|
import {
|
|
5
4
|
ErrorResponse,
|
|
6
5
|
isRouteErrorResponse
|
|
7
|
-
} from "@modern-js/utils/remix-router";
|
|
6
|
+
} from "@modern-js/utils/universal/remix-router";
|
|
7
|
+
import { renderNestedRoute } from "@modern-js/utils/universal/nestedRoutes";
|
|
8
8
|
import { DefaultNotFound } from "./DefaultNotFound";
|
|
9
9
|
import DeferredDataScripts from "./DeferredDataScripts";
|
|
10
10
|
function getRouteComponents(routes, {
|
|
11
11
|
globalApp,
|
|
12
|
-
ssrMode
|
|
12
|
+
ssrMode,
|
|
13
|
+
props
|
|
13
14
|
}) {
|
|
14
|
-
const Layout = ({ Component, ...
|
|
15
|
+
const Layout = ({ Component, ...props2 }) => {
|
|
15
16
|
const GlobalLayout = globalApp;
|
|
16
17
|
if (!GlobalLayout) {
|
|
17
|
-
return /* @__PURE__ */ jsx(Component, { ...
|
|
18
|
+
return /* @__PURE__ */ jsx(Component, { ...props2 });
|
|
18
19
|
}
|
|
19
|
-
return /* @__PURE__ */ jsx(GlobalLayout, { Component, ...
|
|
20
|
+
return /* @__PURE__ */ jsx(GlobalLayout, { Component, ...props2 });
|
|
20
21
|
};
|
|
21
22
|
const routeElements = [];
|
|
22
23
|
for (const route of routes) {
|
|
23
24
|
if (route.type === "nested") {
|
|
24
25
|
const routeElement = renderNestedRoute(route, {
|
|
25
|
-
DeferredDataComponent: ssrMode === "stream" ? DeferredDataScripts : void 0
|
|
26
|
+
DeferredDataComponent: ssrMode === "stream" ? DeferredDataScripts : void 0,
|
|
27
|
+
props
|
|
26
28
|
});
|
|
27
29
|
routeElements.push(routeElement);
|
|
28
30
|
} else {
|
|
@@ -40,7 +42,11 @@ function getRouteComponents(routes, {
|
|
|
40
42
|
routeElements.push(/* @__PURE__ */ jsx(Route, { path: "*", element: /* @__PURE__ */ jsx(DefaultNotFound, {}) }, "*"));
|
|
41
43
|
return routeElements;
|
|
42
44
|
}
|
|
43
|
-
function renderRoutes(
|
|
45
|
+
function renderRoutes({
|
|
46
|
+
routesConfig,
|
|
47
|
+
props,
|
|
48
|
+
ssrMode
|
|
49
|
+
}) {
|
|
44
50
|
if (!routesConfig) {
|
|
45
51
|
return null;
|
|
46
52
|
}
|
|
@@ -48,7 +54,11 @@ function renderRoutes(routesConfig, ssrMode) {
|
|
|
48
54
|
if (!routes) {
|
|
49
55
|
return null;
|
|
50
56
|
}
|
|
51
|
-
const routeElements = getRouteComponents(routes, {
|
|
57
|
+
const routeElements = getRouteComponents(routes, {
|
|
58
|
+
globalApp,
|
|
59
|
+
ssrMode,
|
|
60
|
+
props
|
|
61
|
+
});
|
|
52
62
|
return routeElements;
|
|
53
63
|
}
|
|
54
64
|
function getLocation(serverContext) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { serializeJson } from "@modern-js/utils/serialize";
|
|
1
|
+
import { serializeJson } from "@modern-js/utils/universal/serialize";
|
|
2
2
|
import { buildTemplate } from "./buildTemplate.share";
|
|
3
3
|
function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
4
4
|
const callbacks = [injectSSRDataScript];
|
|
@@ -42,8 +42,8 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
42
42
|
if (routeId) {
|
|
43
43
|
const routeManifest2 = routeAssets[routeId];
|
|
44
44
|
if (routeManifest2) {
|
|
45
|
-
const {
|
|
46
|
-
const _cssChunks =
|
|
45
|
+
const { referenceCssAssets = [] } = routeManifest2;
|
|
46
|
+
const _cssChunks = referenceCssAssets.filter(
|
|
47
47
|
(asset) => asset == null ? void 0 : asset.endsWith(".css")
|
|
48
48
|
);
|
|
49
49
|
cssChunks.push(..._cssChunks);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import ReactDomServer from "react-dom/server";
|
|
3
|
-
import { serializeJson } from "@modern-js/utils/serialize";
|
|
3
|
+
import { serializeJson } from "@modern-js/utils/universal/serialize";
|
|
4
4
|
import ReactHelmet from "react-helmet";
|
|
5
5
|
import { serializeErrors } from "../../../router/runtime/utils";
|
|
6
6
|
import helmetReplace from "../helmet";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { LinkProps as RouterLinkProps, NavLinkProps as RouterNavLinkProps } from 'react-router-dom';
|
|
3
|
+
export declare function composeEventHandlers<EventType extends React.SyntheticEvent | Event>(theirHandler: ((event: EventType) => any) | undefined, ourHandler: (event: EventType) => any): (event: EventType) => any;
|
|
4
|
+
/**
|
|
5
|
+
* Modified from https://github.com/remix-run/remix/blob/9a0601bd704d2f3ee622e0ddacab9b611eb0c5bc/packages/remix-react/components.tsx#L218
|
|
6
|
+
*
|
|
7
|
+
* MIT Licensed
|
|
8
|
+
* Author Michael Jackson
|
|
9
|
+
* Copyright 2021 Remix Software Inc.
|
|
10
|
+
* https://github.com/remix-run/remix/blob/2b5e1a72fc628d0408e27cf4d72e537762f1dc5b/LICENSE.md
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Defines the prefetching behavior of the link:
|
|
15
|
+
*
|
|
16
|
+
* - "intent": Fetched when the user focuses or hovers the link
|
|
17
|
+
* - "render": Fetched when the link is rendered
|
|
18
|
+
* - "none": Never fetched
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
type PrefetchBehavior = 'intent' | 'render' | 'none';
|
|
22
|
+
export interface PrefetchLinkProps extends RouterLinkProps {
|
|
23
|
+
prefetch?: PrefetchBehavior;
|
|
24
|
+
}
|
|
25
|
+
export interface PrefetchNavLinkProps extends RouterNavLinkProps {
|
|
26
|
+
prefetch?: PrefetchBehavior;
|
|
27
|
+
}
|
|
28
|
+
declare const Link: React.ForwardRefExoticComponent<PrefetchLinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
29
|
+
declare const NavLink: React.ForwardRefExoticComponent<PrefetchNavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
30
|
+
export { Link as PrefetchLink, NavLink as PrefetchNavLink };
|
|
@@ -4,6 +4,8 @@ export type { SingleRouteConfig, RouterConfig };
|
|
|
4
4
|
export default routerPlugin;
|
|
5
5
|
export { modifyRoutes } from './plugin';
|
|
6
6
|
export * from './withRouter';
|
|
7
|
+
export { PrefetchLink, PrefetchNavLink } from './PrefetchLink';
|
|
8
|
+
export type { PrefetchLinkProps, PrefetchNavLinkProps } from './PrefetchLink';
|
|
7
9
|
export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, FetcherWithComponents, BrowserRouterProps, HashRouterProps, HistoryRouterProps, LinkProps, NavLinkProps, FormProps, ScrollRestorationProps, SubmitFunction, ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To } from 'react-router-dom';
|
|
8
10
|
export { createBrowserRouter, createHashRouter, createMemoryRouter, RouterProvider, BrowserRouter, HashRouter, MemoryRouter, Router, Await, Form, Link, NavLink, Navigate, Outlet, Route, Routes, ScrollRestoration, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, useSearchParams, useSubmit, createRoutesFromChildren, createRoutesFromElements, createSearchParams, generatePath, isRouteErrorResponse, matchPath, matchRoutes, renderMatches, resolvePath } from 'react-router-dom';
|
|
9
|
-
export { defer, json, redirect } from '@modern-js/utils/remix-router';
|
|
11
|
+
export { defer, json, redirect } from '@modern-js/utils/universal/remix-router';
|
|
@@ -37,4 +37,13 @@ export type RouterConfig = {
|
|
|
37
37
|
basename?: string;
|
|
38
38
|
createRoutes?: () => RouteObject[];
|
|
39
39
|
};
|
|
40
|
-
export type Routes = RouterConfig['routesConfig']['routes'];
|
|
40
|
+
export type Routes = RouterConfig['routesConfig']['routes'];
|
|
41
|
+
export interface RouteManifest {
|
|
42
|
+
routeAssets: RouteAssets;
|
|
43
|
+
}
|
|
44
|
+
export interface RouteAssets {
|
|
45
|
+
[routeId: string]: {
|
|
46
|
+
chunkIds?: (string | number)[];
|
|
47
|
+
assets?: string[];
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type NestedRoute, type PageRoute, type SSRMode } from '@modern-js/types';
|
|
3
|
-
import { type Router, type StaticHandlerContext } from '@modern-js/utils/remix-router';
|
|
3
|
+
import { type Router, type StaticHandlerContext } from '@modern-js/utils/universal/remix-router';
|
|
4
4
|
import { RouterConfig } from './types';
|
|
5
5
|
export declare function getRouteComponents(routes: (NestedRoute | PageRoute)[], {
|
|
6
6
|
globalApp,
|
|
7
|
-
ssrMode
|
|
7
|
+
ssrMode,
|
|
8
|
+
props
|
|
8
9
|
}: {
|
|
9
10
|
globalApp?: React.ComponentType<any>;
|
|
10
11
|
ssrMode?: SSRMode;
|
|
12
|
+
props?: Record<string, any>;
|
|
11
13
|
}): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
|
|
12
|
-
export declare function renderRoutes(
|
|
14
|
+
export declare function renderRoutes({
|
|
15
|
+
routesConfig,
|
|
16
|
+
props,
|
|
17
|
+
ssrMode
|
|
18
|
+
}: {
|
|
19
|
+
routesConfig: RouterConfig['routesConfig'];
|
|
20
|
+
props?: Record<string, any>;
|
|
21
|
+
ssrMode?: SSRMode;
|
|
22
|
+
}): React.ReactElement<any, string | React.JSXElementConstructor<any>>[] | null;
|
|
13
23
|
export declare function getLocation(serverContext: any): string;
|
|
14
24
|
export declare const urlJoin: (...parts: string[]) => string;
|
|
15
25
|
export declare function standardSlash(str: string): string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Store } from '@modern-js-reduck/store';
|
|
3
|
-
import type { StaticHandlerContext } from '@modern-js/utils/remix-router';
|
|
3
|
+
import type { StaticHandlerContext } from '@modern-js/utils/universal/remix-router';
|
|
4
4
|
import { createLoaderManager } from './core/loader/loaderManager';
|
|
5
5
|
import { runtime } from './core/plugin';
|
|
6
|
+
import { RouteManifest } from './router/runtime/types';
|
|
6
7
|
import { SSRServerContext } from './ssr/serverRender/types';
|
|
7
8
|
export interface BaseRuntimeContext {
|
|
8
9
|
initialData?: Record<string, unknown>;
|
|
@@ -10,6 +11,7 @@ export interface BaseRuntimeContext {
|
|
|
10
11
|
runner: ReturnType<typeof runtime.init>;
|
|
11
12
|
ssrContext?: SSRServerContext;
|
|
12
13
|
store?: Store;
|
|
14
|
+
routeManifest: RouteManifest;
|
|
13
15
|
routerContext?: StaticHandlerContext;
|
|
14
16
|
}
|
|
15
17
|
export interface RuntimeContext extends BaseRuntimeContext {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.11.0",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=14.17.6"
|
|
17
17
|
},
|
|
@@ -158,9 +158,9 @@
|
|
|
158
158
|
"react-side-effect": "^2.1.1",
|
|
159
159
|
"redux-logger": "^3.0.6",
|
|
160
160
|
"styled-components": "^5.3.1",
|
|
161
|
-
"@modern-js/plugin": "2.
|
|
162
|
-
"@modern-js/types": "2.
|
|
163
|
-
"@modern-js/utils": "2.
|
|
161
|
+
"@modern-js/plugin": "2.11.0",
|
|
162
|
+
"@modern-js/types": "2.11.0",
|
|
163
|
+
"@modern-js/utils": "2.11.0"
|
|
164
164
|
},
|
|
165
165
|
"peerDependencies": {
|
|
166
166
|
"react": ">=17",
|
|
@@ -181,11 +181,11 @@
|
|
|
181
181
|
"react-dom": "^18",
|
|
182
182
|
"ts-jest": "^29.0.5",
|
|
183
183
|
"typescript": "^4",
|
|
184
|
-
"@modern-js/app-tools": "2.
|
|
185
|
-
"@modern-js/core": "2.
|
|
186
|
-
"@modern-js/server-core": "2.
|
|
187
|
-
"@scripts/build": "2.
|
|
188
|
-
"@scripts/jest-config": "2.
|
|
184
|
+
"@modern-js/app-tools": "2.11.0",
|
|
185
|
+
"@modern-js/core": "2.11.0",
|
|
186
|
+
"@modern-js/server-core": "2.11.0",
|
|
187
|
+
"@scripts/build": "2.11.0",
|
|
188
|
+
"@scripts/jest-config": "2.11.0"
|
|
189
189
|
},
|
|
190
190
|
"sideEffects": false,
|
|
191
191
|
"modernConfig": {},
|