@modern-js/plugin-garfish 2.68.18 → 2.68.19-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.
@@ -55,6 +55,35 @@ function pathJoin(...args) {
55
55
  }, "");
56
56
  return res || "/";
57
57
  }
58
+ function deepEqualExcludeFunctions(prev, next) {
59
+ if (prev === next)
60
+ return true;
61
+ if (!prev || !next)
62
+ return false;
63
+ if (typeof prev !== "object" || typeof next !== "object")
64
+ return false;
65
+ const prevKeys = Object.keys(prev).filter((key) => typeof prev[key] !== "function");
66
+ const nextKeys = Object.keys(next).filter((key) => typeof next[key] !== "function");
67
+ if (prevKeys.length !== nextKeys.length)
68
+ return false;
69
+ for (const key of prevKeys) {
70
+ if (!nextKeys.includes(key))
71
+ return false;
72
+ const prevVal = prev[key];
73
+ const nextVal = next[key];
74
+ if (typeof prevVal === "function" || typeof nextVal === "function") {
75
+ continue;
76
+ }
77
+ if (typeof prevVal === "object" && typeof nextVal === "object") {
78
+ if (!deepEqualExcludeFunctions(prevVal, nextVal)) {
79
+ return false;
80
+ }
81
+ } else if (prevVal !== nextVal) {
82
+ return false;
83
+ }
84
+ }
85
+ return true;
86
+ }
58
87
  function getAppInstance(options, appInfo, manifest) {
59
88
  const componentSetterRegistry = {
60
89
  current: null
@@ -63,6 +92,9 @@ function getAppInstance(options, appInfo, manifest) {
63
92
  var _context_router, _context_router1, _context_router2, _context_router3, _context_router4;
64
93
  const appRef = (0, import_react.useRef)(null);
65
94
  const locationHrefRef = (0, import_react.useRef)("");
95
+ const propsRef = (0, import_react.useRef)(props);
96
+ const previousPropsRef = (0, import_react.useRef)(props);
97
+ const propsUpdateCounterRef = (0, import_react.useRef)(0);
66
98
  const domId = (0, import_util.generateSubAppContainerKey)(appInfo);
67
99
  const [{ component: SubModuleComponent }, setSubModuleComponent] = (0, import_react.useState)({
68
100
  component: null
@@ -133,9 +165,44 @@ or directly pass the "basename":
133
165
  }, [
134
166
  locationPathname
135
167
  ]);
168
+ (0, import_react.useEffect)(() => {
169
+ const prevPropsForCompare = {
170
+ ...previousPropsRef.current
171
+ };
172
+ const currentPropsForCompare = {
173
+ ...props
174
+ };
175
+ Object.keys(prevPropsForCompare).forEach((key) => {
176
+ if (typeof prevPropsForCompare[key] === "function") {
177
+ delete prevPropsForCompare[key];
178
+ }
179
+ });
180
+ Object.keys(currentPropsForCompare).forEach((key) => {
181
+ if (typeof currentPropsForCompare[key] === "function") {
182
+ delete currentPropsForCompare[key];
183
+ }
184
+ });
185
+ if (!deepEqualExcludeFunctions(prevPropsForCompare, currentPropsForCompare)) {
186
+ var _appRef_current;
187
+ previousPropsRef.current = props;
188
+ propsRef.current = props;
189
+ 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
+ }
198
+ }
199
+ }, [
200
+ props,
201
+ appInfo.name
202
+ ]);
136
203
  (0, import_react.useEffect)(() => {
137
204
  componentSetterRegistry.current = setSubModuleComponent;
138
- const { setLoadingState, ...userProps } = props;
205
+ const { setLoadingState, ...userProps } = propsRef.current;
139
206
  const loadAppOptions = {
140
207
  cache: true,
141
208
  insulationVariable: [
@@ -232,13 +299,17 @@ or directly pass the "basename":
232
299
  }
233
300
  }
234
301
  };
235
- }, []);
302
+ }, [
303
+ basename,
304
+ domId,
305
+ appInfo.name
306
+ ]);
236
307
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
237
308
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
238
309
  id: domId,
239
310
  children: SubModuleComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SubModuleComponent, {
240
- ...props
241
- })
311
+ ...propsRef.current
312
+ }, `${appInfo.name}-${propsUpdateCounterRef.current}`)
242
313
  })
243
314
  });
244
315
  }
@@ -4,6 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
5
5
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
6
6
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
7
+ import { _ as _type_of } from "@swc/helpers/_/_type_of";
7
8
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
8
9
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
9
10
  import { RuntimeReactContext } from "@meta/runtime";
@@ -31,6 +32,56 @@ function pathJoin() {
31
32
  }, "");
32
33
  return res || "/";
33
34
  }
