@modern-js/plugin-garfish 2.68.13-alpha.2 → 2.68.13-alpha.4
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.
|
@@ -29,8 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var apps_exports = {};
|
|
30
30
|
__export(apps_exports, {
|
|
31
31
|
generateApps: () => generateApps,
|
|
32
|
-
pathJoin: () => pathJoin
|
|
33
|
-
useMicroAppMountStatus: () => useMicroAppMountStatus
|
|
32
|
+
pathJoin: () => pathJoin
|
|
34
33
|
});
|
|
35
34
|
module.exports = __toCommonJS(apps_exports);
|
|
36
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -39,13 +38,6 @@ var import_garfish = __toESM(require("garfish"));
|
|
|
39
38
|
var import_react = require("react");
|
|
40
39
|
var import_util = require("../../util");
|
|
41
40
|
var import_loadable = require("../loadable");
|
|
42
|
-
const MicroAppMountContext = /* @__PURE__ */ (0, import_react.createContext)({
|
|
43
|
-
isMounted: true
|
|
44
|
-
});
|
|
45
|
-
const useMicroAppMountStatus = () => {
|
|
46
|
-
const { isMounted } = (0, import_react.useContext)(MicroAppMountContext);
|
|
47
|
-
return isMounted;
|
|
48
|
-
};
|
|
49
41
|
function pathJoin(...args) {
|
|
50
42
|
const res = args.reduce((res2, path) => {
|
|
51
43
|
let nPath = path;
|
|
@@ -65,6 +57,9 @@ function pathJoin(...args) {
|
|
|
65
57
|
}
|
|
66
58
|
function getAppInstance(options, appInfo, manifest) {
|
|
67
59
|
let locationHref = "";
|
|
60
|
+
const componentSetterRegistry = {
|
|
61
|
+
current: null
|
|
62
|
+
};
|
|
68
63
|
function MicroApp(props) {
|
|
69
64
|
var _context_router, _context_router1, _context_router2, _context_router3, _context_router4;
|
|
70
65
|
const appRef = (0, import_react.useRef)(null);
|
|
@@ -72,9 +67,6 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
72
67
|
const [{ component: SubModuleComponent }, setSubModuleComponent] = (0, import_react.useState)({
|
|
73
68
|
component: null
|
|
74
69
|
});
|
|
75
|
-
const destroyRef = (0, import_react.useRef)(null);
|
|
76
|
-
const isMountedRef = (0, import_react.useRef)(true);
|
|
77
|
-
const abortControllerRef = (0, import_react.useRef)(null);
|
|
78
70
|
const context = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
|
|
79
71
|
var _props_useRouteMatch;
|
|
80
72
|
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;
|
|
@@ -137,14 +129,8 @@ or directly pass the "basename":
|
|
|
137
129
|
location
|
|
138
130
|
]);
|
|
139
131
|
(0, import_react.useEffect)(() => {
|
|
132
|
+
componentSetterRegistry.current = setSubModuleComponent;
|
|
140
133
|
const { setLoadingState, ...userProps } = props;
|
|
141
|
-
abortControllerRef.current = new AbortController();
|
|
142
|
-
const safeSetLoadingState = (state) => {
|
|
143
|
-
var _abortControllerRef_current;
|
|
144
|
-
if (isMountedRef.current && !((_abortControllerRef_current = abortControllerRef.current) === null || _abortControllerRef_current === void 0 ? void 0 : _abortControllerRef_current.signal.aborted)) {
|
|
145
|
-
setLoadingState(state);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
134
|
const loadAppOptions = {
|
|
149
135
|
cache: true,
|
|
150
136
|
insulationVariable: [
|
|
@@ -162,33 +148,15 @@ or directly pass the "basename":
|
|
|
162
148
|
const { render, destroy, SubModuleComponent: SubModuleComponent2, jupiter_submodule_app_key } = provider;
|
|
163
149
|
const SubComponent = SubModuleComponent2 || jupiter_submodule_app_key;
|
|
164
150
|
const componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
|
|
165
|
-
if (destroy) {
|
|
166
|
-
destroyRef.current = () => {
|
|
167
|
-
const dom = document.getElementById(domId);
|
|
168
|
-
if (dom) {
|
|
169
|
-
const destroyProps = {
|
|
170
|
-
dom,
|
|
171
|
-
basename,
|
|
172
|
-
appName: appInfo.name,
|
|
173
|
-
appRenderInfo: {},
|
|
174
|
-
props: {
|
|
175
|
-
...appInfo.props,
|
|
176
|
-
...userProps
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
destroy.apply(provider, [
|
|
180
|
-
destroyProps
|
|
181
|
-
]);
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
151
|
return {
|
|
186
152
|
mount: (...props2) => {
|
|
187
153
|
if (componetRenderMode && SubComponent) {
|
|
188
|
-
if (
|
|
189
|
-
|
|
154
|
+
if (componentSetterRegistry.current) {
|
|
155
|
+
componentSetterRegistry.current({
|
|
190
156
|
component: SubComponent
|
|
191
157
|
});
|
|
158
|
+
} else {
|
|
159
|
+
(0, import_util.logger)(`[Garfish] MicroApp for "${appInfo.name}" tried to mount, but no active component setter was found.`);
|
|
192
160
|
}
|
|
193
161
|
return void 0;
|
|
194
162
|
} else {
|
|
@@ -206,7 +174,7 @@ or directly pass the "basename":
|
|
|
206
174
|
};
|
|
207
175
|
}
|
|
208
176
|
};
|
|
209
|
-
|
|
177
|
+
setLoadingState({
|
|
210
178
|
isLoading: true,
|
|
211
179
|
error: null
|
|
212
180
|
});
|
|
@@ -215,19 +183,12 @@ or directly pass the "basename":
|
|
|
215
183
|
});
|
|
216
184
|
async function renderApp() {
|
|
217
185
|
try {
|
|
218
|
-
var _abortControllerRef_current, _abortControllerRef_current1;
|
|
219
|
-
if ((_abortControllerRef_current = abortControllerRef.current) === null || _abortControllerRef_current === void 0 ? void 0 : _abortControllerRef_current.signal.aborted) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
186
|
const appInstance = await import_garfish.default.loadApp(appInfo.name, loadAppOptions);
|
|
223
|
-
if ((_abortControllerRef_current1 = abortControllerRef.current) === null || _abortControllerRef_current1 === void 0 ? void 0 : _abortControllerRef_current1.signal.aborted) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
187
|
if (!appInstance) {
|
|
227
188
|
throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
|
|
228
189
|
}
|
|
229
190
|
appRef.current = appInstance;
|
|
230
|
-
|
|
191
|
+
setLoadingState({
|
|
231
192
|
isLoading: false
|
|
232
193
|
});
|
|
233
194
|
if (appInstance.mounted && appInstance.appInfo.cache) {
|
|
@@ -244,21 +205,15 @@ or directly pass the "basename":
|
|
|
244
205
|
await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
|
|
245
206
|
}
|
|
246
207
|
} catch (error) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
error
|
|
252
|
-
});
|
|
253
|
-
}
|
|
208
|
+
setLoadingState({
|
|
209
|
+
isLoading: true,
|
|
210
|
+
error
|
|
211
|
+
});
|
|
254
212
|
}
|
|
255
213
|
}
|
|
256
214
|
renderApp();
|
|
257
215
|
return () => {
|
|
258
|
-
|
|
259
|
-
if (abortControllerRef.current) {
|
|
260
|
-
abortControllerRef.current.abort();
|
|
261
|
-
}
|
|
216
|
+
componentSetterRegistry.current = null;
|
|
262
217
|
if (appRef.current) {
|
|
263
218
|
const { appInfo: appInfo2 } = appRef.current;
|
|
264
219
|
if (appInfo2.cache) {
|
|
@@ -273,40 +228,12 @@ or directly pass the "basename":
|
|
|
273
228
|
}
|
|
274
229
|
};
|
|
275
230
|
}, []);
|
|
276
|
-
(0, import_react.useEffect)(() => {
|
|
277
|
-
return () => {
|
|
278
|
-
if (SubModuleComponent && destroyRef.current && isMountedRef.current) {
|
|
279
|
-
(0, import_util.logger)("MicroApp SubModuleComponent cleanup");
|
|
280
|
-
try {
|
|
281
|
-
destroyRef.current();
|
|
282
|
-
} catch (error) {
|
|
283
|
-
(0, import_util.logger)("Error during SubModuleComponent cleanup:", error);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
}, [
|
|
288
|
-
SubModuleComponent
|
|
289
|
-
]);
|
|
290
|
-
const SafeSubModuleComponent = (0, import_react.useCallback)(() => {
|
|
291
|
-
if (!SubModuleComponent || !isMountedRef.current) {
|
|
292
|
-
return null;
|
|
293
|
-
}
|
|
294
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MicroAppMountContext.Provider, {
|
|
295
|
-
value: {
|
|
296
|
-
isMounted: isMountedRef.current
|
|
297
|
-
},
|
|
298
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SubModuleComponent, {
|
|
299
|
-
...props
|
|
300
|
-
})
|
|
301
|
-
});
|
|
302
|
-
}, [
|
|
303
|
-
SubModuleComponent,
|
|
304
|
-
props
|
|
305
|
-
]);
|
|
306
231
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
307
232
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
308
233
|
id: domId,
|
|
309
|
-
children: SubModuleComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
234
|
+
children: SubModuleComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SubModuleComponent, {
|
|
235
|
+
...props
|
|
236
|
+
})
|
|
310
237
|
})
|
|
311
238
|
});
|
|
312
239
|
}
|
|
@@ -328,6 +255,5 @@ function generateApps(options, manifest) {
|
|
|
328
255
|
// Annotate the CommonJS export names for ESM import in node:
|
|
329
256
|
0 && (module.exports = {
|
|
330
257
|
generateApps,
|
|
331
|
-
pathJoin
|
|
332
|
-
useMicroAppMountStatus
|
|
258
|
+
pathJoin
|
|
333
259
|
});
|
|
@@ -8,16 +8,9 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
8
8
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
9
9
|
import { RuntimeReactContext } from "@meta/runtime";
|
|
10
10
|
import Garfish from "garfish";
|
|
11
|
-
import {
|
|
11
|
+
import { useContext, useEffect, useRef, useState } from "react";
|
|
12
12
|
import { generateSubAppContainerKey, logger } from "../../util";
|
|
13
13
|
import { Loadable } from "../loadable";
|
|
14
|
-
var MicroAppMountContext = /* @__PURE__ */ createContext({
|
|
15
|
-
isMounted: true
|
|
16
|
-
});
|
|
17
|
-
var useMicroAppMountStatus = function() {
|
|
18
|
-
var isMounted = useContext(MicroAppMountContext).isMounted;
|
|
19
|
-
return isMounted;
|
|
20
|
-
};
|
|
21
14
|
function pathJoin() {
|
|
22
15
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
23
16
|
args[_key] = arguments[_key];
|
|
@@ -40,6 +33,9 @@ function pathJoin() {
|
|
|
40
33
|
}
|
|
41
34
|
function getAppInstance(options, appInfo, manifest) {
|
|
42
35
|
var locationHref = "";
|
|
36
|
+
var componentSetterRegistry = {
|
|
37
|
+
current: null
|
|
38
|
+
};
|
|
43
39
|
function MicroApp(props) {
|
|
44
40
|
var _context_router, _context_router1, _context_router2, _context_router3, _context_router4;
|
|
45
41
|
var appRef = useRef(null);
|
|
@@ -47,9 +43,6 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
47
43
|
var _useState = _sliced_to_array(useState({
|
|
48
44
|
component: null
|
|
49
45
|
}), 2), _useState_ = _useState[0], SubModuleComponent = _useState_.component, setSubModuleComponent = _useState[1];
|
|
50
|
-
var destroyRef = useRef(null);
|
|
51
|
-
var isMountedRef = useRef(true);
|
|
52
|
-
var abortControllerRef = useRef(null);
|
|
53
46
|
var context = useContext(RuntimeReactContext);
|
|
54
47
|
var _props_useRouteMatch;
|
|
55
48
|
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;
|
|
@@ -113,16 +106,10 @@ or directly pass the "basename":
|
|
|
113
106
|
var renderApp = function renderApp2() {
|
|
114
107
|
return _renderApp.apply(this, arguments);
|
|
115
108
|
};
|
|
109
|
+
componentSetterRegistry.current = setSubModuleComponent;
|
|
116
110
|
var setLoadingState = props.setLoadingState, userProps = _object_without_properties(props, [
|
|
117
111
|
"setLoadingState"
|
|
118
112
|
]);
|
|
119
|
-
abortControllerRef.current = new AbortController();
|
|
120
|
-
var safeSetLoadingState = function(state) {
|
|
121
|
-
var _abortControllerRef_current;
|
|
122
|
-
if (isMountedRef.current && !((_abortControllerRef_current = abortControllerRef.current) === null || _abortControllerRef_current === void 0 ? void 0 : _abortControllerRef_current.signal.aborted)) {
|
|
123
|
-
setLoadingState(state);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
113
|
var loadAppOptions = _object_spread_props(_object_spread({
|
|
127
114
|
cache: true,
|
|
128
115
|
insulationVariable: _to_consumable_array(appInfo.insulationVariable || []).concat([
|
|
@@ -136,33 +123,18 @@ or directly pass the "basename":
|
|
|
136
123
|
var render = provider.render, destroy = provider.destroy, SubModuleComponent2 = provider.SubModuleComponent, jupiter_submodule_app_key = provider.jupiter_submodule_app_key;
|
|
137
124
|
var SubComponent = SubModuleComponent2 || jupiter_submodule_app_key;
|
|
138
125
|
var componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
|
|
139
|
-
if (destroy) {
|
|
140
|
-
destroyRef.current = function() {
|
|
141
|
-
var dom = document.getElementById(domId);
|
|
142
|
-
if (dom) {
|
|
143
|
-
var destroyProps = {
|
|
144
|
-
dom,
|
|
145
|
-
basename,
|
|
146
|
-
appName: appInfo.name,
|
|
147
|
-
appRenderInfo: {},
|
|
148
|
-
props: _object_spread({}, appInfo.props, userProps)
|
|
149
|
-
};
|
|
150
|
-
destroy.apply(provider, [
|
|
151
|
-
destroyProps
|
|
152
|
-
]);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
126
|
return {
|
|
157
127
|
mount: function() {
|
|
158
128
|
for (var _len = arguments.length, _$props = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
159
129
|
_$props[_key] = arguments[_key];
|
|
160
130
|
}
|
|
161
131
|
if (componetRenderMode && SubComponent) {
|
|
162
|
-
if (
|
|
163
|
-
|
|
132
|
+
if (componentSetterRegistry.current) {
|
|
133
|
+
componentSetterRegistry.current({
|
|
164
134
|
component: SubComponent
|
|
165
135
|
});
|
|
136
|
+
} else {
|
|
137
|
+
logger('[Garfish] MicroApp for "'.concat(appInfo.name, '" tried to mount, but no active component setter was found.'));
|
|
166
138
|
}
|
|
167
139
|
return void 0;
|
|
168
140
|
} else {
|
|
@@ -183,7 +155,7 @@ or directly pass the "basename":
|
|
|
183
155
|
};
|
|
184
156
|
}
|
|
185
157
|
});
|
|
186
|
-
|
|
158
|
+
setLoadingState({
|
|
187
159
|
isLoading: true,
|
|
188
160
|
error: null
|
|
189
161
|
});
|
|
@@ -192,7 +164,7 @@ or directly pass the "basename":
|
|
|
192
164
|
});
|
|
193
165
|
function _renderApp() {
|
|
194
166
|
_renderApp = _async_to_generator(function() {
|
|
195
|
-
var
|
|
167
|
+
var appInstance, error;
|
|
196
168
|
return _ts_generator(this, function(_state) {
|
|
197
169
|
switch (_state.label) {
|
|
198
170
|
case 0:
|
|
@@ -202,27 +174,17 @@ or directly pass the "basename":
|
|
|
202
174
|
,
|
|
203
175
|
7
|
|
204
176
|
]);
|
|
205
|
-
if ((_abortControllerRef_current = abortControllerRef.current) === null || _abortControllerRef_current === void 0 ? void 0 : _abortControllerRef_current.signal.aborted) {
|
|
206
|
-
return [
|
|
207
|
-
2
|
|
208
|
-
];
|
|
209
|
-
}
|
|
210
177
|
return [
|
|
211
178
|
4,
|
|
212
179
|
Garfish.loadApp(appInfo.name, loadAppOptions)
|
|
213
180
|
];
|
|
214
181
|
case 1:
|
|
215
182
|
appInstance = _state.sent();
|
|
216
|
-
if ((_abortControllerRef_current1 = abortControllerRef.current) === null || _abortControllerRef_current1 === void 0 ? void 0 : _abortControllerRef_current1.signal.aborted) {
|
|
217
|
-
return [
|
|
218
|
-
2
|
|
219
|
-
];
|
|
220
|
-
}
|
|
221
183
|
if (!appInstance) {
|
|
222
184
|
throw new Error('MicroApp Garfish.loadApp "'.concat(appInfo.name, '" result is null'));
|
|
223
185
|
}
|
|
224
186
|
appRef.current = appInstance;
|
|
225
|
-
|
|
187
|
+
setLoadingState({
|
|
226
188
|
isLoading: false
|
|
227
189
|
});
|
|
228
190
|
if (!(appInstance.mounted && appInstance.appInfo.cache))
|
|
@@ -263,12 +225,10 @@ or directly pass the "basename":
|
|
|
263
225
|
];
|
|
264
226
|
case 6:
|
|
265
227
|
error = _state.sent();
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
});
|
|
271
|
-
}
|
|
228
|
+
setLoadingState({
|
|
229
|
+
isLoading: true,
|
|
230
|
+
error
|
|
231
|
+
});
|
|
272
232
|
return [
|
|
273
233
|
3,
|
|
274
234
|
7
|
|
@@ -284,10 +244,7 @@ or directly pass the "basename":
|
|
|
284
244
|
}
|
|
285
245
|
renderApp();
|
|
286
246
|
return function() {
|
|
287
|
-
|
|
288
|
-
if (abortControllerRef.current) {
|
|
289
|
-
abortControllerRef.current.abort();
|
|
290
|
-
}
|
|
247
|
+
componentSetterRegistry.current = null;
|
|
291
248
|
if (appRef.current) {
|
|
292
249
|
var _$appInfo = appRef.current.appInfo;
|
|
293
250
|
if (_$appInfo.cache) {
|
|
@@ -302,38 +259,10 @@ or directly pass the "basename":
|
|
|
302
259
|
}
|
|
303
260
|
};
|
|
304
261
|
}, []);
|
|
305
|
-
useEffect(function() {
|
|
306
|
-
return function() {
|
|
307
|
-
if (SubModuleComponent && destroyRef.current && isMountedRef.current) {
|
|
308
|
-
logger("MicroApp SubModuleComponent cleanup");
|
|
309
|
-
try {
|
|
310
|
-
destroyRef.current();
|
|
311
|
-
} catch (error) {
|
|
312
|
-
logger("Error during SubModuleComponent cleanup:", error);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
}, [
|
|
317
|
-
SubModuleComponent
|
|
318
|
-
]);
|
|
319
|
-
var SafeSubModuleComponent = useCallback(function() {
|
|
320
|
-
if (!SubModuleComponent || !isMountedRef.current) {
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
return /* @__PURE__ */ _jsx(MicroAppMountContext.Provider, {
|
|
324
|
-
value: {
|
|
325
|
-
isMounted: isMountedRef.current
|
|
326
|
-
},
|
|
327
|
-
children: /* @__PURE__ */ _jsx(SubModuleComponent, _object_spread({}, props))
|
|
328
|
-
});
|
|
329
|
-
}, [
|
|
330
|
-
SubModuleComponent,
|
|
331
|
-
props
|
|
332
|
-
]);
|
|
333
262
|
return /* @__PURE__ */ _jsx(_Fragment, {
|
|
334
263
|
children: /* @__PURE__ */ _jsx("div", {
|
|
335
264
|
id: domId,
|
|
336
|
-
children: SubModuleComponent && /* @__PURE__ */ _jsx(
|
|
265
|
+
children: SubModuleComponent && /* @__PURE__ */ _jsx(SubModuleComponent, _object_spread({}, props))
|
|
337
266
|
})
|
|
338
267
|
});
|
|
339
268
|
}
|
|
@@ -354,6 +283,5 @@ function generateApps(options, manifest) {
|
|
|
354
283
|
}
|
|
355
284
|
export {
|
|
356
285
|
generateApps,
|
|
357
|
-
pathJoin
|
|
358
|
-
useMicroAppMountStatus
|
|
286
|
+
pathJoin
|
|
359
287
|
};
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { RuntimeReactContext } from "@meta/runtime";
|
|
3
3
|
import Garfish from "garfish";
|
|
4
|
-
import {
|
|
4
|
+
import { useContext, useEffect, useRef, useState } from "react";
|
|
5
5
|
import { generateSubAppContainerKey, logger } from "../../util";
|
|
6
6
|
import { Loadable } from "../loadable";
|
|
7
|
-
const MicroAppMountContext = /* @__PURE__ */ createContext({
|
|
8
|
-
isMounted: true
|
|
9
|
-
});
|
|
10
|
-
const useMicroAppMountStatus = () => {
|
|
11
|
-
const { isMounted } = useContext(MicroAppMountContext);
|
|
12
|
-
return isMounted;
|
|
13
|
-
};
|
|
14
7
|
function pathJoin(...args) {
|
|
15
8
|
const res = args.reduce((res2, path) => {
|
|
16
9
|
let nPath = path;
|
|
@@ -30,6 +23,9 @@ function pathJoin(...args) {
|
|
|
30
23
|
}
|
|
31
24
|
function getAppInstance(options, appInfo, manifest) {
|
|
32
25
|
let locationHref = "";
|
|
26
|
+
const componentSetterRegistry = {
|
|
27
|
+
current: null
|
|
28
|
+
};
|
|
33
29
|
function MicroApp(props) {
|
|
34
30
|
var _context_router, _context_router1, _context_router2, _context_router3, _context_router4;
|
|
35
31
|
const appRef = useRef(null);
|
|
@@ -37,9 +33,6 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
37
33
|
const [{ component: SubModuleComponent }, setSubModuleComponent] = useState({
|
|
38
34
|
component: null
|
|
39
35
|
});
|
|
40
|
-
const destroyRef = useRef(null);
|
|
41
|
-
const isMountedRef = useRef(true);
|
|
42
|
-
const abortControllerRef = useRef(null);
|
|
43
36
|
const context = useContext(RuntimeReactContext);
|
|
44
37
|
var _props_useRouteMatch;
|
|
45
38
|
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;
|
|
@@ -102,14 +95,8 @@ or directly pass the "basename":
|
|
|
102
95
|
location
|
|
103
96
|
]);
|
|
104
97
|
useEffect(() => {
|
|
98
|
+
componentSetterRegistry.current = setSubModuleComponent;
|
|
105
99
|
const { setLoadingState, ...userProps } = props;
|
|
106
|
-
abortControllerRef.current = new AbortController();
|
|
107
|
-
const safeSetLoadingState = (state) => {
|
|
108
|
-
var _abortControllerRef_current;
|
|
109
|
-
if (isMountedRef.current && !((_abortControllerRef_current = abortControllerRef.current) === null || _abortControllerRef_current === void 0 ? void 0 : _abortControllerRef_current.signal.aborted)) {
|
|
110
|
-
setLoadingState(state);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
100
|
const loadAppOptions = {
|
|
114
101
|
cache: true,
|
|
115
102
|
insulationVariable: [
|
|
@@ -127,33 +114,15 @@ or directly pass the "basename":
|
|
|
127
114
|
const { render, destroy, SubModuleComponent: SubModuleComponent2, jupiter_submodule_app_key } = provider;
|
|
128
115
|
const SubComponent = SubModuleComponent2 || jupiter_submodule_app_key;
|
|
129
116
|
const componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
|
|
130
|
-
if (destroy) {
|
|
131
|
-
destroyRef.current = () => {
|
|
132
|
-
const dom = document.getElementById(domId);
|
|
133
|
-
if (dom) {
|
|
134
|
-
const destroyProps = {
|
|
135
|
-
dom,
|
|
136
|
-
basename,
|
|
137
|
-
appName: appInfo.name,
|
|
138
|
-
appRenderInfo: {},
|
|
139
|
-
props: {
|
|
140
|
-
...appInfo.props,
|
|
141
|
-
...userProps
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
destroy.apply(provider, [
|
|
145
|
-
destroyProps
|
|
146
|
-
]);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
117
|
return {
|
|
151
118
|
mount: (...props2) => {
|
|
152
119
|
if (componetRenderMode && SubComponent) {
|
|
153
|
-
if (
|
|
154
|
-
|
|
120
|
+
if (componentSetterRegistry.current) {
|
|
121
|
+
componentSetterRegistry.current({
|
|
155
122
|
component: SubComponent
|
|
156
123
|
});
|
|
124
|
+
} else {
|
|
125
|
+
logger(`[Garfish] MicroApp for "${appInfo.name}" tried to mount, but no active component setter was found.`);
|
|
157
126
|
}
|
|
158
127
|
return void 0;
|
|
159
128
|
} else {
|
|
@@ -171,7 +140,7 @@ or directly pass the "basename":
|
|
|
171
140
|
};
|
|
172
141
|
}
|
|
173
142
|
};
|
|
174
|
-
|
|
143
|
+
setLoadingState({
|
|
175
144
|
isLoading: true,
|
|
176
145
|
error: null
|
|
177
146
|
});
|
|
@@ -180,19 +149,12 @@ or directly pass the "basename":
|
|
|
180
149
|
});
|
|
181
150
|
async function renderApp() {
|
|
182
151
|
try {
|
|
183
|
-
var _abortControllerRef_current, _abortControllerRef_current1;
|
|
184
|
-
if ((_abortControllerRef_current = abortControllerRef.current) === null || _abortControllerRef_current === void 0 ? void 0 : _abortControllerRef_current.signal.aborted) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
152
|
const appInstance = await Garfish.loadApp(appInfo.name, loadAppOptions);
|
|
188
|
-
if ((_abortControllerRef_current1 = abortControllerRef.current) === null || _abortControllerRef_current1 === void 0 ? void 0 : _abortControllerRef_current1.signal.aborted) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
153
|
if (!appInstance) {
|
|
192
154
|
throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
|
|
193
155
|
}
|
|
194
156
|
appRef.current = appInstance;
|
|
195
|
-
|
|
157
|
+
setLoadingState({
|
|
196
158
|
isLoading: false
|
|
197
159
|
});
|
|
198
160
|
if (appInstance.mounted && appInstance.appInfo.cache) {
|
|
@@ -209,21 +171,15 @@ or directly pass the "basename":
|
|
|
209
171
|
await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
|
|
210
172
|
}
|
|
211
173
|
} catch (error) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
error
|
|
217
|
-
});
|
|
218
|
-
}
|
|
174
|
+
setLoadingState({
|
|
175
|
+
isLoading: true,
|
|
176
|
+
error
|
|
177
|
+
});
|
|
219
178
|
}
|
|
220
179
|
}
|
|
221
180
|
renderApp();
|
|
222
181
|
return () => {
|
|
223
|
-
|
|
224
|
-
if (abortControllerRef.current) {
|
|
225
|
-
abortControllerRef.current.abort();
|
|
226
|
-
}
|
|
182
|
+
componentSetterRegistry.current = null;
|
|
227
183
|
if (appRef.current) {
|
|
228
184
|
const { appInfo: appInfo2 } = appRef.current;
|
|
229
185
|
if (appInfo2.cache) {
|
|
@@ -238,40 +194,12 @@ or directly pass the "basename":
|
|
|
238
194
|
}
|
|
239
195
|
};
|
|
240
196
|
}, []);
|
|
241
|
-
useEffect(() => {
|
|
242
|
-
return () => {
|
|
243
|
-
if (SubModuleComponent && destroyRef.current && isMountedRef.current) {
|
|
244
|
-
logger("MicroApp SubModuleComponent cleanup");
|
|
245
|
-
try {
|
|
246
|
-
destroyRef.current();
|
|
247
|
-
} catch (error) {
|
|
248
|
-
logger("Error during SubModuleComponent cleanup:", error);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
}, [
|
|
253
|
-
SubModuleComponent
|
|
254
|
-
]);
|
|
255
|
-
const SafeSubModuleComponent = useCallback(() => {
|
|
256
|
-
if (!SubModuleComponent || !isMountedRef.current) {
|
|
257
|
-
return null;
|
|
258
|
-
}
|
|
259
|
-
return /* @__PURE__ */ _jsx(MicroAppMountContext.Provider, {
|
|
260
|
-
value: {
|
|
261
|
-
isMounted: isMountedRef.current
|
|
262
|
-
},
|
|
263
|
-
children: /* @__PURE__ */ _jsx(SubModuleComponent, {
|
|
264
|
-
...props
|
|
265
|
-
})
|
|
266
|
-
});
|
|
267
|
-
}, [
|
|
268
|
-
SubModuleComponent,
|
|
269
|
-
props
|
|
270
|
-
]);
|
|
271
197
|
return /* @__PURE__ */ _jsx(_Fragment, {
|
|
272
198
|
children: /* @__PURE__ */ _jsx("div", {
|
|
273
199
|
id: domId,
|
|
274
|
-
children: SubModuleComponent && /* @__PURE__ */ _jsx(
|
|
200
|
+
children: SubModuleComponent && /* @__PURE__ */ _jsx(SubModuleComponent, {
|
|
201
|
+
...props
|
|
202
|
+
})
|
|
275
203
|
})
|
|
276
204
|
});
|
|
277
205
|
}
|
|
@@ -292,6 +220,5 @@ function generateApps(options, manifest) {
|
|
|
292
220
|
}
|
|
293
221
|
export {
|
|
294
222
|
generateApps,
|
|
295
|
-
pathJoin
|
|
296
|
-
useMicroAppMountStatus
|
|
223
|
+
pathJoin
|
|
297
224
|
};
|
|
@@ -5,7 +5,6 @@ export interface Provider extends interfaces.Provider {
|
|
|
5
5
|
SubModuleComponent?: React.ComponentType<any>;
|
|
6
6
|
jupiter_submodule_app_key?: React.ComponentType<any>;
|
|
7
7
|
}
|
|
8
|
-
export declare const useMicroAppMountStatus: () => boolean;
|
|
9
8
|
export interface AppMap {
|
|
10
9
|
[key: string]: React.FC<MicroComponentProps>;
|
|
11
10
|
}
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.68.13-alpha.
|
|
18
|
+
"version": "2.68.13-alpha.4",
|
|
19
19
|
"jsnext:source": "./src/cli/index.ts",
|
|
20
20
|
"types": "./dist/types/cli/index.d.ts",
|
|
21
21
|
"typesVersions": {
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"debug": "4.3.7",
|
|
70
70
|
"garfish": "^1.8.1",
|
|
71
71
|
"react-loadable": "^5.5.0",
|
|
72
|
-
"@modern-js/runtime-utils": "2.68.12",
|
|
73
72
|
"@modern-js/plugin-v2": "2.68.12",
|
|
74
|
-
"@modern-js/utils": "2.68.12"
|
|
73
|
+
"@modern-js/utils": "2.68.12",
|
|
74
|
+
"@modern-js/runtime-utils": "2.68.12"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@modern-js/runtime": "^2.68.12",
|
|
@@ -93,12 +93,12 @@
|
|
|
93
93
|
"react-dom": "^18.3.1",
|
|
94
94
|
"react-router-dom": "6.27.0",
|
|
95
95
|
"typescript": "^5",
|
|
96
|
-
"@modern-js/app-tools": "2.68.12",
|
|
97
96
|
"@scripts/build": "2.66.0",
|
|
97
|
+
"@modern-js/app-tools": "2.68.12",
|
|
98
98
|
"@modern-js/core": "2.68.12",
|
|
99
|
-
"@modern-js/plugin-router-v5": "2.68.12",
|
|
100
|
-
"@modern-js/types": "2.68.12",
|
|
101
99
|
"@modern-js/runtime": "2.68.12",
|
|
100
|
+
"@modern-js/types": "2.68.12",
|
|
101
|
+
"@modern-js/plugin-router-v5": "2.68.12",
|
|
102
102
|
"@scripts/jest-config": "2.66.0"
|
|
103
103
|
},
|
|
104
104
|
"sideEffects": false,
|