@modern-js/runtime 2.26.0 → 2.28.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 +30 -0
- package/dist/cjs/core/compatible.js +16 -17
- package/dist/cjs/core/loader/useLoader.js +10 -12
- package/dist/cjs/core/plugin.js +3 -2
- package/dist/cjs/document/Html.js +4 -3
- package/dist/cjs/document/cli/index.js +138 -138
- package/dist/cjs/router/cli/index.js +91 -92
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +4 -2
- package/dist/cjs/router/runtime/PrefetchLink.js +8 -4
- package/dist/cjs/router/runtime/plugin.js +4 -3
- package/dist/cjs/router/runtime/plugin.node.js +11 -4
- package/dist/cjs/router/runtime/utils.js +3 -3
- package/dist/cjs/ssr/cli/index.js +122 -123
- package/dist/cjs/ssr/index.js +105 -107
- package/dist/cjs/ssr/index.node.js +37 -38
- package/dist/cjs/ssr/prefetch.js +37 -39
- package/dist/cjs/ssr/react/prerender/util.js +4 -2
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +4 -2
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +8 -7
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +8 -6
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +2 -1
- package/dist/cjs/state/cli/index.js +70 -72
- package/dist/cjs/state/runtime/plugin.js +40 -42
- package/dist/esm/core/compatible.js +10 -9
- package/dist/esm/core/loader/useLoader.js +9 -9
- package/dist/esm/core/plugin.js +3 -2
- package/dist/esm/document/Html.js +4 -3
- package/dist/esm/document/cli/index.js +4 -3
- package/dist/esm/router/cli/index.js +2 -1
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +4 -2
- package/dist/esm/router/runtime/PrefetchLink.js +8 -4
- package/dist/esm/router/runtime/plugin.js +4 -3
- package/dist/esm/router/runtime/plugin.node.js +11 -4
- package/dist/esm/router/runtime/utils.js +3 -3
- package/dist/esm/ssr/cli/index.js +7 -6
- package/dist/esm/ssr/index.js +6 -6
- package/dist/esm/ssr/index.node.js +2 -1
- package/dist/esm/ssr/prefetch.js +2 -2
- package/dist/esm/ssr/react/prerender/util.js +4 -2
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +4 -2
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +8 -7
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +7 -7
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +2 -1
- package/dist/esm/state/runtime/plugin.js +2 -2
- package/dist/esm-node/core/compatible.js +16 -17
- package/dist/esm-node/core/loader/useLoader.js +10 -12
- package/dist/esm-node/core/plugin.js +3 -2
- package/dist/esm-node/document/Html.js +4 -3
- package/dist/esm-node/document/cli/index.js +138 -138
- package/dist/esm-node/router/cli/index.js +91 -92
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +4 -2
- package/dist/esm-node/router/runtime/PrefetchLink.js +8 -4
- package/dist/esm-node/router/runtime/plugin.js +4 -3
- package/dist/esm-node/router/runtime/plugin.node.js +11 -4
- package/dist/esm-node/router/runtime/utils.js +3 -3
- package/dist/esm-node/ssr/cli/index.js +122 -123
- package/dist/esm-node/ssr/cli/loadable-bundler-plugin.js +2 -2
- package/dist/esm-node/ssr/index.js +105 -107
- package/dist/esm-node/ssr/index.node.js +37 -38
- package/dist/esm-node/ssr/prefetch.js +37 -39
- package/dist/esm-node/ssr/react/prerender/util.js +4 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +4 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +8 -7
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +8 -6
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +2 -1
- package/dist/esm-node/state/cli/index.js +70 -72
- package/dist/esm-node/state/runtime/plugin.js +40 -42
- package/package.json +13 -10
|
@@ -19,80 +19,78 @@ _export(exports, {
|
|
|
19
19
|
});
|
|
20
20
|
const _utils = require("@modern-js/utils");
|
|
21
21
|
const PLUGIN_IDENTIFIER = "state";
|
|
22
|
-
const statePlugin = () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath()
|
|
39
|
-
}
|
|
22
|
+
const statePlugin = () => ({
|
|
23
|
+
name: "@modern-js/plugin-state",
|
|
24
|
+
required: [
|
|
25
|
+
"@modern-js/runtime"
|
|
26
|
+
],
|
|
27
|
+
setup: (api) => {
|
|
28
|
+
const stateConfigMap = /* @__PURE__ */ new Map();
|
|
29
|
+
let pluginsExportsUtils;
|
|
30
|
+
return {
|
|
31
|
+
config() {
|
|
32
|
+
const appContext = api.useAppContext();
|
|
33
|
+
pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, "plugins");
|
|
34
|
+
return {
|
|
35
|
+
source: {
|
|
36
|
+
alias: {
|
|
37
|
+
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath()
|
|
40
38
|
}
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
modifyEntryImports({ entrypoint, imports }) {
|
|
44
|
-
var _getEntryOptions;
|
|
45
|
-
const { entryName, isMainEntry } = entrypoint;
|
|
46
|
-
const userConfig = api.useResolvedConfigContext();
|
|
47
|
-
const { packageName } = api.useAppContext();
|
|
48
|
-
const stateConfig = (_getEntryOptions = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
49
|
-
stateConfigMap.set(entryName, stateConfig);
|
|
50
|
-
if (stateConfig) {
|
|
51
|
-
imports.push({
|
|
52
|
-
value: "@modern-js/runtime/plugins",
|
|
53
|
-
specifiers: [
|
|
54
|
-
{
|
|
55
|
-
imported: PLUGIN_IDENTIFIER
|
|
56
|
-
}
|
|
57
|
-
]
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
entrypoint,
|
|
62
|
-
imports
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
|
66
|
-
const stateOptions = stateConfigMap.get(entrypoint.entryName);
|
|
67
|
-
if (stateOptions) {
|
|
68
|
-
plugins.push({
|
|
69
|
-
name: PLUGIN_IDENTIFIER,
|
|
70
|
-
options: `${JSON.stringify(stateConfigMap.get(entrypoint.entryName))}`
|
|
71
|
-
});
|
|
72
39
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
modifyEntryImports({ entrypoint, imports }) {
|
|
43
|
+
var _getEntryOptions;
|
|
44
|
+
const { entryName, isMainEntry } = entrypoint;
|
|
45
|
+
const userConfig = api.useResolvedConfigContext();
|
|
46
|
+
const { packageName } = api.useAppContext();
|
|
47
|
+
const stateConfig = (_getEntryOptions = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
48
|
+
stateConfigMap.set(entryName, stateConfig);
|
|
49
|
+
if (stateConfig) {
|
|
50
|
+
imports.push({
|
|
51
|
+
value: "@modern-js/runtime/plugins",
|
|
52
|
+
specifiers: [
|
|
53
|
+
{
|
|
54
|
+
imported: PLUGIN_IDENTIFIER
|
|
87
55
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
entrypoint,
|
|
61
|
+
imports
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
|
65
|
+
const stateOptions = stateConfigMap.get(entrypoint.entryName);
|
|
66
|
+
if (stateOptions) {
|
|
67
|
+
plugins.push({
|
|
68
|
+
name: PLUGIN_IDENTIFIER,
|
|
69
|
+
options: `${JSON.stringify(stateConfigMap.get(entrypoint.entryName))}`
|
|
70
|
+
});
|
|
93
71
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
};
|
|
72
|
+
return {
|
|
73
|
+
entrypoint,
|
|
74
|
+
plugins
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
validateSchema() {
|
|
78
|
+
return [
|
|
79
|
+
{
|
|
80
|
+
target: "runtime.state",
|
|
81
|
+
schema: {
|
|
82
|
+
type: [
|
|
83
|
+
"boolean",
|
|
84
|
+
"object"
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
},
|
|
90
|
+
addRuntimeExports() {
|
|
91
|
+
pluginsExportsUtils.addExport(`export { default as state } from '@modern-js/runtime/model'`);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
});
|
|
98
96
|
const _default = statePlugin;
|
|
@@ -42,48 +42,46 @@ const getStoreConfig = (config) => {
|
|
|
42
42
|
storeConfig.plugins = plugins;
|
|
43
43
|
return storeConfig;
|
|
44
44
|
};
|
|
45
|
-
const state = (config) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
})
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
return next({
|
|
63
|
-
App: (0, _hoistnonreactstatics.default)(getStateApp, App)
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
init({ context }, next) {
|
|
67
|
-
if ((0, _common.isBrowser)()) {
|
|
68
|
-
var _window__SSR_DATA, _window__SSR_DATA_data;
|
|
69
|
-
storeConfig.initialState = storeConfig.initialState || (window === null || window === void 0 ? void 0 : (_window__SSR_DATA = window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_data = _window__SSR_DATA.data) === null || _window__SSR_DATA_data === void 0 ? void 0 : _window__SSR_DATA_data.storeState) || {};
|
|
70
|
-
}
|
|
71
|
-
context.store = (0, _store.createStore)(storeConfig);
|
|
72
|
-
return next({
|
|
73
|
-
context
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
pickContext({ context, pickedContext }, next) {
|
|
77
|
-
return next({
|
|
78
|
-
context,
|
|
79
|
-
pickedContext: {
|
|
80
|
-
...pickedContext,
|
|
81
|
-
store: context.store
|
|
82
|
-
}
|
|
45
|
+
const state = (config) => ({
|
|
46
|
+
name: "@modern-js/plugin-state",
|
|
47
|
+
setup: () => {
|
|
48
|
+
const storeConfig = getStoreConfig(config);
|
|
49
|
+
return {
|
|
50
|
+
hoc({ App }, next) {
|
|
51
|
+
const getStateApp = (props) => {
|
|
52
|
+
const context = (0, _react.useContext)(_core.RuntimeReactContext);
|
|
53
|
+
return /* @__PURE__ */ (0, _jsxruntime.jsx)(_react1.Provider, {
|
|
54
|
+
store: context.store,
|
|
55
|
+
config: storeConfig,
|
|
56
|
+
children: /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
|
57
|
+
...props
|
|
58
|
+
})
|
|
83
59
|
});
|
|
60
|
+
};
|
|
61
|
+
return next({
|
|
62
|
+
App: (0, _hoistnonreactstatics.default)(getStateApp, App)
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
init({ context }, next) {
|
|
66
|
+
if ((0, _common.isBrowser)()) {
|
|
67
|
+
var _window__SSR_DATA_data, _window__SSR_DATA, _window;
|
|
68
|
+
storeConfig.initialState = storeConfig.initialState || ((_window = window) === null || _window === void 0 ? void 0 : (_window__SSR_DATA = _window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_data = _window__SSR_DATA.data) === null || _window__SSR_DATA_data === void 0 ? void 0 : _window__SSR_DATA_data.storeState) || {};
|
|
84
69
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
70
|
+
context.store = (0, _store.createStore)(storeConfig);
|
|
71
|
+
return next({
|
|
72
|
+
context
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
pickContext({ context, pickedContext }, next) {
|
|
76
|
+
return next({
|
|
77
|
+
context,
|
|
78
|
+
pickedContext: {
|
|
79
|
+
...pickedContext,
|
|
80
|
+
store: context.store
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
89
87
|
const _default = state;
|
|
@@ -58,16 +58,17 @@ export var createApp = function(param) {
|
|
|
58
58
|
var context = _param.context, props = _object_without_properties(_param, [
|
|
59
59
|
"context"
|
|
60
60
|
]);
|
|
61
|
+
var _contextValue;
|
|
61
62
|
var contextValue = context;
|
|
62
|
-
if (!(contextValue === null ||
|
|
63
|
+
if (!((_contextValue = contextValue) === null || _contextValue === void 0 ? void 0 : _contextValue.runner)) {
|
|
63
64
|
contextValue = getInitialContext(runner);
|
|
64
65
|
runner.init({
|
|
65
66
|
context: contextValue
|
|
66
67
|
}, {
|
|
67
68
|
onLast: function(param3) {
|
|
68
69
|
var context1 = param3.context;
|
|
69
|
-
var _App_init;
|
|
70
|
-
return _$App === null ||
|
|
70
|
+
var _App_init, _App;
|
|
71
|
+
return (_App = _$App) === null || _App === void 0 ? void 0 : (_App_init = _App.init) === null || _App_init === void 0 ? void 0 : _App_init.call(_App, context1);
|
|
71
72
|
}
|
|
72
73
|
});
|
|
73
74
|
}
|
|
@@ -86,7 +87,7 @@ export var createApp = function(param) {
|
|
|
86
87
|
};
|
|
87
88
|
export var bootstrap = function() {
|
|
88
89
|
var _ref = _async_to_generator(function(BootApp, id, root, ReactDOM) {
|
|
89
|
-
var App, runner, context, runInit, isBrowser, _ssrData_data, _ssrData_data1, ssrData, loadersData, initialLoadersState, initialData, rootElement, ModernRender, ModernHydrate, isRedirectResponse, initialData1;
|
|
90
|
+
var App, runner, context, runInit, isBrowser, _ssrData_data, _ssrData, _ssrData1, _ssrData_data1, _ssrData2, ssrData, loadersData, initialLoadersState, initialData, rootElement, ModernRender, ModernHydrate, isRedirectResponse, initialData1;
|
|
90
91
|
return _ts_generator(this, function(_state) {
|
|
91
92
|
switch (_state.label) {
|
|
92
93
|
case 0:
|
|
@@ -105,8 +106,8 @@ export var bootstrap = function() {
|
|
|
105
106
|
}, {
|
|
106
107
|
onLast: function(param) {
|
|
107
108
|
var context1 = param.context;
|
|
108
|
-
var _App_init;
|
|
109
|
-
return App === null ||
|
|
109
|
+
var _App_init, _App;
|
|
110
|
+
return (_App = App) === null || _App === void 0 ? void 0 : (_App_init = _App.init) === null || _App_init === void 0 ? void 0 : _App_init.call(_App, context1);
|
|
110
111
|
}
|
|
111
112
|
});
|
|
112
113
|
};
|
|
@@ -130,7 +131,7 @@ export var bootstrap = function() {
|
|
|
130
131
|
2
|
|
131
132
|
];
|
|
132
133
|
ssrData = window._SSR_DATA;
|
|
133
|
-
loadersData = (ssrData === null ||
|
|
134
|
+
loadersData = ((_ssrData = ssrData) === null || _ssrData === void 0 ? void 0 : (_ssrData_data = _ssrData.data) === null || _ssrData_data === void 0 ? void 0 : _ssrData_data.loadersData) || {};
|
|
134
135
|
initialLoadersState = Object.keys(loadersData).reduce(function(res, key) {
|
|
135
136
|
var loaderData = loadersData[key];
|
|
136
137
|
if (loaderData.loading !== false) {
|
|
@@ -144,9 +145,9 @@ export var bootstrap = function() {
|
|
|
144
145
|
skipStatic: true
|
|
145
146
|
})
|
|
146
147
|
}, ssrData ? {
|
|
147
|
-
ssrContext: ssrData === null ||
|
|
148
|
+
ssrContext: (_ssrData1 = ssrData) === null || _ssrData1 === void 0 ? void 0 : _ssrData1.context
|
|
148
149
|
} : {}));
|
|
149
|
-
context.initialData = ssrData === null ||
|
|
150
|
+
context.initialData = (_ssrData2 = ssrData) === null || _ssrData2 === void 0 ? void 0 : (_ssrData_data1 = _ssrData2.data) === null || _ssrData_data1 === void 0 ? void 0 : _ssrData_data1.initialData;
|
|
150
151
|
return [
|
|
151
152
|
4,
|
|
152
153
|
runInit(context)
|
|
@@ -19,7 +19,7 @@ var useLoader = function(loaderFn) {
|
|
|
19
19
|
delete options._cache;
|
|
20
20
|
}
|
|
21
21
|
var load = useCallback(function(params) {
|
|
22
|
-
var _unlistenLoaderChangeRef_current, _window__SSR_DATA_data_loadersData_id, _window__SSR_DATA,
|
|
22
|
+
var _unlistenLoaderChangeRef_current, _unlistenLoaderChangeRef, _window__SSR_DATA_data_loadersData_id, _window__SSR_DATA_data, _window__SSR_DATA, _window, _loaderRef_current;
|
|
23
23
|
if (typeof params === "undefined") {
|
|
24
24
|
var _loaderRef_current1;
|
|
25
25
|
return (_loaderRef_current1 = loaderRef.current) === null || _loaderRef_current1 === void 0 ? void 0 : _loaderRef_current1.load();
|
|
@@ -38,26 +38,26 @@ var useLoader = function(loaderFn) {
|
|
|
38
38
|
params: params
|
|
39
39
|
}));
|
|
40
40
|
loaderRef.current = loaderManager.get(id);
|
|
41
|
-
(_unlistenLoaderChangeRef_current = unlistenLoaderChangeRef.current) === null || _unlistenLoaderChangeRef_current === void 0 ? void 0 : _unlistenLoaderChangeRef_current.call(
|
|
41
|
+
(_unlistenLoaderChangeRef_current = (_unlistenLoaderChangeRef = unlistenLoaderChangeRef).current) === null || _unlistenLoaderChangeRef_current === void 0 ? void 0 : _unlistenLoaderChangeRef_current.call(_unlistenLoaderChangeRef);
|
|
42
42
|
if (isSSRRender) {
|
|
43
43
|
return void 0;
|
|
44
44
|
}
|
|
45
45
|
if (options.skip) {
|
|
46
46
|
return void 0;
|
|
47
47
|
}
|
|
48
|
-
if (context._hydration && ((
|
|
48
|
+
if (context._hydration && ((_window = window) === null || _window === void 0 ? void 0 : (_window__SSR_DATA = _window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_data = _window__SSR_DATA.data) === null || _window__SSR_DATA_data === void 0 ? void 0 : (_window__SSR_DATA_data_loadersData_id = _window__SSR_DATA_data.loadersData[id]) === null || _window__SSR_DATA_data_loadersData_id === void 0 ? void 0 : _window__SSR_DATA_data_loadersData_id.error) === null) {
|
|
49
49
|
return void 0;
|
|
50
50
|
}
|
|
51
51
|
var res = loaderRef.current.load();
|
|
52
52
|
unlistenLoaderChangeRef.current = (_loaderRef_current = loaderRef.current) === null || _loaderRef_current === void 0 ? void 0 : _loaderRef_current.onChange(function(_status, _result) {
|
|
53
53
|
setResult(_result);
|
|
54
54
|
if (_status === LoaderStatus.fulfilled) {
|
|
55
|
-
var _options_onSuccess;
|
|
56
|
-
options === null ||
|
|
55
|
+
var _options_onSuccess, _options;
|
|
56
|
+
(_options = options) === null || _options === void 0 ? void 0 : (_options_onSuccess = _options.onSuccess) === null || _options_onSuccess === void 0 ? void 0 : _options_onSuccess.call(_options, _result.data);
|
|
57
57
|
}
|
|
58
58
|
if (_status === LoaderStatus.rejected) {
|
|
59
|
-
var _options_onError;
|
|
60
|
-
options === null ||
|
|
59
|
+
var _options_onError, _options1;
|
|
60
|
+
(_options1 = options) === null || _options1 === void 0 ? void 0 : (_options_onError = _options1.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(_options1, _result.error);
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
return res;
|
|
@@ -66,8 +66,8 @@ var useLoader = function(loaderFn) {
|
|
|
66
66
|
]);
|
|
67
67
|
useEffect(function() {
|
|
68
68
|
return function() {
|
|
69
|
-
var _unlistenLoaderChangeRef_current;
|
|
70
|
-
(_unlistenLoaderChangeRef_current = unlistenLoaderChangeRef.current) === null || _unlistenLoaderChangeRef_current === void 0 ? void 0 : _unlistenLoaderChangeRef_current.call(
|
|
69
|
+
var _unlistenLoaderChangeRef_current, _unlistenLoaderChangeRef;
|
|
70
|
+
(_unlistenLoaderChangeRef_current = (_unlistenLoaderChangeRef = unlistenLoaderChangeRef).current) === null || _unlistenLoaderChangeRef_current === void 0 ? void 0 : _unlistenLoaderChangeRef_current.call(_unlistenLoaderChangeRef);
|
|
71
71
|
};
|
|
72
72
|
}, []);
|
|
73
73
|
useMemo(function() {
|
package/dist/esm/core/plugin.js
CHANGED
|
@@ -23,6 +23,7 @@ var registerInit = function(App, _init) {
|
|
|
23
23
|
var originalInit = App.init;
|
|
24
24
|
App.init = function() {
|
|
25
25
|
var _ref = _async_to_generator(function(context) {
|
|
26
|
+
var _originalInit, _$_init;
|
|
26
27
|
return _ts_generator(this, function(_state) {
|
|
27
28
|
switch (_state.label) {
|
|
28
29
|
case 0:
|
|
@@ -32,8 +33,8 @@ var registerInit = function(App, _init) {
|
|
|
32
33
|
return [
|
|
33
34
|
4,
|
|
34
35
|
Promise.all([
|
|
35
|
-
originalInit === null ||
|
|
36
|
-
_init === null || _init === void 0 ? void 0 : _init(context)
|
|
36
|
+
(_originalInit = originalInit) === null || _originalInit === void 0 ? void 0 : _originalInit(context),
|
|
37
|
+
(_$_init = _init) === null || _$_init === void 0 ? void 0 : _$_init(context)
|
|
37
38
|
])
|
|
38
39
|
];
|
|
39
40
|
case 1:
|
|
@@ -11,7 +11,8 @@ function findTargetChild(tag, children) {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
function getEleType(ele) {
|
|
14
|
-
|
|
14
|
+
var _ele, _ele1;
|
|
15
|
+
return typeof ((_ele = ele) === null || _ele === void 0 ? void 0 : _ele.type) === "function" ? ele.type.name : (_ele1 = ele) === null || _ele1 === void 0 ? void 0 : _ele1.type;
|
|
15
16
|
}
|
|
16
17
|
function findTargetElement(tag, children) {
|
|
17
18
|
if (children.length === 0) {
|
|
@@ -22,11 +23,11 @@ function findTargetElement(tag, children) {
|
|
|
22
23
|
try {
|
|
23
24
|
for (var _iterator = children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
24
25
|
var item = _step.value;
|
|
25
|
-
var _item_props;
|
|
26
|
+
var _item_props, _item;
|
|
26
27
|
if (tag === getEleType(item)) {
|
|
27
28
|
return item;
|
|
28
29
|
}
|
|
29
|
-
if (item === null ||
|
|
30
|
+
if ((_item = item) === null || _item === void 0 ? void 0 : (_item_props = _item.props) === null || _item_props === void 0 ? void 0 : _item_props.children) {
|
|
30
31
|
nextChildren = nextChildren.concat(item.props.children);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -57,7 +57,7 @@ export var documentPlugin = function() {
|
|
|
57
57
|
}
|
|
58
58
|
return function() {
|
|
59
59
|
var _ref2 = _async_to_generator(function(param) {
|
|
60
|
-
var htmlWebpackPlugin, config, documentParams, tempTsConfigFile, userTsConfigFilePath, tsConfig, err, htmlOutputFile, Document, HTMLElement, html, scripts, links, metas, nonce, nonceAttr, finalHtml;
|
|
60
|
+
var htmlWebpackPlugin, _tsConfig, config, documentParams, tempTsConfigFile, userTsConfigFilePath, tsConfig, err, htmlOutputFile, Document, HTMLElement, html, scripts, links, metas, nonce, nonceAttr, finalHtml;
|
|
61
61
|
return _ts_generator(this, function(_state2) {
|
|
62
62
|
switch (_state2.label) {
|
|
63
63
|
case 0:
|
|
@@ -96,7 +96,7 @@ export var documentPlugin = function() {
|
|
|
96
96
|
4
|
|
97
97
|
];
|
|
98
98
|
case 4:
|
|
99
|
-
if (tsConfig === null ||
|
|
99
|
+
if ((_tsConfig = tsConfig) === null || _tsConfig === void 0 ? void 0 : _tsConfig.compilerOptions) {
|
|
100
100
|
tsConfig.compilerOptions.jsx = "react-jsx";
|
|
101
101
|
} else {
|
|
102
102
|
tsConfig.compilerOptions = {
|
|
@@ -210,7 +210,8 @@ export var documentPlugin = function() {
|
|
|
210
210
|
return {
|
|
211
211
|
tools: {
|
|
212
212
|
htmlPlugin: function(options, entry) {
|
|
213
|
-
var
|
|
213
|
+
var _options, _options1, _options2;
|
|
214
|
+
var hackParameters = typeof ((_options = options) === null || _options === void 0 ? void 0 : _options.templateParameters) === "function" ? (_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.templateParameters({}, {}, {}, {}) : _object_spread({}, (_options2 = options) === null || _options2 === void 0 ? void 0 : _options2.templateParameters);
|
|
214
215
|
var templateContent = documentEntry(
|
|
215
216
|
entry.entryName,
|
|
216
217
|
// options,
|
|
@@ -47,12 +47,13 @@ export var routerPlugin = function() {
|
|
|
47
47
|
},
|
|
48
48
|
modifyEntryImports: function modifyEntryImports(param) {
|
|
49
49
|
var entrypoint = param.entrypoint, imports = param.imports;
|
|
50
|
+
var _runtimeConfig;
|
|
50
51
|
var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
51
52
|
var userConfig = api.useResolvedConfigContext();
|
|
52
53
|
var packageName = api.useAppContext().packageName;
|
|
53
54
|
var runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
54
55
|
runtimeConfigMap.set(entryName, runtimeConfig);
|
|
55
|
-
if (runtimeConfig === null ||
|
|
56
|
+
if ((_runtimeConfig = runtimeConfig) === null || _runtimeConfig === void 0 ? void 0 : _runtimeConfig.router) {
|
|
56
57
|
if (!isV5(userConfig)) {
|
|
57
58
|
imports.push({
|
|
58
59
|
value: "@modern-js/runtime/plugins",
|
|
@@ -9,6 +9,7 @@ var setupFnStr = "function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA
|
|
|
9
9
|
var resolveFnStr = "function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};";
|
|
10
10
|
var preResolvedFnStr = "function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};";
|
|
11
11
|
var DeferredDataScripts = function(props) {
|
|
12
|
+
var _props;
|
|
12
13
|
var context = useContext(DataRouterContext);
|
|
13
14
|
var staticContext = (context || {}).staticContext;
|
|
14
15
|
var hydratedRef = useRef(false);
|
|
@@ -37,8 +38,9 @@ var DeferredDataScripts = function(props) {
|
|
|
37
38
|
var deferredKeys = deferredData.deferredKeys;
|
|
38
39
|
var deferredKeyPromiseStr = deferredKeys.map(function(key) {
|
|
39
40
|
if (pendingKeys.has(key)) {
|
|
41
|
+
var _props2;
|
|
40
42
|
deferredDataScripts.push(/* @__PURE__ */ _jsx(DeferredDataScript, {
|
|
41
|
-
nonce: props === null ||
|
|
43
|
+
nonce: (_props2 = props) === null || _props2 === void 0 ? void 0 : _props2.nonce,
|
|
42
44
|
data: deferredData.data[key],
|
|
43
45
|
dataKey: key,
|
|
44
46
|
routeId: routeId
|
|
@@ -74,7 +76,7 @@ var DeferredDataScripts = function(props) {
|
|
|
74
76
|
children: [
|
|
75
77
|
!hydratedRef.current && /* @__PURE__ */ _jsx("script", {
|
|
76
78
|
async: true,
|
|
77
|
-
nonce: props === null ||
|
|
79
|
+
nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce,
|
|
78
80
|
suppressHydrationWarning: true,
|
|
79
81
|
dangerouslySetInnerHTML: {
|
|
80
82
|
__html: deferredScripts[0]
|
|
@@ -9,7 +9,8 @@ import { Link as RouterLink, matchRoutes, useResolvedPath, useHref, useMatches,
|
|
|
9
9
|
import { RuntimeReactContext } from "../../core";
|
|
10
10
|
export function composeEventHandlers(theirHandler, ourHandler) {
|
|
11
11
|
return function(event) {
|
|
12
|
-
|
|
12
|
+
var _theirHandler;
|
|
13
|
+
(_theirHandler = theirHandler) === null || _theirHandler === void 0 ? void 0 : _theirHandler(event);
|
|
13
14
|
if (!event.defaultPrevented) {
|
|
14
15
|
ourHandler(event);
|
|
15
16
|
}
|
|
@@ -98,7 +99,8 @@ function _loadRouteModule() {
|
|
|
98
99
|
return [
|
|
99
100
|
4,
|
|
100
101
|
Promise.all(chunkIds.map(function(chunkId) {
|
|
101
|
-
|
|
102
|
+
var _$__webpack_chunk_load__;
|
|
103
|
+
return (_$__webpack_chunk_load__ = __webpack_chunk_load__) === null || _$__webpack_chunk_load__ === void 0 ? void 0 : _$__webpack_chunk_load__(String(chunkId));
|
|
102
104
|
}))
|
|
103
105
|
];
|
|
104
106
|
case 2:
|
|
@@ -152,7 +154,8 @@ var PrefetchPageLinks = function(param) {
|
|
|
152
154
|
var routeAssets = (routeManifest || {}).routeAssets;
|
|
153
155
|
var matches = Array.isArray(routes) ? matchRoutes(routes, pathname) : [];
|
|
154
156
|
if (Array.isArray(matches) && routeAssets) {
|
|
155
|
-
|
|
157
|
+
var _matches;
|
|
158
|
+
(_matches = matches) === null || _matches === void 0 ? void 0 : _matches.forEach(function(match) {
|
|
156
159
|
return loadRouteModule(match.route, routeAssets);
|
|
157
160
|
});
|
|
158
161
|
}
|
|
@@ -170,7 +173,8 @@ var PrefetchDataLinks = function(param) {
|
|
|
170
173
|
var currentMatches = useMatches();
|
|
171
174
|
var basename = useHref("/");
|
|
172
175
|
var dataHrefs = useMemo(function() {
|
|
173
|
-
|
|
176
|
+
var _matches;
|
|
177
|
+
return (_matches = matches) === null || _matches === void 0 ? void 0 : _matches.filter(function(match, index) {
|
|
174
178
|
if (!match.route.loader || typeof match.route.loader !== "function" || match.route.loader.length === 0) {
|
|
175
179
|
return false;
|
|
176
180
|
}
|
|
@@ -56,6 +56,7 @@ export var routerPlugin = function(param) {
|
|
|
56
56
|
},
|
|
57
57
|
hoc: function(param2, next) {
|
|
58
58
|
var App = param2.App;
|
|
59
|
+
var _routesConfig;
|
|
59
60
|
if (!finalRouteConfig && !createRoutes) {
|
|
60
61
|
return next({
|
|
61
62
|
App: App
|
|
@@ -63,7 +64,7 @@ export var routerPlugin = function(param) {
|
|
|
63
64
|
}
|
|
64
65
|
var getRouteApp = function() {
|
|
65
66
|
return function(props) {
|
|
66
|
-
var _window__SERVER_DATA;
|
|
67
|
+
var _window__SERVER_DATA, _hydrationData;
|
|
67
68
|
beforeCreateRouter = false;
|
|
68
69
|
routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
|
|
69
70
|
routesConfig: finalRouteConfig,
|
|
@@ -74,7 +75,7 @@ export var routerPlugin = function(param) {
|
|
|
74
75
|
var baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
|
|
75
76
|
var _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
|
|
76
77
|
var hydrationData = window._ROUTER_DATA;
|
|
77
|
-
if (hydrationData === null ||
|
|
78
|
+
if ((_hydrationData = hydrationData) === null || _hydrationData === void 0 ? void 0 : _hydrationData.errors) {
|
|
78
79
|
hydrationData = _object_spread_props(_object_spread({}, hydrationData), {
|
|
79
80
|
errors: deserializeErrors(hydrationData.errors)
|
|
80
81
|
});
|
|
@@ -120,7 +121,7 @@ export var routerPlugin = function(param) {
|
|
|
120
121
|
if (App) {
|
|
121
122
|
RouteApp = hoistNonReactStatics(RouteApp, App);
|
|
122
123
|
}
|
|
123
|
-
if (routesConfig === null ||
|
|
124
|
+
if ((_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp) {
|
|
124
125
|
return next({
|
|
125
126
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
126
127
|
});
|
|
@@ -87,7 +87,7 @@ export var routerPlugin = function(param) {
|
|
|
87
87
|
init: function init(param2, next) {
|
|
88
88
|
var context = param2.context;
|
|
89
89
|
return _async_to_generator(function() {
|
|
90
|
-
var _context_ssrContext, request, ssrMode, nonce, baseUrl, _basename, routes, query, remixRequest, routerContext, router
|
|
90
|
+
var _context_ssrContext, request, ssrMode, nonce, baseUrl, _basename, routes, runner, query, remixRequest, routerContext, router;
|
|
91
91
|
return _ts_generator(this, function(_state) {
|
|
92
92
|
switch (_state.label) {
|
|
93
93
|
case 0:
|
|
@@ -109,6 +109,8 @@ export var routerPlugin = function(param) {
|
|
|
109
109
|
nonce: nonce
|
|
110
110
|
}
|
|
111
111
|
}));
|
|
112
|
+
runner = api.useHookRunners();
|
|
113
|
+
routes = runner.modifyRoutes(routes);
|
|
112
114
|
query = createStaticHandler(routes, {
|
|
113
115
|
basename: _basename
|
|
114
116
|
}).query;
|
|
@@ -130,8 +132,6 @@ export var routerPlugin = function(param) {
|
|
|
130
132
|
context.routerContext = routerContext;
|
|
131
133
|
context.routes = routes;
|
|
132
134
|
context.routeManifest = context.ssrContext.routeManifest;
|
|
133
|
-
runner = api.useHookRunners();
|
|
134
|
-
runner.modifyRoutes(routes);
|
|
135
135
|
return [
|
|
136
136
|
2,
|
|
137
137
|
next({
|
|
@@ -144,6 +144,7 @@ export var routerPlugin = function(param) {
|
|
|
144
144
|
},
|
|
145
145
|
hoc: function(param2, next) {
|
|
146
146
|
var App = param2.App;
|
|
147
|
+
var _routesConfig;
|
|
147
148
|
if (!routesConfig) {
|
|
148
149
|
return next({
|
|
149
150
|
App: App
|
|
@@ -162,7 +163,7 @@ export var routerPlugin = function(param) {
|
|
|
162
163
|
};
|
|
163
164
|
};
|
|
164
165
|
var RouteApp = getRouteApp();
|
|
165
|
-
if (routesConfig === null ||
|
|
166
|
+
if ((_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp) {
|
|
166
167
|
return next({
|
|
167
168
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
168
169
|
});
|
|
@@ -174,6 +175,12 @@ export var routerPlugin = function(param) {
|
|
|
174
175
|
pickContext: function(param2, next) {
|
|
175
176
|
var context = param2.context, pickedContext = param2.pickedContext;
|
|
176
177
|
var remixRouter = context.remixRouter;
|
|
178
|
+
if (!remixRouter) {
|
|
179
|
+
return next({
|
|
180
|
+
context: context,
|
|
181
|
+
pickedContext: pickedContext
|
|
182
|
+
});
|
|
183
|
+
}
|
|
177
184
|
var router = {
|
|
178
185
|
navigate: remixRouter.navigate,
|
|
179
186
|
get location() {
|
|
@@ -81,9 +81,9 @@ export function renderRoutes(param) {
|
|
|
81
81
|
return routeElements;
|
|
82
82
|
}
|
|
83
83
|
export function getLocation(serverContext) {
|
|
84
|
-
var _url_replace;
|
|
85
|
-
var _ref = (serverContext === null ||
|
|
86
|
-
var cleanUrl = (
|
|
84
|
+
var _serverContext, _url_replace, _url;
|
|
85
|
+
var _ref = ((_serverContext = serverContext) === null || _serverContext === void 0 ? void 0 : _serverContext.request) || {}, pathname = _ref.pathname, url = _ref.url;
|
|
86
|
+
var cleanUrl = (_url = url) === null || _url === void 0 ? void 0 : (_url_replace = _url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
|
|
87
87
|
var index = (cleanUrl || "").indexOf(pathname);
|
|
88
88
|
if (index === -1) {
|
|
89
89
|
return pathname;
|