35
+ function deepEqualExcludeFunctions(prev, next) {
36
+ if (prev === next)
37
+ return true;
38
+ if (!prev || !next)
39
+ return false;
40
+ if ((typeof prev === "undefined" ? "undefined" : _type_of(prev)) !== "object" || (typeof next === "undefined" ? "undefined" : _type_of(next)) !== "object")
41
+ return false;
42
+ var prevKeys = Object.keys(prev).filter(function(key2) {
43
+ return typeof prev[key2] !== "function";
44
+ });
45
+ var nextKeys = Object.keys(next).filter(function(key2) {
46
+ return typeof next[key2] !== "function";
47
+ });
48
+ if (prevKeys.length !== nextKeys.length)
49
+ return false;
50
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
51
+ try {
52
+ for (var _iterator = prevKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
53
+ var key = _step.value;
54
+ if (!nextKeys.includes(key))
55
+ return false;
56
+ var prevVal = prev[key];
57
+ var nextVal = next[key];
58
+ if (typeof prevVal === "function" || typeof nextVal === "function") {
59
+ continue;
60
+ }
61
+ if ((typeof prevVal === "undefined" ? "undefined" : _type_of(prevVal)) === "object" && (typeof nextVal === "undefined" ? "undefined" : _type_of(nextVal)) === "object") {
62
+ if (!deepEqualExcludeFunctions(prevVal, nextVal)) {
63
+ return false;
64
+ }
65
+ } else if (prevVal !== nextVal) {
66
+ return false;
67
+ }
68
+ }
69
+ } catch (err) {
70
+ _didIteratorError = true;
71
+ _iteratorError = err;
72
+ } finally {
73
+ try {
74
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
75
+ _iterator.return();
76
+ }
77
+ } finally {
78
+ if (_didIteratorError) {
79
+ throw _iteratorError;
80
+ }
81
+ }
82
+ }
83
+ return true;
84
+ }
34
85
  function getAppInstance(options, appInfo, manifest) {
35
86
  var componentSetterRegistry = {
36
87
  current: null
@@ -39,6 +90,9 @@ function getAppInstance(options, appInfo, manifest) {
39
90
  var _context_router, _context_router1, _context_router2, _context_router3, _context_router4;
40
91
  var appRef = useRef(null);
41
92
  var locationHrefRef = useRef("");
93
+ var propsRef = useRef(props);
94
+ var previousPropsRef = useRef(props);
95
+ var propsUpdateCounterRef = useRef(0);
42
96
  var domId = generateSubAppContainerKey(appInfo);
43
97
  var _useState = _sliced_to_array(useState({
44
98
  component: null
@@ -107,12 +161,43 @@ or directly pass the "basename":
107
161
  }, [
108
162
  locationPathname
109
163
  ]);
164
+ useEffect(function() {
165
+ var prevPropsForCompare = _object_spread({}, previousPropsRef.current);
166
+ var currentPropsForCompare = _object_spread({}, props);
167
+ Object.keys(prevPropsForCompare).forEach(function(key2) {
168
+ if (typeof prevPropsForCompare[key2] === "function") {
169
+ delete prevPropsForCompare[key2];
170
+ }
171
+ });
172
+ Object.keys(currentPropsForCompare).forEach(function(key2) {
173
+ if (typeof currentPropsForCompare[key2] === "function") {
174
+ delete currentPropsForCompare[key2];
175
+ }
176
+ });
177
+ if (!deepEqualExcludeFunctions(prevPropsForCompare, currentPropsForCompare)) {
178
+ var _appRef_current;
179
+ previousPropsRef.current = props;
180
+ propsRef.current = props;
181
+ 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
+ }
190
+ }
191
+ }, [
192
+ props,
193
+ appInfo.name
194
+ ]);
110
195
  useEffect(function() {
111
196
  var renderApp = function renderApp2() {
112
197
  return _renderApp.apply(this, arguments);
113
198
  };
114
199
  componentSetterRegistry.current = setSubModuleComponent;
115
- var setLoadingState = props.setLoadingState, userProps = _object_without_properties(props, [
200
+ var _propsRef_current = propsRef.current, setLoadingState = _propsRef_current.setLoadingState, userProps = _object_without_properties(_propsRef_current, [
116
201
  "setLoadingState"
117
202
  ]);
118
203
  var loadAppOptions = _object_spread_props(_object_spread({
@@ -263,11 +348,15 @@ or directly pass the "basename":
263
348
  }
264
349
  }
265
350
  };
266
- }, []);
351
+ }, [
352
+ basename,
353
+ domId,
354
+ appInfo.name
355
+ ]);
267
356
  return /* @__PURE__ */ _jsx(_Fragment, {
268
357
  children: /* @__PURE__ */ _jsx("div", {
269
358
  id: domId,
270
- children: SubModuleComponent && /* @__PURE__ */ _jsx(SubModuleComponent, _object_spread({}, props))
359
+ children: SubModuleComponent && /* @__PURE__ */ _jsx(SubModuleComponent, _object_spread({}, propsRef.current), "".concat(appInfo.name, "-").concat(propsUpdateCounterRef.current))
271
360
  })
272
361
  });
273
362
  }
@@ -21,6 +21,35 @@ function pathJoin(...args) {
21
21
  }, "");
22
22
  return res || "/";
23
23
  }
