@modern-js/runtime 2.0.0-beta.0 → 2.0.0-beta.2
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 +158 -0
- package/dist/js/modern/cli/index.js +6 -6
- package/dist/js/modern/core/app-config.js +2 -1
- package/dist/js/modern/core/compatible.js +66 -48
- package/dist/js/modern/core/index.js +3 -2
- package/dist/js/modern/core/loader/loaderManager.js +12 -34
- package/dist/js/modern/core/loader/useLoader.js +8 -26
- package/dist/js/modern/core/plugin.js +6 -28
- package/dist/js/modern/document/Body.js +17 -0
- package/dist/js/modern/document/DocumentContext.js +6 -0
- package/dist/js/modern/document/DocumentStructrueContext.js +7 -0
- package/dist/js/modern/document/Head.js +24 -0
- package/dist/js/modern/document/Html.js +92 -0
- package/dist/js/modern/document/Root.js +31 -0
- package/dist/js/modern/document/Scripts.js +10 -0
- package/dist/js/modern/document/cli/index.js +132 -0
- package/dist/js/modern/document/constants.js +19 -0
- package/dist/js/modern/document/index.js +8 -0
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/router/cli/index.js +0 -16
- package/dist/js/modern/router/runtime/plugin.js +0 -9
- package/dist/js/modern/router/runtime/plugin.node.js +18 -24
- package/dist/js/modern/router/runtime/root/index.js +19 -0
- package/dist/js/modern/router/runtime/root/load.js +61 -0
- package/dist/js/modern/router/runtime/utils.js +16 -35
- package/dist/js/modern/router/runtime/withRouter.js +1 -3
- package/dist/js/modern/ssr/cli/index.js +2 -23
- package/dist/js/modern/ssr/index.js +23 -34
- package/dist/js/modern/ssr/index.node.js +0 -13
- package/dist/js/modern/ssr/prefetch.js +0 -7
- package/dist/js/modern/ssr/react/prerender/index.js +2 -23
- package/dist/js/modern/ssr/react/prerender/util.js +2 -17
- package/dist/js/modern/ssr/react/withCallback/index.js +0 -1
- package/dist/js/modern/ssr/serverRender/helmet.js +12 -20
- package/dist/js/modern/ssr/serverRender/index.js +1 -2
- package/dist/js/modern/ssr/serverRender/renderToStream/buildTemplate.after.js +5 -5
- package/dist/js/modern/ssr/serverRender/renderToStream/bulidTemplate.before.js +45 -11
- package/dist/js/modern/ssr/serverRender/renderToStream/index.js +6 -39
- package/dist/js/modern/ssr/serverRender/renderToStream/loadable.js +0 -2
- package/dist/js/modern/ssr/serverRender/renderToStream/renderToPipe.js +26 -15
- package/dist/js/modern/ssr/serverRender/renderToStream/template.js +14 -18
- package/dist/js/modern/ssr/serverRender/renderToString/entry.js +2 -34
- package/dist/js/modern/ssr/serverRender/renderToString/index.js +0 -2
- package/dist/js/modern/ssr/serverRender/renderToString/loadable.js +0 -10
- package/dist/js/modern/ssr/serverRender/renderToString/reduce.js +0 -2
- package/dist/js/modern/ssr/serverRender/renderToString/template.js +0 -15
- package/dist/js/modern/ssr/serverRender/renderToString/type.js +0 -1
- package/dist/js/modern/ssr/serverRender/utils.js +2 -6
- package/dist/js/modern/ssr/utils.js +0 -11
- package/dist/js/modern/state/cli/index.js +0 -11
- package/dist/js/modern/state/runtime/plugin.js +1 -14
- package/dist/js/node/cli/index.js +6 -14
- package/dist/js/node/common.js +0 -2
- package/dist/js/node/core/app-config.js +2 -5
- package/dist/js/node/core/compatible.js +66 -66
- package/dist/js/node/core/index.js +0 -16
- package/dist/js/node/core/loader/index.js +0 -2
- package/dist/js/node/core/loader/loaderManager.js +12 -37
- package/dist/js/node/core/loader/useLoader.js +8 -31
- package/dist/js/node/core/plugin.js +5 -34
- package/dist/js/node/document/Body.js +26 -0
- package/dist/js/node/document/DocumentContext.js +14 -0
- package/dist/js/node/document/DocumentStructrueContext.js +15 -0
- package/dist/js/node/document/Head.js +33 -0
- package/dist/js/node/document/Html.js +98 -0
- package/dist/js/node/document/Root.js +41 -0
- package/dist/js/node/document/Scripts.js +17 -0
- package/dist/js/node/document/cli/index.js +142 -0
- package/dist/js/node/document/constants.js +36 -0
- package/dist/js/node/document/index.js +93 -0
- package/dist/js/node/exports/head.js +0 -5
- package/dist/js/node/exports/loadable.js +0 -5
- package/dist/js/node/exports/server.js +0 -2
- package/dist/js/node/exports/styled.js +0 -5
- package/dist/js/node/index.js +0 -8
- package/dist/js/node/router/cli/index.js +0 -20
- package/dist/js/node/router/index.js +0 -4
- package/dist/js/node/router/runtime/DefaultNotFound.js +1 -5
- package/dist/js/node/router/runtime/index.js +0 -5
- package/dist/js/node/router/runtime/plugin.js +0 -17
- package/dist/js/node/router/runtime/plugin.node.js +16 -38
- package/dist/js/node/router/runtime/root/index.js +26 -0
- package/dist/js/node/router/runtime/root/load.js +69 -0
- package/dist/js/node/router/runtime/utils.js +16 -44
- package/dist/js/node/router/runtime/withRouter.js +0 -9
- package/dist/js/node/runtime-context.js +0 -2
- package/dist/js/node/ssr/cli/index.js +2 -26
- package/dist/js/node/ssr/index.js +23 -45
- package/dist/js/node/ssr/index.node.js +0 -23
- package/dist/js/node/ssr/prefetch.js +0 -11
- package/dist/js/node/ssr/react/index.js +0 -2
- package/dist/js/node/ssr/react/nossr/index.js +0 -6
- package/dist/js/node/ssr/react/prerender/index.js +2 -30
- package/dist/js/node/ssr/react/prerender/util.js +2 -25
- package/dist/js/node/ssr/react/withCallback/index.js +1 -4
- package/dist/js/node/ssr/serverRender/helmet.js +13 -20
- package/dist/js/node/ssr/serverRender/index.js +1 -4
- package/dist/js/node/ssr/serverRender/renderToStream/buildTemplate.after.js +5 -9
- package/dist/js/node/ssr/serverRender/renderToStream/buildTemplate.share.js +0 -1
- package/dist/js/node/ssr/serverRender/renderToStream/bulidTemplate.before.js +43 -15
- package/dist/js/node/ssr/serverRender/renderToStream/index.js +6 -48
- package/dist/js/node/ssr/serverRender/renderToStream/loadable.js +0 -4
- package/dist/js/node/ssr/serverRender/renderToStream/renderToPipe.js +26 -17
- package/dist/js/node/ssr/serverRender/renderToStream/styledComponent.js +0 -2
- package/dist/js/node/ssr/serverRender/renderToStream/template.js +16 -23
- package/dist/js/node/ssr/serverRender/renderToString/entry.js +2 -51
- package/dist/js/node/ssr/serverRender/renderToString/index.js +0 -10
- package/dist/js/node/ssr/serverRender/renderToString/loadable.js +0 -14
- package/dist/js/node/ssr/serverRender/renderToString/reduce.js +0 -3
- package/dist/js/node/ssr/serverRender/renderToString/styledComponent.js +0 -3
- package/dist/js/node/ssr/serverRender/renderToString/template.js +0 -18
- package/dist/js/node/ssr/serverRender/renderToString/type.js +0 -1
- package/dist/js/node/ssr/serverRender/types.js +0 -1
- package/dist/js/node/ssr/serverRender/utils.js +2 -8
- package/dist/js/node/ssr/utils.js +0 -20
- package/dist/js/node/state/cli/index.js +0 -16
- package/dist/js/node/state/index.js +0 -4
- package/dist/js/node/state/plugins.js +0 -11
- package/dist/js/node/state/runtime/index.js +0 -7
- package/dist/js/node/state/runtime/plugin.js +1 -25
- package/dist/js/treeshaking/cli/index.js +6 -4
- package/dist/js/treeshaking/core/app-config.js +2 -1
- package/dist/js/treeshaking/core/compatible.js +74 -81
- package/dist/js/treeshaking/core/index.js +3 -2
- package/dist/js/treeshaking/core/loader/loaderManager.js +19 -51
- package/dist/js/treeshaking/core/loader/useLoader.js +11 -28
- package/dist/js/treeshaking/core/plugin.js +6 -51
- package/dist/js/treeshaking/document/Body.js +14 -0
- package/dist/js/treeshaking/document/DocumentContext.js +6 -0
- package/dist/js/treeshaking/document/DocumentStructrueContext.js +7 -0
- package/dist/js/treeshaking/document/Head.js +21 -0
- package/dist/js/treeshaking/document/Html.js +104 -0
- package/dist/js/treeshaking/document/Root.js +24 -0
- package/dist/js/treeshaking/document/Scripts.js +10 -0
- package/dist/js/treeshaking/document/cli/index.js +175 -0
- package/dist/js/treeshaking/document/constants.js +16 -0
- package/dist/js/treeshaking/document/index.js +8 -0
- package/dist/js/treeshaking/index.js +1 -1
- package/dist/js/treeshaking/router/cli/index.js +6 -18
- package/dist/js/treeshaking/router/runtime/plugin.js +5 -13
- package/dist/js/treeshaking/router/runtime/plugin.node.js +23 -36
- package/dist/js/treeshaking/router/runtime/root/index.js +17 -0
- package/dist/js/treeshaking/router/runtime/root/load.js +102 -0
- package/dist/js/treeshaking/router/runtime/utils.js +21 -39
- package/dist/js/treeshaking/router/runtime/withRouter.js +1 -0
- package/dist/js/treeshaking/ssr/cli/index.js +9 -31
- package/dist/js/treeshaking/ssr/index.js +26 -40
- package/dist/js/treeshaking/ssr/index.node.js +12 -29
- package/dist/js/treeshaking/ssr/prefetch.js +0 -13
- package/dist/js/treeshaking/ssr/react/nossr/index.js +3 -4
- package/dist/js/treeshaking/ssr/react/prerender/index.js +2 -21
- package/dist/js/treeshaking/ssr/react/prerender/util.js +3 -20
- package/dist/js/treeshaking/ssr/react/withCallback/index.js +1 -2
- package/dist/js/treeshaking/ssr/serverRender/helmet.js +12 -11
- package/dist/js/treeshaking/ssr/serverRender/index.js +1 -9
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/buildTemplate.after.js +5 -6
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/bulidTemplate.before.js +46 -15
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/index.js +9 -79
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/loadable.js +3 -5
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/renderToPipe.js +46 -35
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/template.js +17 -24
- package/dist/js/treeshaking/ssr/serverRender/renderToString/entry.js +20 -73
- package/dist/js/treeshaking/ssr/serverRender/renderToString/index.js +2 -6
- package/dist/js/treeshaking/ssr/serverRender/renderToString/loadable.js +5 -16
- package/dist/js/treeshaking/ssr/serverRender/renderToString/reduce.js +0 -2
- package/dist/js/treeshaking/ssr/serverRender/renderToString/template.js +2 -18
- package/dist/js/treeshaking/ssr/serverRender/renderToString/type.js +0 -1
- package/dist/js/treeshaking/ssr/serverRender/utils.js +5 -10
- package/dist/js/treeshaking/ssr/utils.js +8 -17
- package/dist/js/treeshaking/state/cli/index.js +3 -11
- package/dist/js/treeshaking/state/runtime/plugin.js +2 -10
- package/dist/types/cli/index.d.ts +2 -4
- package/dist/types/core/compatible.d.ts +8 -10
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/loader/loaderManager.d.ts +0 -1
- package/dist/types/core/loader/useLoader.d.ts +0 -5
- package/dist/types/core/plugin.d.ts +16 -28
- package/dist/types/document/Body.d.ts +4 -0
- package/dist/types/document/DocumentContext.d.ts +13 -0
- package/dist/types/document/DocumentStructrueContext.d.ts +10 -0
- package/dist/types/document/Head.d.ts +5 -0
- package/dist/types/document/Html.d.ts +4 -0
- package/dist/types/document/Root.d.ts +8 -0
- package/dist/types/document/Scripts.d.ts +2 -0
- package/dist/types/document/cli/index.d.ts +3 -0
- package/dist/types/document/constants.d.ts +14 -0
- package/dist/types/document/index.d.ts +8 -0
- package/dist/types/exports/server.d.ts +3 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/router/cli/index.d.ts +2 -4
- package/dist/types/router/runtime/root/index.d.ts +8 -0
- package/dist/types/router/runtime/root/load.d.ts +22 -0
- package/dist/types/router/runtime/types.d.ts +0 -2
- package/dist/types/runtime-context.d.ts +1 -0
- package/dist/types/ssr/cli/index.d.ts +2 -4
- package/dist/types/ssr/prefetch.d.ts +2 -2
- package/dist/types/ssr/serverRender/renderToStream/buildTemplate.after.d.ts +3 -2
- package/dist/types/ssr/serverRender/renderToStream/bulidTemplate.before.d.ts +2 -1
- package/dist/types/ssr/serverRender/renderToStream/renderToPipe.d.ts +3 -3
- package/dist/types/ssr/serverRender/renderToStream/template.d.ts +2 -2
- package/dist/types/ssr/serverRender/types.d.ts +3 -6
- package/dist/types/state/cli/index.d.ts +2 -4
- package/dist/types/state/types.d.ts +0 -1
- package/package.json +24 -15
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import React from 'react';
|
|
8
5
|
import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements } from 'react-router-dom';
|
|
9
6
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
@@ -16,7 +13,6 @@ export const routerPlugin = ({
|
|
|
16
13
|
createRoutes
|
|
17
14
|
}) => {
|
|
18
15
|
const select = pathname => _serverBase.find(baseUrl => pathname.search(baseUrl) === 0) || '/';
|
|
19
|
-
|
|
20
16
|
return {
|
|
21
17
|
name: '@modern-js/plugin-router',
|
|
22
18
|
setup: () => {
|
|
@@ -31,11 +27,9 @@ export const routerPlugin = ({
|
|
|
31
27
|
App
|
|
32
28
|
});
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
const getRouteApp = () => {
|
|
36
31
|
return props => {
|
|
37
32
|
var _window$_SERVER_DATA;
|
|
38
|
-
|
|
39
33
|
const routeElements = renderRoutes(routesConfig);
|
|
40
34
|
const routes = createRoutes ? createRoutes() : createRoutesFromElements(routeElements);
|
|
41
35
|
const baseUrl = ((_window$_SERVER_DATA = window._SERVER_DATA) === null || _window$_SERVER_DATA === void 0 ? void 0 : _window$_SERVER_DATA.router.baseUrl) || select(location.pathname);
|
|
@@ -51,15 +45,12 @@ export const routerPlugin = ({
|
|
|
51
45
|
}));
|
|
52
46
|
};
|
|
53
47
|
};
|
|
54
|
-
|
|
55
48
|
const RouteApp = getRouteApp();
|
|
56
|
-
|
|
57
49
|
if (routesConfig.globalApp) {
|
|
58
50
|
return next({
|
|
59
51
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
60
52
|
});
|
|
61
53
|
}
|
|
62
|
-
|
|
63
54
|
return next({
|
|
64
55
|
App: RouteApp
|
|
65
56
|
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import React, { useContext } from 'react';
|
|
8
5
|
import { unstable_createStaticHandler as createStaticHandler } from '@remix-run/router';
|
|
9
6
|
import { unstable_createStaticRouter as createStaticRouter, unstable_StaticRouterProvider as StaticRouterProvider } from 'react-router-dom/server';
|
|
@@ -11,17 +8,21 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
|
11
8
|
import { installGlobals } from '@remix-run/node';
|
|
12
9
|
import { createRoutesFromElements } from 'react-router-dom';
|
|
13
10
|
import { RuntimeReactContext } from "../../core";
|
|
14
|
-
import { renderRoutes } from "./utils";
|
|
11
|
+
import { renderRoutes } from "./utils";
|
|
15
12
|
|
|
13
|
+
// Polyfill Web Fetch API
|
|
16
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
-
installGlobals();
|
|
15
|
+
installGlobals();
|
|
18
16
|
|
|
17
|
+
// TODO: polish
|
|
19
18
|
function createFetchRequest(req) {
|
|
20
19
|
// const origin = `${req.protocol}://${req.get('host')}`;
|
|
21
|
-
const origin = `${req.protocol}://${req.host}`;
|
|
22
|
-
|
|
20
|
+
const origin = `${req.protocol}://${req.host}`;
|
|
21
|
+
// Note: This had to take originalUrl into account for presumably vite's proxying
|
|
23
22
|
const url = new URL(req.originalUrl || req.url, origin);
|
|
24
|
-
const controller = new AbortController();
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
|
|
25
|
+
// req.on('close', () => {
|
|
25
26
|
// controller.abort();
|
|
26
27
|
// });
|
|
27
28
|
|
|
@@ -29,16 +30,16 @@ function createFetchRequest(req) {
|
|
|
29
30
|
method: req.method,
|
|
30
31
|
headers: createFetchHeaders(req.headers),
|
|
31
32
|
signal: controller.signal
|
|
32
|
-
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
33
36
|
// init.body = req.body;
|
|
34
37
|
// }
|
|
35
38
|
|
|
36
39
|
return new Request(url.href, init);
|
|
37
40
|
}
|
|
38
|
-
|
|
39
41
|
export function createFetchHeaders(requestHeaders) {
|
|
40
42
|
const headers = new Headers();
|
|
41
|
-
|
|
42
43
|
for (const [key, values] of Object.entries(requestHeaders)) {
|
|
43
44
|
if (values) {
|
|
44
45
|
if (Array.isArray(values)) {
|
|
@@ -50,7 +51,6 @@ export function createFetchHeaders(requestHeaders) {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
|
|
54
54
|
return headers;
|
|
55
55
|
}
|
|
56
56
|
export const routerPlugin = ({
|
|
@@ -71,7 +71,6 @@ export const routerPlugin = ({
|
|
|
71
71
|
context
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
-
|
|
75
74
|
const {
|
|
76
75
|
request
|
|
77
76
|
} = context.ssrContext;
|
|
@@ -82,22 +81,21 @@ export const routerPlugin = ({
|
|
|
82
81
|
} = createStaticHandler(routes);
|
|
83
82
|
const remixRequest = createFetchRequest(request);
|
|
84
83
|
const routerContext = await query(remixRequest);
|
|
85
|
-
|
|
86
84
|
if (routerContext instanceof Response) {
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
85
|
+
// React Router would return a Response when redirects occur in loader.
|
|
86
|
+
// Throw the Response to bail out and let the server handle it with an HTTP redirect
|
|
87
|
+
return routerContext;
|
|
91
88
|
}
|
|
92
|
-
|
|
93
89
|
const router = createStaticRouter(routes, routerContext);
|
|
94
90
|
context.router = router;
|
|
95
91
|
context.routerContext = routerContext;
|
|
92
|
+
context.routes = routes;
|
|
93
|
+
// set routeManifest in context to be consistent with csr context
|
|
94
|
+
context.routeManifest = context.ssrContext.routeManifest;
|
|
96
95
|
return next({
|
|
97
96
|
context
|
|
98
97
|
});
|
|
99
98
|
},
|
|
100
|
-
|
|
101
99
|
hoc: ({
|
|
102
100
|
App
|
|
103
101
|
}, next) => {
|
|
@@ -108,7 +106,6 @@ export const routerPlugin = ({
|
|
|
108
106
|
App
|
|
109
107
|
});
|
|
110
108
|
}
|
|
111
|
-
|
|
112
109
|
const getRouteApp = () => {
|
|
113
110
|
return props => {
|
|
114
111
|
const {
|
|
@@ -124,15 +121,12 @@ export const routerPlugin = ({
|
|
|
124
121
|
}));
|
|
125
122
|
};
|
|
126
123
|
};
|
|
127
|
-
|
|
128
124
|
const RouteApp = getRouteApp();
|
|
129
|
-
|
|
130
125
|
if (routesConfig.globalApp) {
|
|
131
126
|
return next({
|
|
132
127
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
133
128
|
});
|
|
134
129
|
}
|
|
135
|
-
|
|
136
130
|
return next({
|
|
137
131
|
App: RouteApp
|
|
138
132
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { useContext, useEffect } from 'react';
|
|
2
|
+
import { useLocation } from 'react-router-dom';
|
|
3
|
+
import { RuntimeReactContext } from "../../../core";
|
|
4
|
+
import { handleLoad } from "./load";
|
|
5
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
export function RootLayout(props) {
|
|
8
|
+
const location = useLocation();
|
|
9
|
+
const context = useContext(RuntimeReactContext);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const {
|
|
12
|
+
routes
|
|
13
|
+
} = props;
|
|
14
|
+
handleLoad(routes, location, context.routeManifest);
|
|
15
|
+
}, [location]);
|
|
16
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
17
|
+
children: props.children
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
import { matchRoutes } from 'react-router-dom';
|
|
3
|
+
class Logger {
|
|
4
|
+
static getLogger(options) {
|
|
5
|
+
if (this.logger) {
|
|
6
|
+
return this.logger;
|
|
7
|
+
}
|
|
8
|
+
this.logger = new Logger(options);
|
|
9
|
+
return this.logger;
|
|
10
|
+
}
|
|
11
|
+
constructor(options) {
|
|
12
|
+
_defineProperty(this, "enableLogging", void 0);
|
|
13
|
+
this.enableLogging = options.enableLogging;
|
|
14
|
+
}
|
|
15
|
+
log(...args) {
|
|
16
|
+
if (this.enableLogging) {
|
|
17
|
+
// eslint-disable-next-line no-console
|
|
18
|
+
console.log(...args);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
_defineProperty(Logger, "logger", void 0);
|
|
23
|
+
export function handleLoad(routes, location, routeManifest) {
|
|
24
|
+
if (!routeManifest || !routeManifest.enableFetchParallel === false) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const {
|
|
28
|
+
routeAssets
|
|
29
|
+
} = routeManifest;
|
|
30
|
+
Logger.getLogger({
|
|
31
|
+
enableLogging: routeManifest.enableLogging
|
|
32
|
+
}).log('handle page load');
|
|
33
|
+
const matches = matchClientRoutes(routes, location);
|
|
34
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach(match => loadRouteModule(match.route, routeAssets));
|
|
35
|
+
}
|
|
36
|
+
export function matchClientRoutes(routes, location) {
|
|
37
|
+
const matches = matchRoutes(routes, location);
|
|
38
|
+
return matches;
|
|
39
|
+
}
|
|
40
|
+
export async function loadRouteModule(route, routeAssets) {
|
|
41
|
+
const routeId = route.id;
|
|
42
|
+
if (!routeId) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!routeAssets[routeId]) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const {
|
|
49
|
+
chunkIds
|
|
50
|
+
} = routeAssets[routeId];
|
|
51
|
+
if (!chunkIds) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
await Promise.all(chunkIds.map(chunkId => {
|
|
56
|
+
return __webpack_chunk_load__(String(chunkId));
|
|
57
|
+
}));
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error(error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
const _excluded = ["Component"];
|
|
2
|
-
|
|
3
2
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
-
|
|
5
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
-
|
|
7
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
-
|
|
9
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
-
|
|
11
6
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
-
|
|
13
7
|
import React, { Suspense } from 'react';
|
|
14
8
|
import { Route } from 'react-router-dom';
|
|
15
9
|
import { DefaultNotFound } from "./DefaultNotFound";
|
|
10
|
+
import { RootLayout } from "./root";
|
|
16
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
-
|
|
18
12
|
const renderNestedRoute = (nestedRoute, parent) => {
|
|
19
13
|
const {
|
|
20
14
|
children,
|
|
@@ -37,27 +31,33 @@ const renderNestedRoute = (nestedRoute, parent) => {
|
|
|
37
31
|
index: nestedRoute.index,
|
|
38
32
|
errorElement: nestedRoute.errorElement
|
|
39
33
|
};
|
|
40
|
-
|
|
41
34
|
if (nestedRoute.error) {
|
|
42
35
|
const errorElement = /*#__PURE__*/_jsx(nestedRoute.error, {});
|
|
43
|
-
|
|
44
36
|
routeProps.errorElement = errorElement;
|
|
45
37
|
}
|
|
46
|
-
|
|
38
|
+
let element;
|
|
47
39
|
if (Component) {
|
|
48
40
|
if (parent !== null && parent !== void 0 && parent.loading) {
|
|
49
41
|
const Loading = parent.loading;
|
|
50
|
-
|
|
42
|
+
element = /*#__PURE__*/_jsx(Suspense, {
|
|
51
43
|
fallback: /*#__PURE__*/_jsx(Loading, {}),
|
|
52
44
|
children: /*#__PURE__*/_jsx(Component, {})
|
|
53
45
|
});
|
|
54
46
|
} else {
|
|
55
|
-
|
|
47
|
+
element = /*#__PURE__*/_jsx(Suspense, {
|
|
56
48
|
children: /*#__PURE__*/_jsx(Component, {})
|
|
57
49
|
});
|
|
58
50
|
}
|
|
59
51
|
}
|
|
60
|
-
|
|
52
|
+
if (!parent) {
|
|
53
|
+
element = /*#__PURE__*/_jsx(RootLayout, {
|
|
54
|
+
routes: [nestedRoute],
|
|
55
|
+
children: /*#__PURE__*/_jsx(Suspense, {
|
|
56
|
+
children: element
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
routeProps.element = element;
|
|
61
61
|
const routeElement = index ? /*#__PURE__*/_jsx(Route, _objectSpread(_objectSpread({}, routeProps), {}, {
|
|
62
62
|
index: true
|
|
63
63
|
}), id) : /*#__PURE__*/_jsx(Route, _objectSpread(_objectSpread({}, routeProps), {}, {
|
|
@@ -66,27 +66,21 @@ const renderNestedRoute = (nestedRoute, parent) => {
|
|
|
66
66
|
}), id);
|
|
67
67
|
return routeElement;
|
|
68
68
|
};
|
|
69
|
-
|
|
70
69
|
export function getRouteComponents(routes, globalApp) {
|
|
71
70
|
const Layout = _ref => {
|
|
72
71
|
let {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
Component
|
|
73
|
+
} = _ref,
|
|
74
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
77
75
|
const GlobalLayout = globalApp;
|
|
78
|
-
|
|
79
76
|
if (!GlobalLayout) {
|
|
80
77
|
return /*#__PURE__*/_jsx(Component, _objectSpread({}, props));
|
|
81
78
|
}
|
|
82
|
-
|
|
83
79
|
return /*#__PURE__*/_jsx(GlobalLayout, _objectSpread({
|
|
84
80
|
Component: Component
|
|
85
81
|
}, props));
|
|
86
82
|
};
|
|
87
|
-
|
|
88
83
|
const routeElements = [];
|
|
89
|
-
|
|
90
84
|
for (const route of routes) {
|
|
91
85
|
if (route.type === 'nested') {
|
|
92
86
|
const routeElement = renderNestedRoute(route);
|
|
@@ -98,11 +92,9 @@ export function getRouteComponents(routes, globalApp) {
|
|
|
98
92
|
Component: route.component
|
|
99
93
|
})
|
|
100
94
|
}, route.path);
|
|
101
|
-
|
|
102
95
|
routeElements.push(routeElement);
|
|
103
96
|
}
|
|
104
97
|
}
|
|
105
|
-
|
|
106
98
|
routeElements.push( /*#__PURE__*/_jsx(Route, {
|
|
107
99
|
path: "*",
|
|
108
100
|
element: /*#__PURE__*/_jsx(DefaultNotFound, {})
|
|
@@ -113,33 +105,27 @@ export function renderRoutes(routesConfig) {
|
|
|
113
105
|
if (!routesConfig) {
|
|
114
106
|
return null;
|
|
115
107
|
}
|
|
116
|
-
|
|
117
108
|
const {
|
|
118
109
|
routes,
|
|
119
110
|
globalApp
|
|
120
111
|
} = routesConfig;
|
|
121
|
-
|
|
122
112
|
if (!routes) {
|
|
123
113
|
return null;
|
|
124
114
|
}
|
|
125
|
-
|
|
126
115
|
const routeElements = getRouteComponents(routes, globalApp);
|
|
127
116
|
return routeElements;
|
|
128
117
|
}
|
|
129
118
|
export function getLocation(serverContext) {
|
|
130
119
|
var _url$replace;
|
|
131
|
-
|
|
132
120
|
const {
|
|
133
121
|
pathname,
|
|
134
122
|
url
|
|
135
123
|
} = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
|
|
136
124
|
const cleanUrl = url === null || url === void 0 ? void 0 : (_url$replace = url.replace('http://', '')) === null || _url$replace === void 0 ? void 0 : _url$replace.replace('https://', '');
|
|
137
125
|
const index = (cleanUrl || '').indexOf(pathname);
|
|
138
|
-
|
|
139
126
|
if (index === -1) {
|
|
140
127
|
return pathname;
|
|
141
128
|
}
|
|
142
|
-
|
|
143
129
|
return cleanUrl.substring(index);
|
|
144
130
|
}
|
|
145
131
|
export const urlJoin = (...parts) => {
|
|
@@ -149,22 +135,17 @@ export const urlJoin = (...parts) => {
|
|
|
149
135
|
};
|
|
150
136
|
export function standardSlash(str) {
|
|
151
137
|
let addr = str;
|
|
152
|
-
|
|
153
138
|
if (!addr || typeof addr !== 'string') {
|
|
154
139
|
return addr;
|
|
155
140
|
}
|
|
156
|
-
|
|
157
141
|
if (addr.startsWith('.')) {
|
|
158
142
|
addr = addr.slice(1);
|
|
159
143
|
}
|
|
160
|
-
|
|
161
144
|
if (!addr.startsWith('/')) {
|
|
162
145
|
addr = `/${addr}`;
|
|
163
146
|
}
|
|
164
|
-
|
|
165
147
|
if (addr.endsWith('/') && addr !== '/') {
|
|
166
148
|
addr = addr.slice(0, addr.length - 1);
|
|
167
149
|
}
|
|
168
|
-
|
|
169
150
|
return addr;
|
|
170
151
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
// legacy withRouter
|
|
5
|
+
|
|
8
6
|
import React from 'react';
|
|
9
7
|
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
|
10
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { getEntryOptions, SERVER_RENDER_FUNCTION_NAME, LOADABLE_STATS_FILE, isUseSSRBundle, createRuntimeExportsUtils, isSingleEntry } from '@modern-js/utils';
|
|
2
2
|
const PLUGIN_IDENTIFIER = 'ssr';
|
|
3
|
-
|
|
4
3
|
const hasStringSSREntry = userConfig => {
|
|
5
4
|
const isStreaming = ssr => ssr && typeof ssr === 'object' && ssr.mode === 'stream';
|
|
6
|
-
|
|
7
5
|
const {
|
|
8
6
|
server
|
|
9
7
|
} = userConfig;
|
|
10
|
-
|
|
11
8
|
if (server !== null && server !== void 0 && server.ssr && !isStreaming(server.ssr)) {
|
|
12
9
|
return true;
|
|
13
10
|
}
|
|
14
|
-
|
|
15
11
|
if (server !== null && server !== void 0 && server.ssrByEntries && typeof server.ssrByEntries === 'object') {
|
|
16
12
|
for (const name of Object.keys(server.ssrByEntries)) {
|
|
17
13
|
if (!isStreaming(server.ssrByEntries[name])) {
|
|
@@ -19,10 +15,8 @@ const hasStringSSREntry = userConfig => {
|
|
|
19
15
|
}
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
return false;
|
|
24
19
|
};
|
|
25
|
-
|
|
26
20
|
export default (() => ({
|
|
27
21
|
name: '@modern-js/plugin-ssr',
|
|
28
22
|
required: ['@modern-js/runtime'],
|
|
@@ -45,11 +39,9 @@ export default (() => ({
|
|
|
45
39
|
CHAIN_ID
|
|
46
40
|
}) => {
|
|
47
41
|
const userConfig = api.useResolvedConfigContext();
|
|
48
|
-
|
|
49
42
|
if (isUseSSRBundle(userConfig) && name !== 'server' && hasStringSSREntry(userConfig)) {
|
|
50
43
|
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
51
44
|
const LoadableWebpackPlugin = require('@loadable/webpack-plugin');
|
|
52
|
-
|
|
53
45
|
chain.plugin(CHAIN_ID.PLUGIN.LOADABLE).use(LoadableWebpackPlugin, [{
|
|
54
46
|
filename: LOADABLE_STATS_FILE
|
|
55
47
|
}]);
|
|
@@ -57,7 +49,6 @@ export default (() => ({
|
|
|
57
49
|
},
|
|
58
50
|
babel: config => {
|
|
59
51
|
const userConfig = api.useResolvedConfigContext();
|
|
60
|
-
|
|
61
52
|
if (isUseSSRBundle(userConfig) && hasStringSSREntry(userConfig)) {
|
|
62
53
|
config.plugins.push(require.resolve('@loadable/babel-plugin'));
|
|
63
54
|
}
|
|
@@ -65,7 +56,6 @@ export default (() => ({
|
|
|
65
56
|
}
|
|
66
57
|
};
|
|
67
58
|
},
|
|
68
|
-
|
|
69
59
|
modifyEntryImports({
|
|
70
60
|
entrypoint,
|
|
71
61
|
imports
|
|
@@ -79,28 +69,23 @@ export default (() => ({
|
|
|
79
69
|
packageName,
|
|
80
70
|
entrypoints
|
|
81
71
|
} = api.useAppContext();
|
|
82
|
-
pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/ssr'`);
|
|
72
|
+
pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/ssr'`);
|
|
83
73
|
|
|
74
|
+
// if use ssg then set ssr config to true
|
|
84
75
|
const ssrConfig = getEntryOptions(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
|
|
85
|
-
|
|
86
76
|
if (typeof ssrConfig === 'object' && ssrConfig.mode === 'stream') {
|
|
87
77
|
var _runtimeConfig$router;
|
|
88
|
-
|
|
89
78
|
const runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
90
|
-
|
|
91
79
|
if (runtimeConfig !== null && runtimeConfig !== void 0 && (_runtimeConfig$router = runtimeConfig.router) !== null && _runtimeConfig$router !== void 0 && _runtimeConfig$router.legacy) {
|
|
92
80
|
throw new Error(`Legacy router plugin doesn't support streaming SSR, check your config 'runtime.router'`);
|
|
93
81
|
}
|
|
94
|
-
|
|
95
82
|
if (fileSystemRoutes && !entrypoint.nestedRoutesEntry) {
|
|
96
83
|
throw new Error(`You should switch to file-system based router to support streaming SSR.`);
|
|
97
84
|
}
|
|
98
85
|
}
|
|
99
|
-
|
|
100
86
|
const ssgConfig = userConfig.output.ssg;
|
|
101
87
|
const useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig === null || ssgConfig === void 0 ? void 0 : ssgConfig[0]) === 'function' || Boolean(ssgConfig === null || ssgConfig === void 0 ? void 0 : ssgConfig[entryName]);
|
|
102
88
|
ssrConfigMap.set(entryName, ssrConfig || useSSG);
|
|
103
|
-
|
|
104
89
|
if (ssrConfig || useSSG) {
|
|
105
90
|
imports.push({
|
|
106
91
|
value: '@modern-js/runtime/plugins',
|
|
@@ -109,13 +94,11 @@ export default (() => ({
|
|
|
109
94
|
}]
|
|
110
95
|
});
|
|
111
96
|
}
|
|
112
|
-
|
|
113
97
|
return {
|
|
114
98
|
entrypoint,
|
|
115
99
|
imports
|
|
116
100
|
};
|
|
117
101
|
},
|
|
118
|
-
|
|
119
102
|
modifyEntryRuntimePlugins({
|
|
120
103
|
entrypoint,
|
|
121
104
|
plugins
|
|
@@ -126,13 +109,11 @@ export default (() => ({
|
|
|
126
109
|
options: JSON.stringify(ssrConfigMap.get(entrypoint.entryName))
|
|
127
110
|
});
|
|
128
111
|
}
|
|
129
|
-
|
|
130
112
|
return {
|
|
131
113
|
entrypoint,
|
|
132
114
|
plugins
|
|
133
115
|
};
|
|
134
116
|
},
|
|
135
|
-
|
|
136
117
|
modifyEntryExport({
|
|
137
118
|
entrypoint,
|
|
138
119
|
exportStatement
|
|
@@ -145,13 +126,11 @@ export default (() => ({
|
|
|
145
126
|
}`, exportStatement].join('\n')
|
|
146
127
|
};
|
|
147
128
|
}
|
|
148
|
-
|
|
149
129
|
return {
|
|
150
130
|
entrypoint,
|
|
151
131
|
exportStatement
|
|
152
132
|
};
|
|
153
133
|
}
|
|
154
|
-
|
|
155
134
|
};
|
|
156
135
|
}
|
|
157
136
|
}));
|