@modern-js/plugin-garfish 2.68.12 → 2.68.13-alpha.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/cli/code.js +3 -1
- package/dist/cjs/cli/template.js +5 -4
- package/dist/cjs/runtime/provider.js +17 -15
- package/dist/cjs/runtime/utils/apps.js +35 -0
- package/dist/esm/cli/code.js +5 -2
- package/dist/esm/cli/template.js +5 -4
- package/dist/esm/runtime/provider.js +15 -13
- package/dist/esm/runtime/utils/apps.js +32 -0
- package/dist/esm-node/cli/code.js +3 -1
- package/dist/esm-node/cli/template.js +5 -4
- package/dist/esm-node/runtime/provider.js +17 -15
- package/dist/esm-node/runtime/utils/apps.js +35 -0
- package/dist/types/cli/template.d.ts +2 -1
- package/dist/types/runtime/provider.d.ts +4 -3
- package/package.json +3 -3
package/dist/cjs/cli/code.js
CHANGED
|
@@ -41,6 +41,7 @@ const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
|
41
41
|
const generateCode = async (entrypoints, appContext, config, hooks) => {
|
|
42
42
|
const { mountId } = config.html;
|
|
43
43
|
const { enableAsyncEntry } = config.source;
|
|
44
|
+
const { disableComponentCompat } = typeof config.deploy.microFrontend === "object" ? config.deploy.microFrontend : {};
|
|
44
45
|
const { internalDirectory, internalSrcAlias, metaName, srcDirectory } = appContext;
|
|
45
46
|
await Promise.all(entrypoints.map(async (entrypoint) => {
|
|
46
47
|
const { entryName, isAutoMount, entry, customEntry, customBootstrap } = entrypoint;
|
|
@@ -58,7 +59,8 @@ const generateCode = async (entrypoints, appContext, config, hooks) => {
|
|
|
58
59
|
customEntry,
|
|
59
60
|
customBootstrap,
|
|
60
61
|
mountId,
|
|
61
|
-
appendCode
|
|
62
|
+
appendCode,
|
|
63
|
+
disableComponentCompat
|
|
62
64
|
});
|
|
63
65
|
const indexFile = import_path.default.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
|
|
64
66
|
import_utils.fs.outputFileSync(indexFile, indexCode, "utf8");
|
package/dist/cjs/cli/template.js
CHANGED
|
@@ -22,7 +22,7 @@ __export(template_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(template_exports);
|
|
24
24
|
var import_utils = require("@modern-js/utils");
|
|
25
|
-
const genRenderCode = ({ srcDirectory, internalSrcAlias, metaName, entry, customEntry, customBootstrap, mountId }) => customEntry ? `import '${(0, import_utils.formatImportPath)(entry.replace(srcDirectory, internalSrcAlias))}'
|
|
25
|
+
const genRenderCode = ({ srcDirectory, internalSrcAlias, metaName, entry, customEntry, customBootstrap, mountId, disableComponentCompat }) => customEntry ? `import '${(0, import_utils.formatImportPath)(entry.replace(srcDirectory, internalSrcAlias))}'
|
|
26
26
|
export * from '${(0, import_utils.formatImportPath)(entry.replace(srcDirectory, internalSrcAlias))}'` : `import { createRoot } from '@${metaName}/runtime/react';
|
|
27
27
|
import { render } from '@${metaName}/runtime/browser';
|
|
28
28
|
import { isRenderGarfish, createProvider } from '@${metaName}/plugin-garfish/tools';
|
|
@@ -32,9 +32,9 @@ if (!isRenderGarfish()) {
|
|
|
32
32
|
${customBootstrap ? `customBootstrap(ModernRoot, () => render(<ModernRoot />, '${mountId || "root"}'));` : `render(<ModernRoot />, '${mountId || "root"}');`};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export const provider = createProvider('${mountId || "root"}', { customBootstrap });
|
|
35
|
+
export const provider = createProvider('${mountId || "root"}', { customBootstrap, disableComponentCompat: ${disableComponentCompat} });
|
|
36
36
|
`;
|
|
37
|
-
const index = ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, customBootstrap, mountId, appendCode = [] }) => `import '@${metaName}/runtime/registry/${entryName}';
|
|
37
|
+
const index = ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, customBootstrap, mountId, appendCode = [], disableComponentCompat }) => `import '@${metaName}/runtime/registry/${entryName}';
|
|
38
38
|
${genRenderCode({
|
|
39
39
|
srcDirectory,
|
|
40
40
|
internalSrcAlias,
|
|
@@ -42,7 +42,8 @@ const index = ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, cus
|
|
|
42
42
|
entry,
|
|
43
43
|
customEntry,
|
|
44
44
|
customBootstrap,
|
|
45
|
-
mountId
|
|
45
|
+
mountId,
|
|
46
|
+
disableComponentCompat
|
|
46
47
|
})}
|
|
47
48
|
${appendCode.join("\n")}
|
|
48
49
|
`;
|
|
@@ -29,9 +29,23 @@ function generateRootDom(dom, id) {
|
|
|
29
29
|
const mountNode = dom ? dom.querySelector(`#${id}`) || dom : document.getElementById(id);
|
|
30
30
|
return mountNode;
|
|
31
31
|
}
|
|
32
|
-
function createProvider(id, { customBootstrap, beforeRender } = {}) {
|
|
32
|
+
function createProvider(id, { customBootstrap, beforeRender, disableComponentCompat } = {}) {
|
|
33
33
|
return ({ basename, dom }) => {
|
|
34
34
|
let root = null;
|
|
35
|
+
const SubModuleComponent = disableComponentCompat ? null : (props) => {
|
|
36
|
+
const ModernRoot = (0, import_react.createRoot)(null);
|
|
37
|
+
return /* @__PURE__ */ (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
38
|
+
basename,
|
|
39
|
+
...props
|
|
40
|
+
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
41
|
+
};
|
|
42
|
+
const jupiter_submodule_app_key = disableComponentCompat ? null : (props) => {
|
|
43
|
+
const ModernRoot = (0, import_react.createRoot)(null);
|
|
44
|
+
return /* @__PURE__ */ (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
45
|
+
basename,
|
|
46
|
+
...props
|
|
47
|
+
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
48
|
+
};
|
|
35
49
|
return {
|
|
36
50
|
async render({ basename: basename2, dom: dom2, props, appName }) {
|
|
37
51
|
const ModernRoot = (0, import_react.createRoot)(null);
|
|
@@ -68,20 +82,8 @@ function createProvider(id, { customBootstrap, beforeRender } = {}) {
|
|
|
68
82
|
}
|
|
69
83
|
},
|
|
70
84
|
// 兼容旧版本
|
|
71
|
-
SubModuleComponent
|
|
72
|
-
|
|
73
|
-
return /* @__PURE__ */ (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
74
|
-
basename,
|
|
75
|
-
...props
|
|
76
|
-
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
77
|
-
},
|
|
78
|
-
jupiter_submodule_app_key: (props) => {
|
|
79
|
-
const ModernRoot = (0, import_react.createRoot)(null);
|
|
80
|
-
return /* @__PURE__ */ (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
81
|
-
basename,
|
|
82
|
-
...props
|
|
83
|
-
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
84
|
-
}
|
|
85
|
+
SubModuleComponent,
|
|
86
|
+
jupiter_submodule_app_key
|
|
85
87
|
};
|
|
86
88
|
};
|
|
87
89
|
}
|
|
@@ -64,6 +64,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
64
64
|
const [{ component: SubModuleComponent }, setSubModuleComponent] = (0, import_react.useState)({
|
|
65
65
|
component: null
|
|
66
66
|
});
|
|
67
|
+
const destroyRef = (0, import_react.useRef)(null);
|
|
67
68
|
const context = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
|
|
68
69
|
var _props_useRouteMatch;
|
|
69
70
|
const useRouteMatch = (_props_useRouteMatch = props.useRouteMatch) !== null && _props_useRouteMatch !== void 0 ? _props_useRouteMatch : context === null || context === void 0 ? void 0 : (_context_router = context.router) === null || _context_router === void 0 ? void 0 : _context_router.useRouteMatch;
|
|
@@ -144,6 +145,26 @@ or directly pass the "basename":
|
|
|
144
145
|
const { render, destroy, SubModuleComponent: SubModuleComponent2, jupiter_submodule_app_key } = provider;
|
|
145
146
|
const SubComponent = SubModuleComponent2 || jupiter_submodule_app_key;
|
|
146
147
|
const componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
|
|
148
|
+
if (destroy) {
|
|
149
|
+
destroyRef.current = () => {
|
|
150
|
+
const dom = document.getElementById(domId);
|
|
151
|
+
if (dom) {
|
|
152
|
+
const destroyProps = {
|
|
153
|
+
dom,
|
|
154
|
+
basename,
|
|
155
|
+
appName: appInfo.name,
|
|
156
|
+
appRenderInfo: {},
|
|
157
|
+
props: {
|
|
158
|
+
...appInfo.props,
|
|
159
|
+
...userProps
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
destroy.apply(provider, [
|
|
163
|
+
destroyProps
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
147
168
|
return {
|
|
148
169
|
mount: (...props2) => {
|
|
149
170
|
if (componetRenderMode && SubComponent) {
|
|
@@ -219,6 +240,20 @@ or directly pass the "basename":
|
|
|
219
240
|
}
|
|
220
241
|
};
|
|
221
242
|
}, []);
|
|
243
|
+
(0, import_react.useEffect)(() => {
|
|
244
|
+
return () => {
|
|
245
|
+
if (SubModuleComponent && destroyRef.current) {
|
|
246
|
+
(0, import_util.logger)("MicroApp SubModuleComponent cleanup");
|
|
247
|
+
try {
|
|
248
|
+
destroyRef.current();
|
|
249
|
+
} catch (error) {
|
|
250
|
+
(0, import_util.logger)("Error during SubModuleComponent cleanup:", error);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}, [
|
|
255
|
+
SubModuleComponent
|
|
256
|
+
]);
|
|
222
257
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
223
258
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
224
259
|
id: domId,
|
package/dist/esm/cli/code.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
2
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
4
|
import path from "path";
|
|
4
5
|
import { fs } from "@modern-js/utils";
|
|
@@ -8,12 +9,13 @@ var ENTRY_POINT_FILE_NAME = "index.jsx";
|
|
|
8
9
|
var ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
9
10
|
var generateCode = function() {
|
|
10
11
|
var _ref = _async_to_generator(function(entrypoints, appContext, config, hooks) {
|
|
11
|
-
var mountId, enableAsyncEntry, internalDirectory, internalSrcAlias, metaName, srcDirectory;
|
|
12
|
+
var mountId, enableAsyncEntry, disableComponentCompat, internalDirectory, internalSrcAlias, metaName, srcDirectory;
|
|
12
13
|
return _ts_generator(this, function(_state) {
|
|
13
14
|
switch (_state.label) {
|
|
14
15
|
case 0:
|
|
15
16
|
mountId = config.html.mountId;
|
|
16
17
|
enableAsyncEntry = config.source.enableAsyncEntry;
|
|
18
|
+
disableComponentCompat = (_type_of(config.deploy.microFrontend) === "object" ? config.deploy.microFrontend : {}).disableComponentCompat;
|
|
17
19
|
internalDirectory = appContext.internalDirectory, internalSrcAlias = appContext.internalSrcAlias, metaName = appContext.metaName, srcDirectory = appContext.srcDirectory;
|
|
18
20
|
return [
|
|
19
21
|
4,
|
|
@@ -43,7 +45,8 @@ var generateCode = function() {
|
|
|
43
45
|
customEntry,
|
|
44
46
|
customBootstrap,
|
|
45
47
|
mountId,
|
|
46
|
-
appendCode
|
|
48
|
+
appendCode,
|
|
49
|
+
disableComponentCompat
|
|
47
50
|
});
|
|
48
51
|
indexFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
|
|
49
52
|
fs.outputFileSync(indexFile, indexCode, "utf8");
|
package/dist/esm/cli/template.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { formatImportPath } from "@modern-js/utils";
|
|
2
2
|
var genRenderCode = function(param) {
|
|
3
|
-
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, customEntry = param.customEntry, customBootstrap = param.customBootstrap, mountId = param.mountId;
|
|
4
|
-
return customEntry ? "import '".concat(formatImportPath(entry.replace(srcDirectory, internalSrcAlias)), "'\nexport * from '").concat(formatImportPath(entry.replace(srcDirectory, internalSrcAlias)), "'") : "import { createRoot } from '@".concat(metaName, "/runtime/react';\nimport { render } from '@").concat(metaName, "/runtime/browser';\nimport { isRenderGarfish, createProvider } from '@").concat(metaName, "/plugin-garfish/tools';\n").concat(customBootstrap ? "import customBootstrap from '".concat(formatImportPath(customBootstrap.replace(srcDirectory, internalSrcAlias)), "';") : "let customBootstrap;", "\nif (!isRenderGarfish()) {\n const ModernRoot = createRoot();\n ").concat(customBootstrap ? "customBootstrap(ModernRoot, () => render(<ModernRoot />, '".concat(mountId || "root", "'));") : "render(<ModernRoot />, '".concat(mountId || "root", "');"), ";\n}\n\nexport const provider = createProvider('").concat(mountId || "root", "', { customBootstrap });\n");
|
|
3
|
+
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, customEntry = param.customEntry, customBootstrap = param.customBootstrap, mountId = param.mountId, disableComponentCompat = param.disableComponentCompat;
|
|
4
|
+
return customEntry ? "import '".concat(formatImportPath(entry.replace(srcDirectory, internalSrcAlias)), "'\nexport * from '").concat(formatImportPath(entry.replace(srcDirectory, internalSrcAlias)), "'") : "import { createRoot } from '@".concat(metaName, "/runtime/react';\nimport { render } from '@").concat(metaName, "/runtime/browser';\nimport { isRenderGarfish, createProvider } from '@").concat(metaName, "/plugin-garfish/tools';\n").concat(customBootstrap ? "import customBootstrap from '".concat(formatImportPath(customBootstrap.replace(srcDirectory, internalSrcAlias)), "';") : "let customBootstrap;", "\nif (!isRenderGarfish()) {\n const ModernRoot = createRoot();\n ").concat(customBootstrap ? "customBootstrap(ModernRoot, () => render(<ModernRoot />, '".concat(mountId || "root", "'));") : "render(<ModernRoot />, '".concat(mountId || "root", "');"), ";\n}\n\nexport const provider = createProvider('").concat(mountId || "root", "', { customBootstrap, disableComponentCompat: ").concat(disableComponentCompat, " });\n");
|
|
5
5
|
};
|
|
6
6
|
var index = function(param) {
|
|
7
|
-
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, entryName = param.entryName, customEntry = param.customEntry, customBootstrap = param.customBootstrap, mountId = param.mountId, _param_appendCode = param.appendCode, appendCode = _param_appendCode === void 0 ? [] : _param_appendCode;
|
|
7
|
+
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, entryName = param.entryName, customEntry = param.customEntry, customBootstrap = param.customBootstrap, mountId = param.mountId, _param_appendCode = param.appendCode, appendCode = _param_appendCode === void 0 ? [] : _param_appendCode, disableComponentCompat = param.disableComponentCompat;
|
|
8
8
|
return "import '@".concat(metaName, "/runtime/registry/").concat(entryName, "';\n ").concat(genRenderCode({
|
|
9
9
|
srcDirectory,
|
|
10
10
|
internalSrcAlias,
|
|
@@ -12,7 +12,8 @@ var index = function(param) {
|
|
|
12
12
|
entry,
|
|
13
13
|
customEntry,
|
|
14
14
|
customBootstrap,
|
|
15
|
-
mountId
|
|
15
|
+
mountId,
|
|
16
|
+
disableComponentCompat
|
|
16
17
|
}), "\n ").concat(appendCode.join("\n"), "\n ");
|
|
17
18
|
};
|
|
18
19
|
export {
|
|
@@ -10,10 +10,22 @@ function generateRootDom(dom, id) {
|
|
|
10
10
|
return mountNode;
|
|
11
11
|
}
|
|
12
12
|
function createProvider(id) {
|
|
13
|
-
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, customBootstrap = _ref.customBootstrap, beforeRender = _ref.beforeRender;
|
|
13
|
+
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, customBootstrap = _ref.customBootstrap, beforeRender = _ref.beforeRender, disableComponentCompat = _ref.disableComponentCompat;
|
|
14
14
|
return function(param) {
|
|
15
15
|
var basename = param.basename, dom = param.dom;
|
|
16
16
|
var root = null;
|
|
17
|
+
var SubModuleComponent = disableComponentCompat ? null : function(props) {
|
|
18
|
+
var ModernRoot = createRoot(null);
|
|
19
|
+
return /* @__PURE__ */ createPortal(/* @__PURE__ */ _jsx(ModernRoot, _object_spread({
|
|
20
|
+
basename
|
|
21
|
+
}, props)), dom.querySelector("#".concat(id || "root")) || dom);
|
|
22
|
+
};
|
|
23
|
+
var jupiter_submodule_app_key = disableComponentCompat ? null : function(props) {
|
|
24
|
+
var ModernRoot = createRoot(null);
|
|
25
|
+
return /* @__PURE__ */ createPortal(/* @__PURE__ */ _jsx(ModernRoot, _object_spread({
|
|
26
|
+
basename
|
|
27
|
+
}, props)), dom.querySelector("#".concat(id || "root")) || dom);
|
|
28
|
+
};
|
|
17
29
|
return {
|
|
18
30
|
render: function render1(param2) {
|
|
19
31
|
var basename2 = param2.basename, dom2 = param2.dom, props = param2.props, appName = param2.appName;
|
|
@@ -91,18 +103,8 @@ function createProvider(id) {
|
|
|
91
103
|
}
|
|
92
104
|
},
|
|
93
105
|
// 兼容旧版本
|
|
94
|
-
SubModuleComponent
|
|
95
|
-
|
|
96
|
-
return /* @__PURE__ */ createPortal(/* @__PURE__ */ _jsx(ModernRoot, _object_spread({
|
|
97
|
-
basename
|
|
98
|
-
}, props)), dom.querySelector("#".concat(id || "root")) || dom);
|
|
99
|
-
},
|
|
100
|
-
jupiter_submodule_app_key: function(props) {
|
|
101
|
-
var ModernRoot = createRoot(null);
|
|
102
|
-
return /* @__PURE__ */ createPortal(/* @__PURE__ */ _jsx(ModernRoot, _object_spread({
|
|
103
|
-
basename
|
|
104
|
-
}, props)), dom.querySelector("#".concat(id || "root")) || dom);
|
|
105
|
-
}
|
|
106
|
+
SubModuleComponent,
|
|
107
|
+
jupiter_submodule_app_key
|
|
106
108
|
};
|
|
107
109
|
};
|
|
108
110
|
}
|
|
@@ -40,6 +40,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
40
40
|
var _useState = _sliced_to_array(useState({
|
|
41
41
|
component: null
|
|
42
42
|
}), 2), _useState_ = _useState[0], SubModuleComponent = _useState_.component, setSubModuleComponent = _useState[1];
|
|
43
|
+
var destroyRef = useRef(null);
|
|
43
44
|
var context = useContext(RuntimeReactContext);
|
|
44
45
|
var _props_useRouteMatch;
|
|
45
46
|
var useRouteMatch = (_props_useRouteMatch = props.useRouteMatch) !== null && _props_useRouteMatch !== void 0 ? _props_useRouteMatch : context === null || context === void 0 ? void 0 : (_context_router = context.router) === null || _context_router === void 0 ? void 0 : _context_router.useRouteMatch;
|
|
@@ -119,6 +120,23 @@ or directly pass the "basename":
|
|
|
119
120
|
var render = provider.render, destroy = provider.destroy, SubModuleComponent2 = provider.SubModuleComponent, jupiter_submodule_app_key = provider.jupiter_submodule_app_key;
|
|
120
121
|
var SubComponent = SubModuleComponent2 || jupiter_submodule_app_key;
|
|
121
122
|
var componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
|
|
123
|
+
if (destroy) {
|
|
124
|
+
destroyRef.current = function() {
|
|
125
|
+
var dom = document.getElementById(domId);
|
|
126
|
+
if (dom) {
|
|
127
|
+
var destroyProps = {
|
|
128
|
+
dom,
|
|
129
|
+
basename,
|
|
130
|
+
appName: appInfo.name,
|
|
131
|
+
appRenderInfo: {},
|
|
132
|
+
props: _object_spread({}, appInfo.props, userProps)
|
|
133
|
+
};
|
|
134
|
+
destroy.apply(provider, [
|
|
135
|
+
destroyProps
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
122
140
|
return {
|
|
123
141
|
mount: function() {
|
|
124
142
|
for (var _len = arguments.length, _$props = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -250,6 +268,20 @@ or directly pass the "basename":
|
|
|
250
268
|
}
|
|
251
269
|
};
|
|
252
270
|
}, []);
|
|
271
|
+
useEffect(function() {
|
|
272
|
+
return function() {
|
|
273
|
+
if (SubModuleComponent && destroyRef.current) {
|
|
274
|
+
logger("MicroApp SubModuleComponent cleanup");
|
|
275
|
+
try {
|
|
276
|
+
destroyRef.current();
|
|
277
|
+
} catch (error) {
|
|
278
|
+
logger("Error during SubModuleComponent cleanup:", error);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}, [
|
|
283
|
+
SubModuleComponent
|
|
284
|
+
]);
|
|
253
285
|
return /* @__PURE__ */ _jsx(_Fragment, {
|
|
254
286
|
children: /* @__PURE__ */ _jsx("div", {
|
|
255
287
|
id: domId,
|
|
@@ -7,6 +7,7 @@ const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
|
7
7
|
const generateCode = async (entrypoints, appContext, config, hooks) => {
|
|
8
8
|
const { mountId } = config.html;
|
|
9
9
|
const { enableAsyncEntry } = config.source;
|
|
10
|
+
const { disableComponentCompat } = typeof config.deploy.microFrontend === "object" ? config.deploy.microFrontend : {};
|
|
10
11
|
const { internalDirectory, internalSrcAlias, metaName, srcDirectory } = appContext;
|
|
11
12
|
await Promise.all(entrypoints.map(async (entrypoint) => {
|
|
12
13
|
const { entryName, isAutoMount, entry, customEntry, customBootstrap } = entrypoint;
|
|
@@ -24,7 +25,8 @@ const generateCode = async (entrypoints, appContext, config, hooks) => {
|
|
|
24
25
|
customEntry,
|
|
25
26
|
customBootstrap,
|
|
26
27
|
mountId,
|
|
27
|
-
appendCode
|
|
28
|
+
appendCode,
|
|
29
|
+
disableComponentCompat
|
|
28
30
|
});
|
|
29
31
|
const indexFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
|
|
30
32
|
fs.outputFileSync(indexFile, indexCode, "utf8");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { formatImportPath } from "@modern-js/utils";
|
|
2
|
-
const genRenderCode = ({ srcDirectory, internalSrcAlias, metaName, entry, customEntry, customBootstrap, mountId }) => customEntry ? `import '${formatImportPath(entry.replace(srcDirectory, internalSrcAlias))}'
|
|
2
|
+
const genRenderCode = ({ srcDirectory, internalSrcAlias, metaName, entry, customEntry, customBootstrap, mountId, disableComponentCompat }) => customEntry ? `import '${formatImportPath(entry.replace(srcDirectory, internalSrcAlias))}'
|
|
3
3
|
export * from '${formatImportPath(entry.replace(srcDirectory, internalSrcAlias))}'` : `import { createRoot } from '@${metaName}/runtime/react';
|
|
4
4
|
import { render } from '@${metaName}/runtime/browser';
|
|
5
5
|
import { isRenderGarfish, createProvider } from '@${metaName}/plugin-garfish/tools';
|
|
@@ -9,9 +9,9 @@ if (!isRenderGarfish()) {
|
|
|
9
9
|
${customBootstrap ? `customBootstrap(ModernRoot, () => render(<ModernRoot />, '${mountId || "root"}'));` : `render(<ModernRoot />, '${mountId || "root"}');`};
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const provider = createProvider('${mountId || "root"}', { customBootstrap });
|
|
12
|
+
export const provider = createProvider('${mountId || "root"}', { customBootstrap, disableComponentCompat: ${disableComponentCompat} });
|
|
13
13
|
`;
|
|
14
|
-
const index = ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, customBootstrap, mountId, appendCode = [] }) => `import '@${metaName}/runtime/registry/${entryName}';
|
|
14
|
+
const index = ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, customBootstrap, mountId, appendCode = [], disableComponentCompat }) => `import '@${metaName}/runtime/registry/${entryName}';
|
|
15
15
|
${genRenderCode({
|
|
16
16
|
srcDirectory,
|
|
17
17
|
internalSrcAlias,
|
|
@@ -19,7 +19,8 @@ const index = ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, cus
|
|
|
19
19
|
entry,
|
|
20
20
|
customEntry,
|
|
21
21
|
customBootstrap,
|
|
22
|
-
mountId
|
|
22
|
+
mountId,
|
|
23
|
+
disableComponentCompat
|
|
23
24
|
})}
|
|
24
25
|
${appendCode.join("\n")}
|
|
25
26
|
`;
|
|
@@ -6,9 +6,23 @@ function generateRootDom(dom, id) {
|
|
|
6
6
|
const mountNode = dom ? dom.querySelector(`#${id}`) || dom : document.getElementById(id);
|
|
7
7
|
return mountNode;
|
|
8
8
|
}
|
|
9
|
-
function createProvider(id, { customBootstrap, beforeRender } = {}) {
|
|
9
|
+
function createProvider(id, { customBootstrap, beforeRender, disableComponentCompat } = {}) {
|
|
10
10
|
return ({ basename, dom }) => {
|
|
11
11
|
let root = null;
|
|
12
|
+
const SubModuleComponent = disableComponentCompat ? null : (props) => {
|
|
13
|
+
const ModernRoot = createRoot(null);
|
|
14
|
+
return /* @__PURE__ */ createPortal(/* @__PURE__ */ _jsx(ModernRoot, {
|
|
15
|
+
basename,
|
|
16
|
+
...props
|
|
17
|
+
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
18
|
+
};
|
|
19
|
+
const jupiter_submodule_app_key = disableComponentCompat ? null : (props) => {
|
|
20
|
+
const ModernRoot = createRoot(null);
|
|
21
|
+
return /* @__PURE__ */ createPortal(/* @__PURE__ */ _jsx(ModernRoot, {
|
|
22
|
+
basename,
|
|
23
|
+
...props
|
|
24
|
+
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
25
|
+
};
|
|
12
26
|
return {
|
|
13
27
|
async render({ basename: basename2, dom: dom2, props, appName }) {
|
|
14
28
|
const ModernRoot = createRoot(null);
|
|
@@ -45,20 +59,8 @@ function createProvider(id, { customBootstrap, beforeRender } = {}) {
|
|
|
45
59
|
}
|
|
46
60
|
},
|
|
47
61
|
// 兼容旧版本
|
|
48
|
-
SubModuleComponent
|
|
49
|
-
|
|
50
|
-
return /* @__PURE__ */ createPortal(/* @__PURE__ */ _jsx(ModernRoot, {
|
|
51
|
-
basename,
|
|
52
|
-
...props
|
|
53
|
-
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
54
|
-
},
|
|
55
|
-
jupiter_submodule_app_key: (props) => {
|
|
56
|
-
const ModernRoot = createRoot(null);
|
|
57
|
-
return /* @__PURE__ */ createPortal(/* @__PURE__ */ _jsx(ModernRoot, {
|
|
58
|
-
basename,
|
|
59
|
-
...props
|
|
60
|
-
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
61
|
-
}
|
|
62
|
+
SubModuleComponent,
|
|
63
|
+
jupiter_submodule_app_key
|
|
62
64
|
};
|
|
63
65
|
};
|
|
64
66
|
}
|
|
@@ -30,6 +30,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
30
30
|
const [{ component: SubModuleComponent }, setSubModuleComponent] = useState({
|
|
31
31
|
component: null
|
|
32
32
|
});
|
|
33
|
+
const destroyRef = useRef(null);
|
|
33
34
|
const context = useContext(RuntimeReactContext);
|
|
34
35
|
var _props_useRouteMatch;
|
|
35
36
|
const useRouteMatch = (_props_useRouteMatch = props.useRouteMatch) !== null && _props_useRouteMatch !== void 0 ? _props_useRouteMatch : context === null || context === void 0 ? void 0 : (_context_router = context.router) === null || _context_router === void 0 ? void 0 : _context_router.useRouteMatch;
|
|
@@ -110,6 +111,26 @@ or directly pass the "basename":
|
|
|
110
111
|
const { render, destroy, SubModuleComponent: SubModuleComponent2, jupiter_submodule_app_key } = provider;
|
|
111
112
|
const SubComponent = SubModuleComponent2 || jupiter_submodule_app_key;
|
|
112
113
|
const componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
|
|
114
|
+
if (destroy) {
|
|
115
|
+
destroyRef.current = () => {
|
|
116
|
+
const dom = document.getElementById(domId);
|
|
117
|
+
if (dom) {
|
|
118
|
+
const destroyProps = {
|
|
119
|
+
dom,
|
|
120
|
+
basename,
|
|
121
|
+
appName: appInfo.name,
|
|
122
|
+
appRenderInfo: {},
|
|
123
|
+
props: {
|
|
124
|
+
...appInfo.props,
|
|
125
|
+
...userProps
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
destroy.apply(provider, [
|
|
129
|
+
destroyProps
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
113
134
|
return {
|
|
114
135
|
mount: (...props2) => {
|
|
115
136
|
if (componetRenderMode && SubComponent) {
|
|
@@ -185,6 +206,20 @@ or directly pass the "basename":
|
|
|
185
206
|
}
|
|
186
207
|
};
|
|
187
208
|
}, []);
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
return () => {
|
|
211
|
+
if (SubModuleComponent && destroyRef.current) {
|
|
212
|
+
logger("MicroApp SubModuleComponent cleanup");
|
|
213
|
+
try {
|
|
214
|
+
destroyRef.current();
|
|
215
|
+
} catch (error) {
|
|
216
|
+
logger("Error during SubModuleComponent cleanup:", error);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}, [
|
|
221
|
+
SubModuleComponent
|
|
222
|
+
]);
|
|
188
223
|
return /* @__PURE__ */ _jsx(_Fragment, {
|
|
189
224
|
children: /* @__PURE__ */ _jsx("div", {
|
|
190
225
|
id: domId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const index: ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, customBootstrap, mountId, appendCode, }: {
|
|
1
|
+
export declare const index: ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, customBootstrap, mountId, appendCode, disableComponentCompat, }: {
|
|
2
2
|
srcDirectory: string;
|
|
3
3
|
internalSrcAlias: string;
|
|
4
4
|
metaName: string;
|
|
@@ -8,4 +8,5 @@ export declare const index: ({ srcDirectory, internalSrcAlias, metaName, entry,
|
|
|
8
8
|
customBootstrap?: string | false;
|
|
9
9
|
mountId?: string;
|
|
10
10
|
appendCode?: string[];
|
|
11
|
+
disableComponentCompat?: boolean;
|
|
11
12
|
}) => string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type RenderFunc } from '@meta/runtime/browser';
|
|
2
2
|
import type { Root } from 'react-dom/client';
|
|
3
|
-
export declare function createProvider(id?: string, { customBootstrap, beforeRender, }?: {
|
|
3
|
+
export declare function createProvider(id?: string, { customBootstrap, beforeRender, disableComponentCompat, }?: {
|
|
4
4
|
customBootstrap?: (App: React.ComponentType, render: RenderFunc) => Promise<HTMLElement | Root>;
|
|
5
5
|
beforeRender?: (App: React.ComponentType, props?: Record<string, any>) => Promise<any>;
|
|
6
|
+
disableComponentCompat?: boolean;
|
|
6
7
|
}): ({ basename, dom }: {
|
|
7
8
|
basename: string;
|
|
8
9
|
dom: HTMLElement;
|
|
@@ -16,6 +17,6 @@ export declare function createProvider(id?: string, { customBootstrap, beforeRen
|
|
|
16
17
|
destroy({ dom }: {
|
|
17
18
|
dom: HTMLElement;
|
|
18
19
|
}): void;
|
|
19
|
-
SubModuleComponent: (props: any) => import("react").ReactPortal;
|
|
20
|
-
jupiter_submodule_app_key: (props: any) => import("react").ReactPortal;
|
|
20
|
+
SubModuleComponent: ((props: any) => import("react").ReactPortal) | null;
|
|
21
|
+
jupiter_submodule_app_key: ((props: any) => import("react").ReactPortal) | null;
|
|
21
22
|
};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.68.
|
|
18
|
+
"version": "2.68.13-alpha.0",
|
|
19
19
|
"jsnext:source": "./src/cli/index.ts",
|
|
20
20
|
"types": "./dist/types/cli/index.d.ts",
|
|
21
21
|
"typesVersions": {
|
|
@@ -95,10 +95,10 @@
|
|
|
95
95
|
"typescript": "^5",
|
|
96
96
|
"@modern-js/app-tools": "2.68.12",
|
|
97
97
|
"@modern-js/core": "2.68.12",
|
|
98
|
-
"@
|
|
98
|
+
"@scripts/build": "2.66.0",
|
|
99
99
|
"@modern-js/plugin-router-v5": "2.68.12",
|
|
100
|
+
"@modern-js/runtime": "2.68.12",
|
|
100
101
|
"@modern-js/types": "2.68.12",
|
|
101
|
-
"@scripts/build": "2.66.0",
|
|
102
102
|
"@scripts/jest-config": "2.66.0"
|
|
103
103
|
},
|
|
104
104
|
"sideEffects": false,
|