@modern-js/plugin-garfish 2.68.19-alpha.0 → 2.68.19-alpha.2

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.
@@ -96,9 +96,11 @@ function getAppInstance(options, appInfo, manifest) {
96
96
  const previousPropsRef = (0, import_react.useRef)(props);
97
97
  const propsUpdateCounterRef = (0, import_react.useRef)(0);
98
98
  const domId = (0, import_util.generateSubAppContainerKey)(appInfo);
99
- const [{ component: SubModuleComponent }, setSubModuleComponent] = (0, import_react.useState)({
100
- component: null
99
+ const [{ component: SubModuleComponent, isFromJupiter }, setSubModuleComponent] = (0, import_react.useState)({
100
+ component: null,
101
+ isFromJupiter: false
101
102
  });
103
+ const [propsUpdateKey, setPropsUpdateKey] = (0, import_react.useState)(0);
102
104
  const context = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
103
105
  var _props_useRouteMatch;
104
106
  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;
@@ -183,18 +185,10 @@ or directly pass the "basename":
183
185
  }
184
186
  });
185
187
  if (!deepEqualExcludeFunctions(prevPropsForCompare, currentPropsForCompare)) {
186
- var _appRef_current;
187
188
  previousPropsRef.current = props;
188
189
  propsRef.current = props;
189
190
  propsUpdateCounterRef.current += 1;
190
- if ((_appRef_current = appRef.current) === null || _appRef_current === void 0 ? void 0 : _appRef_current.mounted) {
191
- window.dispatchEvent(new CustomEvent("garfishPropsUpdated", {
192
- detail: {
193
- appName: appInfo.name,
194
- props
195
- }
196
- }));
197
- }
191
+ setPropsUpdateKey((prev) => prev + 1);
198
192
  }
199
193
  }, [
200
194
  props,
@@ -202,7 +196,7 @@ or directly pass the "basename":
202
196
  ]);
203
197
  (0, import_react.useEffect)(() => {
204
198
  componentSetterRegistry.current = setSubModuleComponent;
205
- const { setLoadingState, ...userProps } = propsRef.current;
199
+ const { setLoadingState: setLoadingState2, ...userProps } = propsRef.current;
206
200
  const loadAppOptions = {
207
201
  cache: true,
208
202
  insulationVariable: [
@@ -219,13 +213,15 @@ or directly pass the "basename":
219
213
  customLoader: (provider) => {
220
214
  const { render, destroy, SubModuleComponent: SubModuleComponent2, jupiter_submodule_app_key } = provider;
221
215
  const SubComponent = SubModuleComponent2 || jupiter_submodule_app_key;
216
+ const isFromJupiter2 = !SubModuleComponent2 && !!jupiter_submodule_app_key;
222
217
  const componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
223
218
  return {
224
219
  mount: (...props2) => {
225
220
  if (componetRenderMode && SubComponent) {
226
221
  if (componentSetterRegistry.current) {
227
222
  componentSetterRegistry.current({
228
- component: SubComponent
223
+ component: SubComponent,
224
+ isFromJupiter: isFromJupiter2
229
225
  });
230
226
  } else {
231
227
  (0, import_util.logger)(`[Garfish] MicroApp for "${appInfo.name}" tried to mount, but no active component setter was found.`);
@@ -246,7 +242,7 @@ or directly pass the "basename":
246
242
  };
247
243
  }
248
244
  };
249
- setLoadingState({
245
+ setLoadingState2({
250
246
  isLoading: true,
251
247
  error: null
252
248
  });
@@ -260,7 +256,7 @@ or directly pass the "basename":
260
256
  throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
261
257
  }
262
258
  appRef.current = appInstance;
263
- setLoadingState({
259
+ setLoadingState2({
264
260
  isLoading: false
265
261
  });
266
262
  if (appInstance.mounted && appInstance.appInfo.cache) {
@@ -277,7 +273,7 @@ or directly pass the "basename":
277
273
  await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
278
274
  }
279
275
  } catch (error) {
280
- setLoadingState({
276
+ setLoadingState2({
281
277
  isLoading: true,
282
278
  error
283
279
  });
@@ -304,12 +300,36 @@ or directly pass the "basename":
304
300
  domId,
305
301
  appInfo.name
306
302
  ]);
303
+ (0, import_react.useEffect)(() => {
304
+ var _appRef_current;
305
+ if ((_appRef_current = appRef.current) === null || _appRef_current === void 0 ? void 0 : _appRef_current.appInfo) {
306
+ const { setLoadingState: setLoadingState2, ...updatedProps } = props;
307
+ const updatedPropsWithKey = {
308
+ ...appInfo.props,
309
+ ...updatedProps,
310
+ _garfishPropsUpdateKey: propsUpdateKey
311
+ };
312
+ appRef.current.appInfo.props = updatedPropsWithKey;
313
+ }
314
+ }, [
315
+ propsUpdateKey,
316
+ props
317
+ ]);
318
+ const { setLoadingState, ...renderProps } = props;
319
+ const finalRenderProps = {
320
+ ...renderProps,
321
+ _garfishPropsUpdateKey: propsUpdateKey
322
+ };
323
+ const componentKey = isFromJupiter ? void 0 : `${appInfo.name}-${propsUpdateKey}`;
307
324
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
308
325
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
309
326
  id: domId,
310
327
  children: SubModuleComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SubModuleComponent, {
311
- ...propsRef.current
312
- }, `${appInfo.name}-${propsUpdateCounterRef.current}`)
328
+ ...componentKey ? {
329
+ key: componentKey
330
+ } : {},
331
+ ...finalRenderProps
332
+ })
313
333
  })
314
334
  });
315
335
  }
@@ -95,8 +95,10 @@ function getAppInstance(options, appInfo, manifest) {
95
95
  var propsUpdateCounterRef = useRef(0);
96
96
  var domId = generateSubAppContainerKey(appInfo);
97
97
  var _useState = _sliced_to_array(useState({
98
- component: null
99
- }), 2), _useState_ = _useState[0], SubModuleComponent = _useState_.component, setSubModuleComponent = _useState[1];
98
+ component: null,
99
+ isFromJupiter: false
100
+ }), 2), _useState_ = _useState[0], SubModuleComponent = _useState_.component, isFromJupiter = _useState_.isFromJupiter, setSubModuleComponent = _useState[1];
101
+ var _useState1 = _sliced_to_array(useState(0), 2), propsUpdateKey = _useState1[0], setPropsUpdateKey = _useState1[1];
100
102
  var context = useContext(RuntimeReactContext);