24
+ function deepEqualExcludeFunctions(prev, next) {
25
+ if (prev === next)
26
+ return true;
27
+ if (!prev || !next)
28
+ return false;
29
+ if (typeof prev !== "object" || typeof next !== "object")
30
+ return false;
31
+ const prevKeys = Object.keys(prev).filter((key) => typeof prev[key] !== "function");
32
+ const nextKeys = Object.keys(next).filter((key) => typeof next[key] !== "function");
33
+ if (prevKeys.length !== nextKeys.length)
34
+ return false;
35
+ for (const key of prevKeys) {
36
+ if (!nextKeys.includes(key))
37
+ return false;
38
+ const prevVal = prev[key];
39
+ const nextVal = next[key];
40
+ if (typeof prevVal === "function" || typeof nextVal === "function") {
41
+ continue;
42
+ }
43
+ if (typeof prevVal === "object" && typeof nextVal === "object") {
44
+ if (!deepEqualExcludeFunctions(prevVal, nextVal)) {
45
+ return false;
46
+ }
47
+ } else if (prevVal !== nextVal) {
48
+ return false;
49
+ }
50
+ }
51
+ return true;
52
+ }
24
53
  function getAppInstance(options, appInfo, manifest) {
25
54
  const componentSetterRegistry = {
26
55
  current: null
@@ -29,6 +58,9 @@ function getAppInstance(options, appInfo, manifest) {
29
58
  var _context_router, _context_router1, _context_router2, _context_router3, _context_router4;
30
59
  const appRef = useRef(null);
31
60
  const locationHrefRef = useRef("");
61
+ const propsRef = useRef(props);
62
+ const previousPropsRef = useRef(props);
63
+ const propsUpdateCounterRef = useRef(0);
32
64
  const domId = generateSubAppContainerKey(appInfo);
33
65
  const [{ component: SubModuleComponent }, setSubModuleComponent] = useState({
34
66
  component: null
@@ -99,9 +131,44 @@ or directly pass the "basename":
99
131
  }, [
100
132
  locationPathname
101
133
  ]);
134
+ useEffect(() => {
135
+ const prevPropsForCompare = {
136
+ ...previousPropsRef.current
137
+ };
138
+ const currentPropsForCompare = {
139
+ ...props
140
+ };
141
+ Object.keys(prevPropsForCompare).forEach((key) => {
142
+ if (typeof prevPropsForCompare[key] === "function") {
143
+ delete prevPropsForCompare[key];
144
+ }
145
+ });
146
+ Object.keys(currentPropsForCompare).forEach((key) => {
147
+ if (typeof currentPropsForCompare[key] === "function") {
148
+ delete currentPropsForCompare[key];
149
+ }
150
+ });
151
+ if (!deepEqualExcludeFunctions(prevPropsForCompare, currentPropsForCompare)) {
152
+ var _appRef_current;
153
+ previousPropsRef.current = props;
154
+ propsRef.current = props;
155
+ 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
+ }
164
+ }
165
+ }, [
166
+ props,
167
+ appInfo.name
168
+ ]);
102
169
  useEffect(() => {
103
170
  componentSetterRegistry.current = setSubModuleComponent;
104
- const { setLoadingState, ...userProps } = props;
171
+ const { setLoadingState, ...userProps } = propsRef.current;
105
172
  const loadAppOptions = {
106
173
  cache: true,
107
174
  insulationVariable: [
@@ -198,13 +265,17 @@ or directly pass the "basename":
198
265
  }
199
266
  }
200
267
  };
201
- }, []);
268
+ }, [
269
+ basename,
270
+ domId,
271
+ appInfo.name
272
+ ]);
202
273
  return /* @__PURE__ */ _jsx(_Fragment, {
203
274
  children: /* @__PURE__ */ _jsx("div", {
204
275
  id: domId,
205
276
  children: SubModuleComponent && /* @__PURE__ */ _jsx(SubModuleComponent, {
206
- ...props
207
- })
277
+ ...propsRef.current
278
+ }, `${appInfo.name}-${propsUpdateCounterRef.current}`)
208
279
  })
209
280
  });
210
281
  }
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.68.18",
18
+ "version": "2.68.19-alpha.0",
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/plugin-v2": "2.68.18",
73
72
  "@modern-js/runtime-utils": "2.68.18",
73
+ "@modern-js/plugin-v2": "2.68.18",
74
74
  "@modern-js/utils": "2.68.18"
75
75
  },
76
76
  "peerDependencies": {
@@ -94,12 +94,12 @@
94
94
  "react-router-dom": "6.27.0",
95
95
  "typescript": "^5",
96
96
  "@modern-js/app-tools": "2.68.18",
97
+ "@scripts/build": "2.66.0",
97
98
  "@modern-js/core": "2.68.18",
98
99
  "@modern-js/plugin-router-v5": "2.68.18",
99
100
  "@modern-js/runtime": "2.68.18",
100
- "@scripts/build": "2.66.0",
101
- "@modern-js/types": "2.68.18",
102
- "@scripts/jest-config": "2.66.0"
101
+ "@scripts/jest-config": "2.66.0",
102
+ "@modern-js/types": "2.68.18"
103
103
  },
104
104
  "sideEffects": false,
105
105
  "publishConfig": {