@modern-js/runtime 1.4.3 → 1.15.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 +43 -0
- package/dist/js/modern/cli/index.js +1 -3
- package/dist/js/modern/core/app-config.js +10 -0
- package/dist/js/modern/core/compatible.js +218 -0
- package/dist/js/modern/core/index.js +7 -0
- package/dist/js/modern/core/loader/index.js +1 -0
- package/dist/js/modern/core/loader/loaderManager.js +189 -0
- package/dist/js/modern/core/loader/useLoader.js +105 -0
- package/dist/js/modern/core/plugin.js +63 -0
- package/dist/js/modern/core/runtime-context.js +2 -0
- package/dist/js/modern/exports/styled.js +2 -2
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/router/runtime/plugin.js +1 -1
- package/dist/js/modern/router/runtime/utils.js +3 -1
- package/dist/js/modern/ssr/index.js +4 -0
- package/dist/js/modern/ssr/index.node.js +1 -1
- package/dist/js/modern/ssr/prefetch.js +2 -2
- package/dist/js/modern/ssr/serverRender/index.js +1 -1
- package/dist/js/modern/ssr/serverRender/styledComponent.js +1 -1
- package/dist/js/modern/ssr/utils.js +9 -3
- package/dist/js/modern/state/cli/index.js +1 -1
- package/dist/js/modern/state/runtime/plugin.js +1 -1
- package/dist/js/node/cli/index.js +1 -3
- package/dist/js/node/core/app-config.js +22 -0
- package/dist/js/node/core/compatible.js +247 -0
- package/dist/js/node/core/index.js +111 -0
- package/dist/js/node/core/loader/index.js +15 -0
- package/dist/js/node/core/loader/loaderManager.js +201 -0
- package/dist/js/node/core/loader/useLoader.js +118 -0
- package/dist/js/node/core/plugin.js +79 -0
- package/dist/js/node/core/runtime-context.js +11 -0
- package/dist/js/node/exports/styled.js +5 -5
- package/dist/js/node/index.js +10 -10
- package/dist/js/node/router/runtime/plugin.js +3 -3
- package/dist/js/node/router/runtime/utils.js +3 -1
- package/dist/js/node/ssr/index.js +4 -0
- package/dist/js/node/ssr/index.node.js +2 -2
- package/dist/js/node/ssr/serverRender/index.js +2 -2
- package/dist/js/node/ssr/serverRender/styledComponent.js +2 -2
- package/dist/js/node/ssr/utils.js +9 -3
- package/dist/js/node/state/cli/index.js +1 -1
- package/dist/js/node/state/runtime/plugin.js +3 -3
- package/dist/js/treeshaking/cli/index.js +1 -3
- package/dist/js/treeshaking/core/app-config.js +13 -0
- package/dist/js/treeshaking/core/compatible.js +255 -0
- package/dist/js/treeshaking/core/index.js +7 -0
- package/dist/js/treeshaking/core/loader/index.js +1 -0
- package/dist/js/treeshaking/core/loader/loaderManager.js +267 -0
- package/dist/js/treeshaking/core/loader/useLoader.js +107 -0
- package/dist/js/treeshaking/core/plugin.js +105 -0
- package/dist/js/treeshaking/core/runtime-context.js +2 -0
- package/dist/js/treeshaking/exports/styled.js +2 -2
- package/dist/js/treeshaking/index.js +1 -1
- package/dist/js/treeshaking/router/runtime/plugin.js +1 -1
- package/dist/js/treeshaking/router/runtime/utils.js +3 -1
- package/dist/js/treeshaking/ssr/index.js +4 -0
- package/dist/js/treeshaking/ssr/index.node.js +1 -1
- package/dist/js/treeshaking/ssr/prefetch.js +2 -2
- package/dist/js/treeshaking/ssr/serverRender/index.js +1 -1
- package/dist/js/treeshaking/ssr/serverRender/styledComponent.js +1 -1
- package/dist/js/treeshaking/ssr/utils.js +8 -3
- package/dist/js/treeshaking/state/cli/index.js +1 -1
- package/dist/js/treeshaking/state/runtime/plugin.js +1 -1
- package/dist/types/core/app-config.d.ts +6 -0
- package/dist/types/core/compatible.d.ts +13 -0
- package/dist/types/core/index.d.ts +9 -0
- package/dist/types/core/loader/index.d.ts +2 -0
- package/dist/types/core/loader/loaderManager.d.ts +57 -0
- package/dist/types/core/loader/useLoader.d.ts +54 -0
- package/dist/types/core/plugin.d.ts +208 -0
- package/dist/types/core/runtime-context.d.ts +13 -0
- package/dist/types/exports/styled.d.ts +2 -2
- package/dist/types/index.d.ts +4 -9
- package/dist/types/router/runtime/plugin.d.ts +1 -1
- package/dist/types/ssr/index.d.ts +2 -2
- package/dist/types/ssr/index.node.d.ts +1 -1
- package/dist/types/ssr/prefetch.d.ts +2 -2
- package/dist/types/ssr/serverRender/entry.d.ts +1 -1
- package/dist/types/ssr/serverRender/index.d.ts +1 -1
- package/dist/types/ssr/serverRender/type.d.ts +1 -1
- package/dist/types/state/runtime/plugin.d.ts +2 -2
- package/lib/types.d.ts +10 -0
- package/package.json +36 -26
|
@@ -67,11 +67,13 @@ export function renderRoutes(routesConfig, extraProps = {}) {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
export function getLocation(serverContext) {
|
|
70
|
+
var _url$replace;
|
|
71
|
+
|
|
70
72
|
const {
|
|
71
73
|
pathname,
|
|
72
74
|
url
|
|
73
75
|
} = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
|
|
74
|
-
const cleanUrl = url.replace('http://', '').replace('https://', '');
|
|
76
|
+
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://', '');
|
|
75
77
|
const index = (cleanUrl || '').indexOf(pathname);
|
|
76
78
|
|
|
77
79
|
if (index === -1) {
|
|
@@ -60,6 +60,10 @@ const ssr = () => ({
|
|
|
60
60
|
const request = (_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$_SSR_DATA = _window2._SSR_DATA) === null || _window2$_SSR_DATA === void 0 ? void 0 : (_window2$_SSR_DATA$co = _window2$_SSR_DATA.context) === null || _window2$_SSR_DATA$co === void 0 ? void 0 : _window2$_SSR_DATA$co.request;
|
|
61
61
|
|
|
62
62
|
if (!request) {
|
|
63
|
+
context.ssrContext = _objectSpread(_objectSpread({}, context.ssrContext), {}, {
|
|
64
|
+
response: mockResp,
|
|
65
|
+
request: formatClient({})
|
|
66
|
+
});
|
|
63
67
|
return next({
|
|
64
68
|
context
|
|
65
69
|
});
|
|
@@ -8,7 +8,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
8
8
|
|
|
9
9
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
10
10
|
import path from 'path';
|
|
11
|
-
import { registerPrefetch } from
|
|
11
|
+
import { registerPrefetch } from "../core";
|
|
12
12
|
import { isBrowser } from "../common";
|
|
13
13
|
import prefetch from "./prefetch";
|
|
14
14
|
import { formatServer } from "./utils";
|
|
@@ -3,10 +3,10 @@ import fs from 'fs';
|
|
|
3
3
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
4
4
|
import { run } from '@modern-js/utils/ssr';
|
|
5
5
|
import { LOADABLE_STATS_FILE } from '@modern-js/utils/constants';
|
|
6
|
-
import { ChunkExtractor } from '@loadable/server';
|
|
7
|
-
|
|
6
|
+
import { ChunkExtractor } from '@loadable/server';
|
|
8
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
8
|
|
|
9
|
+
// todo: SSRContext
|
|
10
10
|
const prefetch = async (App, context) => run(context.ssrContext.request.headers, async () => {
|
|
11
11
|
var _context$store;
|
|
12
12
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RuntimeContext } from '@modern-js/runtime-core';
|
|
2
1
|
import { run } from '@modern-js/utils/ssr';
|
|
2
|
+
import { RuntimeContext } from "../../core";
|
|
3
3
|
import { PreRender } from "../react/prerender";
|
|
4
4
|
import SSREntry from "./entry";
|
|
5
5
|
import { time } from "./measure";
|
|
@@ -19,19 +19,25 @@ export const formatServer = request => {
|
|
|
19
19
|
|
|
20
20
|
const getQuery = () => window.location.search.substring(1).split('&').reduce((res, item) => {
|
|
21
21
|
const [key, value] = item.split('=');
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
if (key) {
|
|
24
|
+
res[key] = value;
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
return res;
|
|
24
28
|
}, {});
|
|
25
29
|
|
|
26
30
|
export const formatClient = request => {
|
|
31
|
+
var _request$headers, _request$headers2;
|
|
32
|
+
|
|
27
33
|
return {
|
|
28
34
|
params: request.params || {},
|
|
29
35
|
host: request.host || location.host,
|
|
30
36
|
pathname: request.pathname || location.pathname,
|
|
31
37
|
headers: request.headers || {},
|
|
32
38
|
cookieMap: request.cookieMap || {},
|
|
33
|
-
cookie: request.headers.cookie || document.cookie,
|
|
34
|
-
userAgent: request.headers['user-agent'] || navigator.userAgent,
|
|
39
|
+
cookie: ((_request$headers = request.headers) === null || _request$headers === void 0 ? void 0 : _request$headers.cookie) || document.cookie,
|
|
40
|
+
userAgent: ((_request$headers2 = request.headers) === null || _request$headers2 === void 0 ? void 0 : _request$headers2['user-agent']) || navigator.userAgent,
|
|
35
41
|
referer: request.referer || document.referrer,
|
|
36
42
|
query: request.query || getQuery(),
|
|
37
43
|
url: location.href
|
|
@@ -100,7 +100,7 @@ export default (() => ({
|
|
|
100
100
|
},
|
|
101
101
|
|
|
102
102
|
addRuntimeExports() {
|
|
103
|
-
pluginsExportsUtils.addExport(`export { default as state } from '@modern-js/runtime
|
|
103
|
+
pluginsExportsUtils.addExport(`export { default as state } from '@modern-js/runtime/runtime-state'`);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
};
|
|
@@ -5,10 +5,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
5
5
|
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
6
|
|
|
7
7
|
import { useContext } from 'react';
|
|
8
|
-
import { RuntimeReactContext } from '@modern-js/runtime-core';
|
|
9
8
|
import { createStore } from '@modern-js-reduck/store';
|
|
10
9
|
import { Provider } from '@modern-js-reduck/react';
|
|
11
10
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
11
|
+
import { RuntimeReactContext } from "../../core";
|
|
12
12
|
import { isBrowser } from "../../common";
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
|
|
@@ -39,9 +39,7 @@ var _default = () => ({
|
|
|
39
39
|
* But it will not be installed under the user project.
|
|
40
40
|
* So need to add alias
|
|
41
41
|
*/
|
|
42
|
-
'styled-components': require.resolve('styled-components'
|
|
43
|
-
paths: [require.resolve('@modern-js/runtime-core')]
|
|
44
|
-
})
|
|
42
|
+
'styled-components': require.resolve('styled-components')
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getConfig = exports.defineConfig = void 0;
|
|
7
|
+
const APP_CONFIG_SYMBOL = 'config';
|
|
8
|
+
|
|
9
|
+
const getConfig = Component => // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
|
+
// @ts-expect-error
|
|
11
|
+
Component[APP_CONFIG_SYMBOL];
|
|
12
|
+
|
|
13
|
+
exports.getConfig = getConfig;
|
|
14
|
+
|
|
15
|
+
const defineConfig = (Component, config) => {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
Component[APP_CONFIG_SYMBOL] = config;
|
|
19
|
+
return Component;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.defineConfig = defineConfig;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useRuntimeContext = exports.createApp = exports.bootstrap = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
11
|
+
|
|
12
|
+
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
|
13
|
+
|
|
14
|
+
var _plugin = require("./plugin");
|
|
15
|
+
|
|
16
|
+
var _runtimeContext = require("./runtime-context");
|
|
17
|
+
|
|
18
|
+
var _loaderManager = require("./loader/loaderManager");
|
|
19
|
+
|
|
20
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
|
+
|
|
22
|
+
const _excluded = ["context"];
|
|
23
|
+
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
+
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
|
+
|
|
28
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
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; }
|
|
39
|
+
|
|
40
|
+
function isClientArgs(id) {
|
|
41
|
+
return typeof id === 'string' || typeof HTMLElement !== 'undefined' && id instanceof HTMLElement;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const runnerMap = new WeakMap();
|
|
45
|
+
|
|
46
|
+
const getInitialContext = runner => ({
|
|
47
|
+
loaderManager: (0, _loaderManager.createLoaderManager)({}),
|
|
48
|
+
runner,
|
|
49
|
+
isBrowser: true
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const createApp = ({
|
|
53
|
+
plugins
|
|
54
|
+
}) => {
|
|
55
|
+
const appRuntime = _plugin.runtime.clone();
|
|
56
|
+
|
|
57
|
+
appRuntime.usePlugin(...plugins);
|
|
58
|
+
return App => {
|
|
59
|
+
const runner = appRuntime.init();
|
|
60
|
+
|
|
61
|
+
const WrapperComponent = props => {
|
|
62
|
+
const element = /*#__PURE__*/_react.default.createElement(App || _react.default.Fragment, _objectSpread({}, props), props.children);
|
|
63
|
+
|
|
64
|
+
const context = (0, _react.useContext)(_runtimeContext.RuntimeReactContext);
|
|
65
|
+
return runner.provide({
|
|
66
|
+
element,
|
|
67
|
+
props: _objectSpread({}, props),
|
|
68
|
+
context
|
|
69
|
+
}, {
|
|
70
|
+
onLast: ({
|
|
71
|
+
element
|
|
72
|
+
}) => element
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
if (App) {
|
|
77
|
+
(0, _hoistNonReactStatics.default)(WrapperComponent, App);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const HOCApp = runner.hoc({
|
|
81
|
+
App: WrapperComponent
|
|
82
|
+
}, {
|
|
83
|
+
onLast: ({
|
|
84
|
+
App
|
|
85
|
+
}) => {
|
|
86
|
+
const WrapComponent = _ref => {
|
|
87
|
+
var _contextValue;
|
|
88
|
+
|
|
89
|
+
let {
|
|
90
|
+
context
|
|
91
|
+
} = _ref,
|
|
92
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
93
|
+
|
|
94
|
+
let contextValue = context; // We should construct the context, when root component is not passed into `bootstrap`.
|
|
95
|
+
|
|
96
|
+
if (!((_contextValue = contextValue) !== null && _contextValue !== void 0 && _contextValue.runner)) {
|
|
97
|
+
contextValue = getInitialContext(runner);
|
|
98
|
+
runner.init({
|
|
99
|
+
context: contextValue
|
|
100
|
+
}, {
|
|
101
|
+
onLast: ({
|
|
102
|
+
context: context1
|
|
103
|
+
}) => {
|
|
104
|
+
var _App$init;
|
|
105
|
+
|
|
106
|
+
return App === null || App === void 0 ? void 0 : (_App$init = App.init) === null || _App$init === void 0 ? void 0 : _App$init.call(App, context1);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_runtimeContext.RuntimeReactContext.Provider, {
|
|
112
|
+
value: contextValue,
|
|
113
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return (0, _hoistNonReactStatics.default)(WrapComponent, App);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
runnerMap.set(HOCApp, runner);
|
|
121
|
+
return HOCApp;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
exports.createApp = createApp;
|
|
126
|
+
|
|
127
|
+
const bootstrap = async (BootApp,
|
|
128
|
+
/**
|
|
129
|
+
* When csr, id is root id.
|
|
130
|
+
* When ssr, id is serverContext
|
|
131
|
+
*/
|
|
132
|
+
id) => {
|
|
133
|
+
let App = BootApp;
|
|
134
|
+
let runner = runnerMap.get(App); // ensure Component used is created by `createApp`
|
|
135
|
+
|
|
136
|
+
if (!runner) {
|
|
137
|
+
App = createApp({
|
|
138
|
+
plugins: []
|
|
139
|
+
})(App);
|
|
140
|
+
runner = runnerMap.get(App);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const context = getInitialContext(runner);
|
|
144
|
+
|
|
145
|
+
const runInit = _context => runner.init({
|
|
146
|
+
context: _context
|
|
147
|
+
}, {
|
|
148
|
+
onLast: ({
|
|
149
|
+
context: context1
|
|
150
|
+
}) => {
|
|
151
|
+
var _App, _App$init2;
|
|
152
|
+
|
|
153
|
+
return (_App = App) === null || _App === void 0 ? void 0 : (_App$init2 = _App.init) === null || _App$init2 === void 0 ? void 0 : _App$init2.call(_App, context1);
|
|
154
|
+
}
|
|
155
|
+
}); // don't mount the App, let user in charge of it.
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
if (!id) {
|
|
159
|
+
return /*#__PURE__*/_react.default.createElement(App, {
|
|
160
|
+
context
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const isBrowser = typeof window !== 'undefined' && window.name !== 'nodejs';
|
|
165
|
+
|
|
166
|
+
if (isBrowser) {
|
|
167
|
+
if (isClientArgs(id)) {
|
|
168
|
+
var _ssrData$data, _ssrData$data2;
|
|
169
|
+
|
|
170
|
+
const ssrData = window._SSR_DATA;
|
|
171
|
+
const loadersData = (ssrData === null || ssrData === void 0 ? void 0 : (_ssrData$data = ssrData.data) === null || _ssrData$data === void 0 ? void 0 : _ssrData$data.loadersData) || {};
|
|
172
|
+
const initialLoadersState = Object.keys(loadersData).reduce((res, key) => {
|
|
173
|
+
const loaderData = loadersData[key];
|
|
174
|
+
|
|
175
|
+
if (loaderData.loading !== false) {
|
|
176
|
+
return res;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
res[key] = loaderData;
|
|
180
|
+
return res;
|
|
181
|
+
}, {});
|
|
182
|
+
Object.assign(context, _objectSpread({
|
|
183
|
+
loaderManager: (0, _loaderManager.createLoaderManager)(initialLoadersState, {
|
|
184
|
+
skipStatic: true
|
|
185
|
+
})
|
|
186
|
+
}, ssrData ? {
|
|
187
|
+
ssrContext: ssrData === null || ssrData === void 0 ? void 0 : ssrData.context
|
|
188
|
+
} : {}));
|
|
189
|
+
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData$data2 = ssrData.data) === null || _ssrData$data2 === void 0 ? void 0 : _ssrData$data2.initialData;
|
|
190
|
+
const initialData = await runInit(context);
|
|
191
|
+
|
|
192
|
+
if (initialData) {
|
|
193
|
+
context.initialData = initialData;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return runner.client({
|
|
197
|
+
App,
|
|
198
|
+
context,
|
|
199
|
+
rootElement: typeof id !== 'string' ? id : document.getElementById(id || 'root')
|
|
200
|
+
}, {
|
|
201
|
+
onLast: ({
|
|
202
|
+
App,
|
|
203
|
+
rootElement
|
|
204
|
+
}) => {
|
|
205
|
+
_reactDom.default.render( /*#__PURE__*/_react.default.createElement(App, {
|
|
206
|
+
context
|
|
207
|
+
}), rootElement);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
throw Error('`bootstrap` needs id in browser environment, it needs to be string or element');
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
Object.assign(context, {
|
|
215
|
+
ssrContext: id,
|
|
216
|
+
isBrowser: false,
|
|
217
|
+
loaderManager: (0, _loaderManager.createLoaderManager)({}, {
|
|
218
|
+
skipNonStatic: id.staticGenerate,
|
|
219
|
+
// if not static generate, only non-static loader can exec on prod env
|
|
220
|
+
skipStatic: process.env.NODE_ENV === 'production' && !id.staticGenerate
|
|
221
|
+
})
|
|
222
|
+
});
|
|
223
|
+
const initialData = await runInit(context);
|
|
224
|
+
context.initialData = initialData;
|
|
225
|
+
return runner.server({
|
|
226
|
+
App,
|
|
227
|
+
context
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
exports.bootstrap = bootstrap;
|
|
233
|
+
|
|
234
|
+
const useRuntimeContext = () => {
|
|
235
|
+
const context = (0, _react.useContext)(_runtimeContext.RuntimeReactContext);
|
|
236
|
+
const memoizedContext = (0, _react.useMemo)(() => context.runner.pickContext({
|
|
237
|
+
context,
|
|
238
|
+
pickedContext: {}
|
|
239
|
+
}, {
|
|
240
|
+
onLast: ({
|
|
241
|
+
pickedContext
|
|
242
|
+
}) => pickedContext
|
|
243
|
+
}), [context]);
|
|
244
|
+
return memoizedContext;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
exports.useRuntimeContext = useRuntimeContext;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
createPlugin: true,
|
|
8
|
+
createRuntime: true,
|
|
9
|
+
runtime: true,
|
|
10
|
+
registerInit: true,
|
|
11
|
+
registerPrefetch: true,
|
|
12
|
+
defineConfig: true,
|
|
13
|
+
getConfig: true,
|
|
14
|
+
RuntimeReactContext: true
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "RuntimeReactContext", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _runtimeContext.RuntimeReactContext;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "createPlugin", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return _plugin.createPlugin;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "createRuntime", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return _plugin.createRuntime;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "defineConfig", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return _appConfig.defineConfig;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "getConfig", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return _appConfig.getConfig;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, "registerInit", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () {
|
|
49
|
+
return _plugin.registerInit;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, "registerPrefetch", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () {
|
|
55
|
+
return _plugin.registerPrefetch;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(exports, "runtime", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () {
|
|
61
|
+
return _plugin.runtime;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
var _plugin = require("./plugin");
|
|
66
|
+
|
|
67
|
+
var _appConfig = require("./app-config");
|
|
68
|
+
|
|
69
|
+
var _compatible = require("./compatible");
|
|
70
|
+
|
|
71
|
+
Object.keys(_compatible).forEach(function (key) {
|
|
72
|
+
if (key === "default" || key === "__esModule") return;
|
|
73
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
74
|
+
if (key in exports && exports[key] === _compatible[key]) return;
|
|
75
|
+
Object.defineProperty(exports, key, {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () {
|
|
78
|
+
return _compatible[key];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
var _runtimeContext = require("./runtime-context");
|
|
84
|
+
|
|
85
|
+
var _loader = require("./loader");
|
|
86
|
+
|
|
87
|
+
Object.keys(_loader).forEach(function (key) {
|
|
88
|
+
if (key === "default" || key === "__esModule") return;
|
|
89
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
90
|
+
if (key in exports && exports[key] === _loader[key]) return;
|
|
91
|
+
Object.defineProperty(exports, key, {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () {
|
|
94
|
+
return _loader[key];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
var _plugin2 = require("@modern-js/plugin");
|
|
100
|
+
|
|
101
|
+
Object.keys(_plugin2).forEach(function (key) {
|
|
102
|
+
if (key === "default" || key === "__esModule") return;
|
|
103
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
104
|
+
if (key in exports && exports[key] === _plugin2[key]) return;
|
|
105
|
+
Object.defineProperty(exports, key, {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () {
|
|
108
|
+
return _plugin2[key];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "useLoader", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useLoader.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _useLoader = _interopRequireDefault(require("./useLoader"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|