101
103
  var _props_useRouteMatch;
102
104
  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;
@@ -175,18 +177,12 @@ or directly pass the "basename":
175
177
  }
176
178
  });
177
179
  if (!deepEqualExcludeFunctions(prevPropsForCompare, currentPropsForCompare)) {
178
- var _appRef_current;
179
180
  previousPropsRef.current = props;
180
181
  propsRef.current = props;
181
182
  propsUpdateCounterRef.current += 1;
182
- if ((_appRef_current = appRef.current) === null || _appRef_current === void 0 ? void 0 : _appRef_current.mounted) {
183
- window.dispatchEvent(new CustomEvent("garfishPropsUpdated", {
184
- detail: {
185
- appName: appInfo.name,
186
- props
187
- }
188
- }));
189
- }
183
+ setPropsUpdateKey(function(prev) {
184
+ return prev + 1;
185
+ });
190
186
  }
191
187
  }, [
192
188
  props,
@@ -197,7 +193,7 @@ or directly pass the "basename":
197
193
  return _renderApp.apply(this, arguments);
198
194
  };
199
195
  componentSetterRegistry.current = setSubModuleComponent;
200
- var _propsRef_current = propsRef.current, setLoadingState = _propsRef_current.setLoadingState, userProps = _object_without_properties(_propsRef_current, [
196
+ var _propsRef_current = propsRef.current, setLoadingState2 = _propsRef_current.setLoadingState, userProps = _object_without_properties(_propsRef_current, [
201
197
  "setLoadingState"
202
198
  ]);
203
199
  var loadAppOptions = _object_spread_props(_object_spread({
@@ -212,6 +208,7 @@ or directly pass the "basename":
212
208
  customLoader: function(provider) {
213
209
  var render = provider.render, destroy = provider.destroy, SubModuleComponent2 = provider.SubModuleComponent, jupiter_submodule_app_key = provider.jupiter_submodule_app_key;
214
210
  var SubComponent = SubModuleComponent2 || jupiter_submodule_app_key;
211
+ var isFromJupiter2 = !SubModuleComponent2 && !!jupiter_submodule_app_key;
215
212
  var componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
216
213
  return {
217
214
  mount: function() {
@@ -221,7 +218,8 @@ or directly pass the "basename":
221
218
  if (componetRenderMode && SubComponent) {
222
219
  if (componentSetterRegistry.current) {
223
220
  componentSetterRegistry.current({
224
- component: SubComponent
221
+ component: SubComponent,
222
+ isFromJupiter: isFromJupiter2
225
223
  });
226
224
  } else {
227
225
  logger('[Garfish] MicroApp for "'.concat(appInfo.name, '" tried to mount, but no active component setter was found.'));
@@ -245,7 +243,7 @@ or directly pass the "basename":
245
243
  };
246
244
  }
247
245
  });
248
- setLoadingState({
246
+ setLoadingState2({
249
247
  isLoading: true,
250
248
  error: null
251
249
  });
@@ -274,7 +272,7 @@ or directly pass the "basename":
274
272
  throw new Error('MicroApp Garfish.loadApp "'.concat(appInfo.name, '" result is null'));
275
273
  }
276
274
  appRef.current = appInstance;
277
- setLoadingState({
275
+ setLoadingState2({
278
276
  isLoading: false
279
277
  });
280
278
  if (!(appInstance.mounted && appInstance.appInfo.cache))
@@ -315,7 +313,7 @@ or directly pass the "basename":
315
313
  ];
316
314
  case 6:
317
315
  error = _state.sent();
318
- setLoadingState({
316
+ setLoadingState2({
319
317
  isLoading: true,
320
318
  error
321
319
  });
@@ -353,10 +351,34 @@ or directly pass the "basename":
353
351
  domId,
354
352
  appInfo.name
355
353
  ]);
354
+ useEffect(function() {
355
+ var _appRef_current;
356
+ if ((_appRef_current = appRef.current) === null || _appRef_current === void 0 ? void 0 : _appRef_current.appInfo) {
357
+ var setLoadingState2 = props.setLoadingState, updatedProps = _object_without_properties(props, [
358
+ "setLoadingState"
359
+ ]);
360
+ var updatedPropsWithKey = _object_spread_props(_object_spread({}, appInfo.props, updatedProps), {
361
+ _garfishPropsUpdateKey: propsUpdateKey
362
+ });
363
+ appRef.current.appInfo.props = updatedPropsWithKey;
364
+ }
365
+ }, [
366
+ propsUpdateKey,
367
+ props
368
+ ]);
369
+ var setLoadingState = props.setLoadingState, renderProps = _object_without_properties(props, [
370
+ "setLoadingState"
371
+ ]);
372
+ var finalRenderProps = _object_spread_props(_object_spread({}, renderProps), {
373
+ _garfishPropsUpdateKey: propsUpdateKey
374
+ });
375
+ var componentKey = isFromJupiter ? void 0 : "".concat(appInfo.name, "-").concat(propsUpdateKey);
356
376
  return /* @__PURE__ */ _jsx(_Fragment, {
357
377
  children: /* @__PURE__ */ _jsx("div", {
358
378
  id: domId,
359
- children: SubModuleComponent && /* @__PURE__ */ _jsx(SubModuleComponent, _object_spread({}, propsRef.current), "".concat(appInfo.name, "-").concat(propsUpdateCounterRef.current))
379
+ children: SubModuleComponent && /* @__PURE__ */ _jsx(SubModuleComponent, _object_spread({}, componentKey ? {
380
+ key: componentKey
381
+ } : {}, finalRenderProps))
360
382
  })
361
383
  });
362
384
  }
@@ -62,9 +62,11 @@ function getAppInstance(options, appInfo, manifest) {
62
62
  const previousPropsRef = useRef(props);
63
63
  const propsUpdateCounterRef = useRef(0);
64
64
  const domId = generateSubAppContainerKey(appInfo);
65
- const [{ component: SubModuleComponent }, setSubModuleComponent] = useState({
66
- component: null
65
+ const [{ component: SubModuleComponent, isFromJupiter }, setSubModuleComponent] = useState({
66
+ component: null,
67
+ isFromJupiter: false
67
68
  });
69
+ const [propsUpdateKey, setPropsUpdateKey] = useState(0);
68
70
  const context = useContext(RuntimeReactContext);
69
71
  var _props_useRouteMatch;
70
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;
@@ -149,18 +151,10 @@ or directly pass the "basename":
149
151
  }
150
152
  });
151
153
  if (!deepEqualExcludeFunctions(prevPropsForCompare, currentPropsForCompare)) {
152
- var _appRef_current;
153
154
  previousPropsRef.current = props;
154
155
  propsRef.current = props;
155
156
  propsUpdateCounterRef.current += 1;
156
- if ((_appRef_current = appRef.current) === null || _appRef_current === void 0 ? void 0 : _appRef_current.mounted) {
157
- window.dispatchEvent(new CustomEvent("garfishPropsUpdated", {
158
- detail: {
159
- appName: appInfo.name,
160
- props
161
- }
162
- }));
163
- }
157
+ setPropsUpdateKey((prev) => prev + 1);
164
158
  }
165
159
  }, [
166
160
  props,
@@ -168,7 +162,7 @@ or directly pass the "basename":
168
162
  ]);
169
163
  useEffect(() => {
170
164
  componentSetterRegistry.current = setSubModuleComponent;
171
- const { setLoadingState, ...userProps } = propsRef.current;
165
+ const { setLoadingState: setLoadingState2, ...userProps } = propsRef.current;
172
166
  const loadAppOptions = {
173
167
  cache: true,
174
168
  insulationVariable: [
@@ -185,13 +179,15 @@ or directly pass the "basename":
185
179
  customLoader: (provider) => {
186
180
  const { render, destroy, SubModuleComponent: SubModuleComponent2, jupiter_submodule_app_key } = provider;
187
181
  const SubComponent = SubModuleComponent2 || jupiter_submodule_app_key;
182
+ const isFromJupiter2 = !SubModuleComponent2 && !!jupiter_submodule_app_key;
188
183
  const componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
189
184
  return {
190
185
  mount: (...props2) => {
191
186
  if (componetRenderMode && SubComponent) {
192
187
  if (componentSetterRegistry.current) {
193
188
  componentSetterRegistry.current({
194
- component: SubComponent
189
+ component: SubComponent,
190
+ isFromJupiter: isFromJupiter2
195
191
  });
196
192
  } else {
197
193
  logger(`[Garfish] MicroApp for "${appInfo.name}" tried to mount, but no active component setter was found.`);
@@ -212,7 +208,7 @@ or directly pass the "basename":
212
208
  };
213
209
  }
214
210
  };
215
- setLoadingState({
211
+ setLoadingState2({
216
212
  isLoading: true,
217
213
  error: null
218
214
  });
@@ -226,7 +222,7 @@ or directly pass the "basename":
226
222
  throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
227
223
  }
228
224
  appRef.current = appInstance;
229
- setLoadingState({
225
+ setLoadingState2({
230
226
  isLoading: false
231
227
  });
232
228
  if (appInstance.mounted && appInstance.appInfo.cache) {
@@ -243,7 +239,7 @@ or directly pass the "basename":
243
239
  await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
244
240
  }
245
241
  } catch (error) {
246
- setLoadingState({
242
+ setLoadingState2({
247
243
  isLoading: true,
248
244
  error
249
245
  });
@@ -270,12 +266,36 @@ or directly pass the "basename":
270
266
  domId,
271
267
  appInfo.name
272
268
  ]);
269
+ useEffect(() => {
270
+ var _appRef_current;
271
+ if ((_appRef_current = appRef.current) === null || _appRef_current === void 0 ? void 0 : _appRef_current.appInfo) {
272
+ const { setLoadingState: setLoadingState2, ...updatedProps } = props;
273
+ const updatedPropsWithKey = {
274
+ ...appInfo.props,
275
+ ...updatedProps,
276
+ _garfishPropsUpdateKey: propsUpdateKey
277
+ };
278
+ appRef.current.appInfo.props = updatedPropsWithKey;
279
+ }
280
+ }, [
281
+ propsUpdateKey,
282
+ props
283
+ ]);
284
+ const { setLoadingState, ...renderProps } = props;
285
+ const finalRenderProps = {
286
+ ...renderProps,
287
+ _garfishPropsUpdateKey: propsUpdateKey
288
+ };
289
+ const componentKey = isFromJupiter ? void 0 : `${appInfo.name}-${propsUpdateKey}`;
273
290
  return /* @__PURE__ */ _jsx(_Fragment, {
274
291
  children: /* @__PURE__ */ _jsx("div", {
275
292
  id: domId,
276
293
  children: SubModuleComponent && /* @__PURE__ */ _jsx(SubModuleComponent, {
277
- ...propsRef.current
278
- }, `${appInfo.name}-${propsUpdateCounterRef.current}`)
294
+ ...componentKey ? {
295
+ key: componentKey
296
+ } : {},
297
+ ...finalRenderProps
298
+ })
279
299
  })
280
300
  });
281
301
  }
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.68.19-alpha.0",
18
+ "version": "2.68.19-alpha.2",
19
19
  "jsnext:source": "./src/cli/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "typesVersions": {
@@ -69,8 +69,8 @@
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.18",
73
72
  "@modern-js/plugin-v2": "2.68.18",
73
+ "@modern-js/runtime-utils": "2.68.18",
74
74
  "@modern-js/utils": "2.68.18"
75
75
  },
76
76
  "peerDependencies": {
@@ -97,9 +97,9 @@
97
97
  "@scripts/build": "2.66.0",
98
98
  "@modern-js/core": "2.68.18",
99
99
  "@modern-js/plugin-router-v5": "2.68.18",
100
+ "@modern-js/types": "2.68.18",
100
101
  "@modern-js/runtime": "2.68.18",
101
- "@scripts/jest-config": "2.66.0",
102
- "@modern-js/types": "2.68.18"
102
+ "@scripts/jest-config": "2.66.0"
103
103
  },
104
104
  "sideEffects": false,
105
105
  "publishConfig": {