@modern-js/runtime 2.63.7 → 2.64.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/dist/cjs/core/browser/index.js +6 -4
- package/dist/cjs/core/compat/hooks.js +80 -0
- package/dist/cjs/core/{plugin/runner.js → compat/index.js} +19 -19
- package/dist/cjs/core/compatible.js +15 -11
- package/dist/cjs/core/context/index.js +12 -2
- package/dist/cjs/core/context/runtime.js +1 -2
- package/dist/cjs/core/index.js +1 -4
- package/dist/cjs/core/plugin/base.js +0 -35
- package/dist/cjs/core/plugin/index.js +17 -17
- package/dist/cjs/core/plugin/types.js +16 -0
- package/dist/cjs/core/react/index.js +3 -3
- package/dist/cjs/core/server/requestHandler.js +4 -4
- package/dist/cjs/router/runtime/hooks.js +7 -7
- package/dist/cjs/router/runtime/plugin.js +107 -108
- package/dist/cjs/router/runtime/plugin.node.js +89 -91
- package/dist/esm/core/browser/index.js +9 -7
- package/dist/esm/core/compat/hooks.js +88 -0
- package/dist/esm/core/compat/index.js +20 -0
- package/dist/esm/core/compatible.js +17 -13
- package/dist/esm/core/context/index.js +9 -1
- package/dist/esm/core/context/runtime.js +2 -3
- package/dist/esm/core/index.js +1 -3
- package/dist/esm/core/plugin/base.js +0 -28
- package/dist/esm/core/plugin/index.js +14 -17
- package/dist/esm/core/plugin/types.js +0 -0
- package/dist/esm/core/react/index.js +4 -4
- package/dist/esm/core/server/requestHandler.js +6 -6
- package/dist/esm/router/runtime/hooks.js +5 -5
- package/dist/esm/router/runtime/plugin.js +114 -115
- package/dist/esm/router/runtime/plugin.node.js +112 -111
- package/dist/esm-node/core/browser/index.js +7 -5
- package/dist/esm-node/core/compat/hooks.js +54 -0
- package/dist/esm-node/core/compat/index.js +18 -0
- package/dist/esm-node/core/compatible.js +16 -12
- package/dist/esm-node/core/context/index.js +9 -1
- package/dist/esm-node/core/context/runtime.js +1 -2
- package/dist/esm-node/core/index.js +1 -3
- package/dist/esm-node/core/plugin/base.js +0 -24
- package/dist/esm-node/core/plugin/index.js +16 -14
- package/dist/esm-node/core/plugin/types.js +0 -0
- package/dist/esm-node/core/react/index.js +4 -4
- package/dist/esm-node/core/server/requestHandler.js +5 -5
- package/dist/esm-node/router/runtime/hooks.js +5 -5
- package/dist/esm-node/router/runtime/plugin.js +108 -109
- package/dist/esm-node/router/runtime/plugin.node.js +90 -92
- package/dist/types/core/browser/hydrate.d.ts +1 -1
- package/dist/types/core/compat/hooks.d.ts +4 -0
- package/dist/types/core/compat/index.d.ts +2 -0
- package/dist/types/core/compatible.d.ts +7 -6
- package/dist/types/core/context/index.d.ts +7 -2
- package/dist/types/core/context/runtime.d.ts +1 -3
- package/dist/types/core/index.d.ts +1 -2
- package/dist/types/core/plugin/base.d.ts +9 -33
- package/dist/types/core/plugin/index.d.ts +19 -12
- package/dist/types/core/plugin/types.d.ts +10 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/router/runtime/hooks.d.ts +7 -3
- package/dist/types/router/runtime/index.d.ts +1 -0
- package/dist/types/router/runtime/plugin.d.ts +5 -2
- package/dist/types/router/runtime/plugin.node.d.ts +5 -2
- package/package.json +10 -10
- package/dist/esm/core/plugin/runner.js +0 -17
- package/dist/esm-node/core/plugin/runner.js +0 -17
- package/dist/types/core/plugin/runner.d.ts +0 -9
|
@@ -7,36 +7,35 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
7
7
|
import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
|
|
8
8
|
import React, { useContext, useMemo } from "react";
|
|
9
9
|
import { hydrateRoot as ModernHydrateRoot } from "./browser/hydrate";
|
|
10
|
-
import { getGlobalAppInit } from "./context";
|
|
10
|
+
import { getGlobalAppInit, getGlobalInternalRuntimeContext } from "./context";
|
|
11
11
|
import { RuntimeReactContext } from "./context/runtime";
|
|
12
12
|
import { createLoaderManager } from "./loader/loaderManager";
|
|
13
13
|
import { registerPlugin } from "./plugin";
|
|
14
|
-
import { getGlobalRunner } from "./plugin/runner";
|
|
15
14
|
import { wrapRuntimeContextProvider } from "./react/wrapper";
|
|
16
15
|
var IS_REACT18 = process.env.IS_REACT18 === "true";
|
|
17
16
|
function isClientArgs(id) {
|
|
18
17
|
return typeof id === "string" || typeof HTMLElement !== "undefined" && _instanceof(id, HTMLElement);
|
|
19
18
|
}
|
|
20
|
-
var getInitialContext = function(
|
|
19
|
+
var getInitialContext = function() {
|
|
21
20
|
return {
|
|
22
21
|
loaderManager: createLoaderManager({}),
|
|
23
|
-
runner,
|
|
24
22
|
isBrowser: true,
|
|
25
23
|
routeManifest: typeof window !== "undefined" && window[ROUTE_MANIFEST]
|
|
26
24
|
};
|
|
27
25
|
};
|
|
28
26
|
var createApp = function(param) {
|
|
29
|
-
var plugins = param.plugins,
|
|
30
|
-
var
|
|
27
|
+
var plugins = param.plugins, globalProps = param.props;
|
|
28
|
+
var context = registerPlugin(plugins, {
|
|
31
29
|
plugins: []
|
|
32
|
-
}
|
|
30
|
+
});
|
|
31
|
+
var hooks = context.hooks;
|
|
33
32
|
return function(App) {
|
|
34
33
|
var WrapperComponent = function(props) {
|
|
35
34
|
return /* @__PURE__ */ React.createElement(App || React.Fragment, App ? _object_spread({}, props) : null, App ? props.children : React.Children.map(props.children, function(child) {
|
|
36
35
|
return /* @__PURE__ */ React.isValidElement(child) ? /* @__PURE__ */ React.cloneElement(child, _object_spread({}, child.props, props)) : child;
|
|
37
36
|
}));
|
|
38
37
|
};
|
|
39
|
-
var WrapperApp =
|
|
38
|
+
var WrapperApp = hooks.wrapRoot.call(WrapperComponent);
|
|
40
39
|
var WrapComponent = function(props) {
|
|
41
40
|
var mergedProps = _object_spread({}, props, globalProps);
|
|
42
41
|
return /* @__PURE__ */ _jsx(WrapperApp, _object_spread({}, mergedProps));
|
|
@@ -46,13 +45,16 @@ var createApp = function(param) {
|
|
|
46
45
|
};
|
|
47
46
|
var bootstrap = function() {
|
|
48
47
|
var _ref = _async_to_generator(function(BootApp, id, root, ReactDOM) {
|
|
49
|
-
var App,
|
|
48
|
+
var App, internalRuntimeContext, api, hooks, context, runBeforeRender, isBrowser, _ssrData_data, _ssrData_data1, ssrData, loadersData, initialLoadersState, initialData, rootElement, ModernRender, ModernHydrate;
|
|
50
49
|
return _ts_generator(this, function(_state) {
|
|
51
50
|
switch (_state.label) {
|
|
52
51
|
case 0:
|
|
53
52
|
App = BootApp;
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
internalRuntimeContext = getGlobalInternalRuntimeContext();
|
|
54
|
+
api = internalRuntimeContext.pluginAPI;
|
|
55
|
+
hooks = internalRuntimeContext.hooks;
|
|
56
|
+
context = getInitialContext();
|
|
57
|
+
api.updateRuntimeContext(context);
|
|
56
58
|
runBeforeRender = function() {
|
|
57
59
|
var _ref2 = _async_to_generator(function(context2) {
|
|
58
60
|
var init;
|
|
@@ -61,7 +63,7 @@ var bootstrap = function() {
|
|
|
61
63
|
case 0:
|
|
62
64
|
return [
|
|
63
65
|
4,
|
|
64
|
-
|
|
66
|
+
hooks.onBeforeRender.call(context2)
|
|
65
67
|
];
|
|
66
68
|
case 1:
|
|
67
69
|
_state2.sent();
|
|
@@ -208,8 +210,10 @@ var useRuntimeContext = function() {
|
|
|
208
210
|
request: (_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.request,
|
|
209
211
|
response: (_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : _context_ssrContext1.response
|
|
210
212
|
});
|
|
213
|
+
var internalRuntimeContext = getGlobalInternalRuntimeContext();
|
|
214
|
+
var hooks = internalRuntimeContext.hooks;
|
|
211
215
|
var memoizedContext = useMemo(function() {
|
|
212
|
-
return
|
|
216
|
+
return hooks.pickContext.call(pickedContext);
|
|
213
217
|
}, [
|
|
214
218
|
context
|
|
215
219
|
]);
|
|
@@ -7,6 +7,12 @@ function setGlobalContext(context) {
|
|
|
7
7
|
globalContext.appConfig = typeof context.appConfig === "function" ? context.appConfig() : context.appConfig;
|
|
8
8
|
globalContext.layoutApp = context.layoutApp;
|
|
9
9
|
}
|
|
10
|
+
function setGlobalInternalRuntimeContext(context) {
|
|
11
|
+
globalContext.internalRuntimeContext = context;
|
|
12
|
+
}
|
|
13
|
+
function getGlobalInternalRuntimeContext() {
|
|
14
|
+
return globalContext.internalRuntimeContext;
|
|
15
|
+
}
|
|
10
16
|
function getGlobalApp() {
|
|
11
17
|
return globalContext.App;
|
|
12
18
|
}
|
|
@@ -29,8 +35,10 @@ export {
|
|
|
29
35
|
getGlobalApp,
|
|
30
36
|
getGlobalAppConfig,
|
|
31
37
|
getGlobalAppInit,
|
|
38
|
+
getGlobalInternalRuntimeContext,
|
|
32
39
|
getGlobalLayoutApp,
|
|
33
40
|
getGlobalRoutes,
|
|
34
41
|
getInitialContext,
|
|
35
|
-
setGlobalContext
|
|
42
|
+
setGlobalContext,
|
|
43
|
+
setGlobalInternalRuntimeContext
|
|
36
44
|
};
|
|
@@ -3,11 +3,10 @@ import { createContext } from "react";
|
|
|
3
3
|
import { createLoaderManager } from "../loader/loaderManager";
|
|
4
4
|
var RuntimeReactContext = createContext({});
|
|
5
5
|
var ServerRouterContext = createContext({});
|
|
6
|
-
var getInitialContext = function(
|
|
7
|
-
var isBrowser = arguments.length >
|
|
6
|
+
var getInitialContext = function() {
|
|
7
|
+
var isBrowser = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true, routeManifest = arguments.length > 1 ? arguments[1] : void 0;
|
|
8
8
|
return {
|
|
9
9
|
loaderManager: createLoaderManager({}),
|
|
10
|
-
runner,
|
|
11
10
|
isBrowser,
|
|
12
11
|
routeManifest: routeManifest || typeof window !== "undefined" && window[ROUTE_MANIFEST]
|
|
13
12
|
};
|
package/dist/esm/core/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { runtime } from "./plugin";
|
|
2
1
|
import { defineConfig, getConfig, defineRuntimeConfig } from "./config";
|
|
3
2
|
export * from "./compatible";
|
|
4
3
|
import { RuntimeReactContext, ServerRouterContext } from "./context/runtime";
|
|
@@ -9,6 +8,5 @@ export {
|
|
|
9
8
|
ServerRouterContext,
|
|
10
9
|
defineConfig,
|
|
11
10
|
defineRuntimeConfig,
|
|
12
|
-
getConfig
|
|
13
|
-
runtime
|
|
11
|
+
getConfig
|
|
14
12
|
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createAsyncInterruptWorkflow, createContext, createManager, createSyncParallelWorkflow, createWaterfall } from "@modern-js/plugin";
|
|
2
|
-
var RuntimeConfigContext = createContext({});
|
|
3
|
-
var useRuntimeConfigContext = function() {
|
|
4
|
-
return RuntimeConfigContext.use().value;
|
|
5
|
-
};
|
|
6
|
-
var wrapRoot = createWaterfall();
|
|
7
|
-
var beforeRender = createAsyncInterruptWorkflow();
|
|
8
|
-
var pickContext = createWaterfall();
|
|
9
|
-
var modifyRuntimeConfig = createSyncParallelWorkflow();
|
|
10
|
-
var runtimeHooks = {
|
|
11
|
-
beforeRender,
|
|
12
|
-
wrapRoot,
|
|
13
|
-
pickContext,
|
|
14
|
-
modifyRuntimeConfig
|
|
15
|
-
};
|
|
16
|
-
var runtimePluginAPI = {
|
|
17
|
-
useRuntimeConfigContext
|
|
18
|
-
};
|
|
19
|
-
var createRuntime = function() {
|
|
20
|
-
return createManager(runtimeHooks, runtimePluginAPI);
|
|
21
|
-
};
|
|
22
|
-
var runtime = createRuntime();
|
|
23
|
-
export {
|
|
24
|
-
RuntimeConfigContext,
|
|
25
|
-
createRuntime,
|
|
26
|
-
runtime,
|
|
27
|
-
useRuntimeConfigContext
|
|
28
|
-
};
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
+
import { runtime } from "@modern-js/plugin-v2/runtime";
|
|
2
3
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
function
|
|
7
|
-
var runner = getGlobalRunner();
|
|
8
|
-
var configs = runner.modifyRuntimeConfig();
|
|
9
|
-
RuntimeConfigContext.set(merge.apply(void 0, [
|
|
10
|
-
{}
|
|
11
|
-
].concat(_to_consumable_array(configs))));
|
|
12
|
-
}
|
|
13
|
-
function registerPlugin(internalPlugins, runtimeConfig, customRuntime) {
|
|
14
|
-
var _instance;
|
|
4
|
+
import { compatPlugin } from "../compat";
|
|
5
|
+
import { handleSetupResult } from "../compat/hooks";
|
|
6
|
+
import { setGlobalInternalRuntimeContext } from "../context";
|
|
7
|
+
function registerPlugin(internalPlugins, runtimeConfig) {
|
|
15
8
|
var _ref = runtimeConfig || {}, _ref_plugins = _ref.plugins, plugins = _ref_plugins === void 0 ? [] : _ref_plugins;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
var runtimeContext = runtime.run({
|
|
10
|
+
plugins: [
|
|
11
|
+
compatPlugin()
|
|
12
|
+
].concat(_to_consumable_array(internalPlugins), _to_consumable_array(plugins)),
|
|
13
|
+
config: runtimeConfig || {},
|
|
14
|
+
handleSetupResult
|
|
15
|
+
}).runtimeContext;
|
|
16
|
+
setGlobalInternalRuntimeContext(runtimeContext);
|
|
17
|
+
return runtimeContext;
|
|
21
18
|
}
|
|
22
19
|
function mergeConfig(config) {
|
|
23
20
|
for (var _len = arguments.length, otherConfig = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
File without changes
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
2
2
|
import { isBrowser } from "../../common";
|
|
3
3
|
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
|
|
4
|
-
import { getGlobalApp } from "../context";
|
|
5
|
-
import { getGlobalRunner } from "../plugin/runner";
|
|
4
|
+
import { getGlobalApp, getGlobalInternalRuntimeContext } from "../context";
|
|
6
5
|
function createRoot(UserApp) {
|
|
7
6
|
var App = UserApp || getGlobalApp();
|
|
8
7
|
if (isBrowser()) {
|
|
9
8
|
window._SSR_DATA = window._SSR_DATA || parsedJSONFromElement(SSR_DATA_JSON_ID);
|
|
10
9
|
window._ROUTER_DATA = window._ROUTER_DATA || parsedJSONFromElement(ROUTER_DATA_JSON_ID);
|
|
11
10
|
}
|
|
12
|
-
var
|
|
13
|
-
var
|
|
11
|
+
var internalRuntimeContext = getGlobalInternalRuntimeContext();
|
|
12
|
+
var hooks = internalRuntimeContext.hooks;
|
|
13
|
+
var WrapperApp = hooks.wrapRoot.call(App);
|
|
14
14
|
return WrapperApp;
|
|
15
15
|
}
|
|
16
16
|
export {
|
|
@@ -6,10 +6,9 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
|
6
6
|
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
7
7
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
8
8
|
import { getPathname, parseCookie, parseHeaders, parseQuery } from "@modern-js/runtime-utils/universal/request";
|
|
9
|
-
import { getGlobalAppInit } from "../context";
|
|
9
|
+
import { getGlobalAppInit, getGlobalInternalRuntimeContext } from "../context";
|
|
10
10
|
import { getInitialContext } from "../context/runtime";
|
|
11
11
|
import { createLoaderManager } from "../loader/loaderManager";
|
|
12
|
-
import { getGlobalRunner } from "../plugin/runner";
|
|
13
12
|
import { createRoot } from "../react";
|
|
14
13
|
import { CHUNK_CSS_PLACEHOLDER } from "./constants";
|
|
15
14
|
import { getSSRConfigByEntry, getSSRMode } from "./utils";
|
|
@@ -75,14 +74,15 @@ var createRequestHandler = function() {
|
|
|
75
74
|
return _ts_generator(this, function(_state) {
|
|
76
75
|
requestHandler = function() {
|
|
77
76
|
var _ref2 = _async_to_generator(function(request, options) {
|
|
78
|
-
var _context_routerContext, _context_routerContext1, Root,
|
|
77
|
+
var _context_routerContext, _context_routerContext1, Root, internalRuntimeContext, hooks, routeManifest, context, runBeforeRender, responseProxy, ssrContext, getRedirectResponse, initialData, _context_routerContext2, _context_ssrContext, redirectResponse, htmlTemplate, response;
|
|
79
78
|
return _ts_generator(this, function(_state2) {
|
|
80
79
|
switch (_state2.label) {
|
|
81
80
|
case 0:
|
|
82
81
|
Root = createRoot();
|
|
83
|
-
|
|
82
|
+
internalRuntimeContext = getGlobalInternalRuntimeContext();
|
|
83
|
+
hooks = internalRuntimeContext.hooks;
|
|
84
84
|
routeManifest = options.resource.routeManifest;
|
|
85
|
-
context = getInitialContext(
|
|
85
|
+
context = getInitialContext(false, routeManifest);
|
|
86
86
|
runBeforeRender = function() {
|
|
87
87
|
var _ref3 = _async_to_generator(function(context2) {
|
|
88
88
|
var result, init;
|
|
@@ -91,7 +91,7 @@ var createRequestHandler = function() {
|
|
|
91
91
|
case 0:
|
|
92
92
|
return [
|
|
93
93
|
4,
|
|
94
|
-
|
|
94
|
+
hooks.onBeforeRender.call(context2)
|
|
95
95
|
];
|
|
96
96
|
case 1:
|
|
97
97
|
result = _state3.sent();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
var modifyRoutes =
|
|
3
|
-
var
|
|
1
|
+
import { createSyncHook } from "@modern-js/plugin-v2";
|
|
2
|
+
var modifyRoutes = createSyncHook();
|
|
3
|
+
var onBeforeCreateRoutes = createSyncHook();
|
|
4
4
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
modifyRoutes,
|
|
6
|
+
onBeforeCreateRoutes
|
|
7
7
|
};
|
|
@@ -8,7 +8,7 @@ import { normalizePathname } from "@modern-js/runtime-utils/url";
|
|
|
8
8
|
import { useContext, useMemo } from "react";
|
|
9
9
|
import { RuntimeReactContext } from "../../core";
|
|
10
10
|
import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
|
|
11
|
-
import { modifyRoutes as modifyRoutesHook } from "./hooks";
|
|
11
|
+
import { modifyRoutes as modifyRoutesHook, onBeforeCreateRoutes as onBeforeCreateRoutesHook } from "./hooks";
|
|
12
12
|
import { deserializeErrors, renderRoutes, urlJoin } from "./utils";
|
|
13
13
|
var finalRouteConfig = {
|
|
14
14
|
routes: []
|
|
@@ -27,128 +27,127 @@ var routerPlugin = function() {
|
|
|
27
27
|
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
28
28
|
return {
|
|
29
29
|
name: "@modern-js/plugin-router",
|
|
30
|
-
|
|
31
|
-
modifyRoutes: modifyRoutesHook
|
|
30
|
+
registryHooks: {
|
|
31
|
+
modifyRoutes: modifyRoutesHook,
|
|
32
|
+
onBeforeCreateRoutes: onBeforeCreateRoutesHook
|
|
32
33
|
},
|
|
33
34
|
setup: function(api) {
|
|
34
35
|
var routes = [];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
window.location.reload();
|
|
46
|
-
}
|
|
36
|
+
api.onBeforeRender(function(context) {
|
|
37
|
+
if (window._SSR_DATA && userConfig.unstable_reloadOnURLMismatch) {
|
|
38
|
+
var _ssrContext_request;
|
|
39
|
+
var ssrContext = context.ssrContext;
|
|
40
|
+
var currentPathname = normalizePathname(window.location.pathname);
|
|
41
|
+
var initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && normalizePathname(ssrContext.request.pathname);
|
|
42
|
+
if (initialPathname && initialPathname !== currentPathname) {
|
|
43
|
+
var errorMsg = "The initial URL ".concat(initialPathname, " and the URL ").concat(currentPathname, " to be hydrated do not match, reload.");
|
|
44
|
+
console.error(errorMsg);
|
|
45
|
+
window.location.reload();
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
wrapRoot: function(App) {
|
|
60
|
-
var pluginConfig = api.useRuntimeConfigContext();
|
|
61
|
-
var _merge = merge(pluginConfig.router || {}, userConfig), _merge_serverBase = _merge.serverBase, serverBase = _merge_serverBase === void 0 ? [] : _merge_serverBase, _merge_supportHtml5History = _merge.supportHtml5History, supportHtml5History = _merge_supportHtml5History === void 0 ? true : _merge_supportHtml5History, _merge_basename = _merge.basename, basename = _merge_basename === void 0 ? "" : _merge_basename, routesConfig = _merge.routesConfig, createRoutes = _merge.createRoutes, future = _merge.future;
|
|
62
|
-
var select = function(pathname) {
|
|
63
|
-
return serverBase.find(function(baseUrl) {
|
|
64
|
-
return pathname.search(baseUrl) === 0;
|
|
65
|
-
}) || "/";
|
|
66
|
-
};
|
|
67
|
-
finalRouteConfig = _object_spread({
|
|
68
|
-
routes: getGlobalRoutes(),
|
|
69
|
-
globalApp: getGlobalLayoutApp()
|
|
70
|
-
}, routesConfig);
|
|
71
|
-
if (!finalRouteConfig.routes && !createRoutes) {
|
|
72
|
-
return App;
|
|
47
|
+
}
|
|
48
|
+
context.router = {
|
|
49
|
+
useMatches,
|
|
50
|
+
useLocation,
|
|
51
|
+
useHref
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(context, "routes", {
|
|
54
|
+
get: function get() {
|
|
55
|
+
return routes;
|
|
73
56
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
api.wrapRoot(function(App) {
|
|
60
|
+
var pluginConfig = api.getRuntimeConfig();
|
|
61
|
+
var _merge = merge(pluginConfig.router || {}, userConfig), _merge_serverBase = _merge.serverBase, serverBase = _merge_serverBase === void 0 ? [] : _merge_serverBase, _merge_supportHtml5History = _merge.supportHtml5History, supportHtml5History = _merge_supportHtml5History === void 0 ? true : _merge_supportHtml5History, _merge_basename = _merge.basename, basename = _merge_basename === void 0 ? "" : _merge_basename, routesConfig = _merge.routesConfig, createRoutes = _merge.createRoutes, future = _merge.future;
|
|
62
|
+
var select = function(pathname) {
|
|
63
|
+
return serverBase.find(function(baseUrl) {
|
|
64
|
+
return pathname.search(baseUrl) === 0;
|
|
65
|
+
}) || "/";
|
|
66
|
+
};
|
|
67
|
+
finalRouteConfig = _object_spread({
|
|
68
|
+
routes: getGlobalRoutes(),
|
|
69
|
+
globalApp: getGlobalLayoutApp()
|
|
70
|
+
}, routesConfig);
|
|
71
|
+
if (!finalRouteConfig.routes && !createRoutes) {
|
|
72
|
+
return App;
|
|
73
|
+
}
|
|
74
|
+
var getRouteApp = function() {
|
|
75
|
+
var useCreateRouter = function(props) {
|
|
76
|
+
var runtimeContext = useContext(RuntimeReactContext);
|
|
77
|
+
var baseUrl = select(location.pathname).replace(/^\/*/, "/");
|
|
78
|
+
var _basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
|
|
79
|
+
var hydrationData = window._ROUTER_DATA;
|
|
80
|
+
var getBlockNavState = runtimeContext.unstable_getBlockNavState;
|
|
81
|
+
return useMemo(function() {
|
|
82
|
+
if (hydrationData === null || hydrationData === void 0 ? void 0 : hydrationData.errors) {
|
|
83
|
+
hydrationData = _object_spread_props(_object_spread({}, hydrationData), {
|
|
84
|
+
errors: deserializeErrors(hydrationData.errors)
|
|
99
85
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
86
|
+
}
|
|
87
|
+
routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
|
|
88
|
+
routesConfig: finalRouteConfig,
|
|
89
|
+
props
|
|
90
|
+
}));
|
|
91
|
+
var hooks = api.getHooks();
|
|
92
|
+
routes = hooks.modifyRoutes.call(routes);
|
|
93
|
+
var router = supportHtml5History ? createBrowserRouter(routes, {
|
|
94
|
+
basename: _basename,
|
|
95
|
+
hydrationData
|
|
96
|
+
}) : createHashRouter(routes, {
|
|
97
|
+
basename: _basename,
|
|
98
|
+
hydrationData
|
|
99
|
+
});
|
|
100
|
+
var originSubscribe = router.subscribe;
|
|
101
|
+
router.subscribe = function(listener) {
|
|
102
|
+
var wrapedListener = function() {
|
|
103
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
104
|
+
args[_key] = arguments[_key];
|
|
105
|
+
}
|
|
106
|
+
var blockRoute = getBlockNavState ? getBlockNavState() : false;
|
|
107
|
+
if (blockRoute) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
return listener.apply(void 0, _to_consumable_array(args));
|
|
113
111
|
};
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return null;
|
|
125
|
-
};
|
|
126
|
-
return function(props) {
|
|
127
|
-
beforeCreateRouter = false;
|
|
128
|
-
var router = useCreateRouter(props);
|
|
129
|
-
var routerWrapper = (
|
|
130
|
-
// To match the node tree about https://github.com/web-infra-dev/modern.js/blob/v2.59.0/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx#L150-L168
|
|
131
|
-
// According to react [useId generation algorithm](https://github.com/facebook/react/pull/22644), `useId` will generate id with the react node react struct.
|
|
132
|
-
// To void hydration failed, we must guarantee that the node tree when browser hydrate must have same struct with node tree when ssr render.
|
|
133
|
-
/* @__PURE__ */ _jsxs(_Fragment, {
|
|
134
|
-
children: [
|
|
135
|
-
/* @__PURE__ */ _jsx(RouterProvider, {
|
|
136
|
-
router,
|
|
137
|
-
future
|
|
138
|
-
}),
|
|
139
|
-
/* @__PURE__ */ _jsx(Null, {}),
|
|
140
|
-
/* @__PURE__ */ _jsx(Null, {})
|
|
141
|
-
]
|
|
142
|
-
})
|
|
143
|
-
);
|
|
144
|
-
return App ? /* @__PURE__ */ _jsx(App, {
|
|
145
|
-
children: routerWrapper
|
|
146
|
-
}) : routerWrapper;
|
|
147
|
-
};
|
|
112
|
+
return originSubscribe(wrapedListener);
|
|
113
|
+
};
|
|
114
|
+
return router;
|
|
115
|
+
}, [
|
|
116
|
+
finalRouteConfig,
|
|
117
|
+
props,
|
|
118
|
+
_basename,
|
|
119
|
+
hydrationData,
|
|
120
|
+
getBlockNavState
|
|
121
|
+
]);
|
|
148
122
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
123
|
+
var Null = function() {
|
|
124
|
+
return null;
|
|
125
|
+
};
|
|
126
|
+
return function(props) {
|
|
127
|
+
beforeCreateRouter = false;
|
|
128
|
+
var router = useCreateRouter(props);
|
|
129
|
+
var routerWrapper = (
|
|
130
|
+
// To match the node tree about https://github.com/web-infra-dev/modern.js/blob/v2.59.0/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx#L150-L168
|
|
131
|
+
// According to react [useId generation algorithm](https://github.com/facebook/react/pull/22644), `useId` will generate id with the react node react struct.
|
|
132
|
+
// To void hydration failed, we must guarantee that the node tree when browser hydrate must have same struct with node tree when ssr render.
|
|
133
|
+
/* @__PURE__ */ _jsxs(_Fragment, {
|
|
134
|
+
children: [
|
|
135
|
+
/* @__PURE__ */ _jsx(RouterProvider, {
|
|
136
|
+
router,
|
|
137
|
+
future
|
|
138
|
+
}),
|
|
139
|
+
/* @__PURE__ */ _jsx(Null, {}),
|
|
140
|
+
/* @__PURE__ */ _jsx(Null, {})
|
|
141
|
+
]
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
return App ? /* @__PURE__ */ _jsx(App, {
|
|
145
|
+
children: routerWrapper
|
|
146
|
+
}) : routerWrapper;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
return getRouteApp();
|
|
150
|
+
});
|
|
152
151
|
}
|
|
153
152
|
};
|
|
154
153
|
};
|