@modern-js/plugin-garfish 2.68.13-alpha.0 → 2.68.13-alpha.1

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.
@@ -65,6 +65,7 @@ function getAppInstance(options, appInfo, manifest) {
65
65
  component: null
66
66
  });
67
67
  const destroyRef = (0, import_react.useRef)(null);
68
+ const isMountedRef = (0, import_react.useRef)(true);
68
69
  const context = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
69
70
  var _props_useRouteMatch;
70
71
  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;
@@ -128,6 +129,11 @@ or directly pass the "basename":
128
129
  ]);
129
130
  (0, import_react.useEffect)(() => {
130
131
  const { setLoadingState, ...userProps } = props;
132
+ const safeSetLoadingState = (state) => {
133
+ if (isMountedRef.current) {
134
+ setLoadingState(state);
135
+ }
136
+ };
131
137
  const loadAppOptions = {
132
138
  cache: true,
133
139
  insulationVariable: [
@@ -187,7 +193,7 @@ or directly pass the "basename":
187
193
  };
188
194
  }
189
195
  };
190
- setLoadingState({
196
+ safeSetLoadingState({
191
197
  isLoading: true,
192
198
  error: null
193
199
  });
@@ -201,7 +207,7 @@ or directly pass the "basename":
201
207
  throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
202
208
  }
203
209
  appRef.current = appInstance;
204
- setLoadingState({
210
+ safeSetLoadingState({
205
211
  isLoading: false
206
212
  });
207
213
  if (appInstance.mounted && appInstance.appInfo.cache) {
@@ -218,7 +224,7 @@ or directly pass the "basename":
218
224
  await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
219
225
  }
220
226
  } catch (error) {
221
- setLoadingState({
227
+ safeSetLoadingState({
222
228
  isLoading: true,
223
229
  error
224
230
  });
@@ -226,6 +232,7 @@ or directly pass the "basename":
226
232
  }
227
233
  renderApp();
228
234
  return () => {
235
+ isMountedRef.current = false;
229
236
  if (appRef.current) {
230
237
  const { appInfo: appInfo2 } = appRef.current;
231
238
  if (appInfo2.cache) {
@@ -242,7 +249,7 @@ or directly pass the "basename":
242
249
  }, []);
243
250
  (0, import_react.useEffect)(() => {
244
251
  return () => {
245
- if (SubModuleComponent && destroyRef.current) {
252
+ if (SubModuleComponent && destroyRef.current && isMountedRef.current) {
246
253
  (0, import_util.logger)("MicroApp SubModuleComponent cleanup");
247
254
  try {
248
255
  destroyRef.current();
@@ -41,6 +41,7 @@ function getAppInstance(options, appInfo, manifest) {
41
41
  component: null
42
42
  }), 2), _useState_ = _useState[0], SubModuleComponent = _useState_.component, setSubModuleComponent = _useState[1];
43
43
  var destroyRef = useRef(null);
44
+ var isMountedRef = useRef(true);
44
45
  var context = useContext(RuntimeReactContext);
45
46
  var _props_useRouteMatch;
46
47
  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;
@@ -107,6 +108,11 @@ or directly pass the "basename":
107
108
  var setLoadingState = props.setLoadingState, userProps = _object_without_properties(props, [
108
109
  "setLoadingState"
109
110
  ]);
111
+ var safeSetLoadingState = function(state) {
112
+ if (isMountedRef.current) {
113
+ setLoadingState(state);
114
+ }
115
+ };
110
116
  var loadAppOptions = _object_spread_props(_object_spread({
111
117
  cache: true,
112
118
  insulationVariable: _to_consumable_array(appInfo.insulationVariable || []).concat([
@@ -165,7 +171,7 @@ or directly pass the "basename":
165
171
  };
166
172
  }
167
173
  });
168
- setLoadingState({
174
+ safeSetLoadingState({
169
175
  isLoading: true,
170
176
  error: null
171
177
  });
@@ -194,7 +200,7 @@ or directly pass the "basename":
194
200
  throw new Error('MicroApp Garfish.loadApp "'.concat(appInfo.name, '" result is null'));
195
201
  }
196
202
  appRef.current = appInstance;
197
- setLoadingState({
203
+ safeSetLoadingState({
198
204
  isLoading: false
199
205
  });
200
206
  if (!(appInstance.mounted && appInstance.appInfo.cache))
@@ -235,7 +241,7 @@ or directly pass the "basename":
235
241
  ];
236
242
  case 6:
237
243
  error = _state.sent();
238
- setLoadingState({
244
+ safeSetLoadingState({
239
245
  isLoading: true,
240
246
  error
241
247
  });
@@ -254,6 +260,7 @@ or directly pass the "basename":
254
260
  }
255
261
  renderApp();
256
262
  return function() {
263
+ isMountedRef.current = false;
257
264
  if (appRef.current) {
258
265
  var _$appInfo = appRef.current.appInfo;
259
266
  if (_$appInfo.cache) {
@@ -270,7 +277,7 @@ or directly pass the "basename":
270
277
  }, []);
271
278
  useEffect(function() {
272
279
  return function() {
273
- if (SubModuleComponent && destroyRef.current) {
280
+ if (SubModuleComponent && destroyRef.current && isMountedRef.current) {
274
281
  logger("MicroApp SubModuleComponent cleanup");
275
282
  try {
276
283
  destroyRef.current();
@@ -31,6 +31,7 @@ function getAppInstance(options, appInfo, manifest) {
31
31
  component: null
32
32
  });
33
33
  const destroyRef = useRef(null);
34
+ const isMountedRef = useRef(true);
34
35
  const context = useContext(RuntimeReactContext);
35
36
  var _props_useRouteMatch;
36
37
  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;
@@ -94,6 +95,11 @@ or directly pass the "basename":
94
95
  ]);
95
96
  useEffect(() => {
96
97
  const { setLoadingState, ...userProps } = props;
98
+ const safeSetLoadingState = (state) => {
99
+ if (isMountedRef.current) {
100
+ setLoadingState(state);
101
+ }
102
+ };
97
103
  const loadAppOptions = {
98
104
  cache: true,
99
105
  insulationVariable: [
@@ -153,7 +159,7 @@ or directly pass the "basename":
153
159
  };
154
160
  }
155
161
  };
156
- setLoadingState({
162
+ safeSetLoadingState({
157
163
  isLoading: true,
158
164
  error: null
159
165
  });
@@ -167,7 +173,7 @@ or directly pass the "basename":
167
173
  throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
168
174
  }
169
175
  appRef.current = appInstance;
170
- setLoadingState({
176
+ safeSetLoadingState({
171
177
  isLoading: false
172
178
  });
173
179
  if (appInstance.mounted && appInstance.appInfo.cache) {
@@ -184,7 +190,7 @@ or directly pass the "basename":
184
190
  await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
185
191
  }
186
192
  } catch (error) {
187
- setLoadingState({
193
+ safeSetLoadingState({
188
194
  isLoading: true,
189
195
  error
190
196
  });
@@ -192,6 +198,7 @@ or directly pass the "basename":
192
198
  }
193
199
  renderApp();
194
200
  return () => {
201
+ isMountedRef.current = false;
195
202
  if (appRef.current) {
196
203
  const { appInfo: appInfo2 } = appRef.current;
197
204
  if (appInfo2.cache) {
@@ -208,7 +215,7 @@ or directly pass the "basename":
208
215
  }, []);
209
216
  useEffect(() => {
210
217
  return () => {
211
- if (SubModuleComponent && destroyRef.current) {
218
+ if (SubModuleComponent && destroyRef.current && isMountedRef.current) {
212
219
  logger("MicroApp SubModuleComponent cleanup");
213
220
  try {
214
221
  destroyRef.current();
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.68.13-alpha.0",
18
+ "version": "2.68.13-alpha.1",
19
19
  "jsnext:source": "./src/cli/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "typesVersions": {
@@ -93,13 +93,13 @@
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
- "@modern-js/core": "2.68.12",
98
- "@scripts/build": "2.66.0",
99
- "@modern-js/plugin-router-v5": "2.68.12",
100
96
  "@modern-js/runtime": "2.68.12",
97
+ "@scripts/build": "2.66.0",
101
98
  "@modern-js/types": "2.68.12",
102
- "@scripts/jest-config": "2.66.0"
99
+ "@modern-js/app-tools": "2.68.12",
100
+ "@scripts/jest-config": "2.66.0",
101
+ "@modern-js/plugin-router-v5": "2.68.12",
102
+ "@modern-js/core": "2.68.12"
103
103
  },
104
104
  "sideEffects": false,
105
105
  "publishConfig": {