@modern-js/plugin-garfish 2.68.19-alpha.3 → 2.68.19-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.
@@ -55,13 +55,19 @@ function pathJoin(...args) {
55
55
  }, "");
56
56
  return res || "/";
57
57
  }
58
- function deepEqualExcludeFunctions(prev, next) {
58
+ function deepEqualExcludeFunctions(prev, next, visited) {
59
59
  if (prev === next)
60
60
  return true;
61
61
  if (!prev || !next)
62
62
  return false;
63
63
  if (typeof prev !== "object" || typeof next !== "object")
64
64
  return false;
65
+ const visitedSet = visited !== null && visited !== void 0 ? visited : /* @__PURE__ */ new WeakSet();
66
+ if (visitedSet.has(prev) || visitedSet.has(next)) {
67
+ return true;
68
+ }
69
+ visitedSet.add(prev);
70
+ visitedSet.add(next);
65
71
  const prevKeys = Object.keys(prev).filter((key) => typeof prev[key] !== "function");
66
72
  const nextKeys = Object.keys(next).filter((key) => typeof next[key] !== "function");
67
73
  if (prevKeys.length !== nextKeys.length)
@@ -75,7 +81,7 @@ function deepEqualExcludeFunctions(prev, next) {
75
81
  continue;
76
82
  }
77
83
  if (typeof prevVal === "object" && typeof nextVal === "object") {
78
- if (!deepEqualExcludeFunctions(prevVal, nextVal)) {
84
+ if (!deepEqualExcludeFunctions(prevVal, nextVal, visitedSet)) {
79
85
  return false;
80
86
  }
81
87
  } else if (prevVal !== nextVal) {
@@ -113,6 +119,8 @@ function getAppInstance(options, appInfo, manifest) {
113
119
  const useHistory = (_props_useHistory = props.useHistory) !== null && _props_useHistory !== void 0 ? _props_useHistory : context === null || context === void 0 ? void 0 : (_context_router3 = context.router) === null || _context_router3 === void 0 ? void 0 : _context_router3.useHistory;
114
120
  var _props_useHistory1;
115
121
  const useHref = (_props_useHistory1 = props.useHistory) !== null && _props_useHistory1 !== void 0 ? _props_useHistory1 : context === null || context === void 0 ? void 0 : (_context_router4 = context.router) === null || _context_router4 === void 0 ? void 0 : _context_router4.useHref;
122
+ const lastPropsUpdateKeyRef = (0, import_react.useRef)(0);
123
+ const isRemountingRef = (0, import_react.useRef)(false);
116
124
  const match = useRouteMatch === null || useRouteMatch === void 0 ? void 0 : useRouteMatch();
117
125
  const matchs = useMatches === null || useMatches === void 0 ? void 0 : useMatches();
118
126
  if (!useLocation) {
@@ -169,12 +177,24 @@ or directly pass the "basename":
169
177
  locationPathname
170
178
  ]);
171
179
  (0, import_react.useEffect)(() => {
180
+ if (previousPropsRef.current === props) {
181
+ return;
182
+ }
172
183
  const prevPropsForCompare = {
173
184
  ...previousPropsRef.current
174
185
  };
175
186
  const currentPropsForCompare = {
176
187
  ...props
177
188
  };
189
+ const ignoredKeysForRemount = [
190
+ "style",
191
+ "location",
192
+ "match",
193
+ "history",
194
+ "staticContext",
195
+ "guideState",
196
+ "guideConfig"
197
+ ];
178
198
  Object.keys(prevPropsForCompare).forEach((key) => {
179
199
  if (typeof prevPropsForCompare[key] === "function") {
180
200
  delete prevPropsForCompare[key];
@@ -185,11 +205,27 @@ or directly pass the "basename":
185
205
  delete currentPropsForCompare[key];
186
206
  }
187
207
  });
188
- if (!deepEqualExcludeFunctions(prevPropsForCompare, currentPropsForCompare)) {
208
+ const prevPropsForDeepCompare = {};
209
+ const currentPropsForDeepCompare = {};
210
+ Object.keys(prevPropsForCompare).forEach((key) => {
211
+ if (!ignoredKeysForRemount.includes(key)) {
212
+ prevPropsForDeepCompare[key] = prevPropsForCompare[key];
213
+ }
214
+ });
215
+ Object.keys(currentPropsForCompare).forEach((key) => {
216
+ if (!ignoredKeysForRemount.includes(key)) {
217
+ currentPropsForDeepCompare[key] = currentPropsForCompare[key];
218
+ }
219
+ });
220
+ const propsEqual = deepEqualExcludeFunctions(prevPropsForDeepCompare, currentPropsForDeepCompare);
221
+ if (!propsEqual) {
189
222
  previousPropsRef.current = props;
190
223
  propsRef.current = props;
191
224
  propsUpdateCounterRef.current += 1;
192
225
  setPropsUpdateKey((prev) => prev + 1);
226
+ } else {
227
+ previousPropsRef.current = props;
228
+ propsRef.current = props;
193
229
  }
194
230
  }, [
195
231
  props,
@@ -320,6 +356,10 @@ or directly pass the "basename":
320
356
  (0, import_react.useEffect)(() => {
321
357
  var _appRef_current;
322
358
  const componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
359
+ if (propsUpdateKey === lastPropsUpdateKeyRef.current || isRemountingRef.current) {
360
+ return;
361
+ }
362
+ lastPropsUpdateKeyRef.current = propsUpdateKey;
323
363
  if (componetRenderMode && ((_appRef_current = appRef.current) === null || _appRef_current === void 0 ? void 0 : _appRef_current.mounted)) {
324
364
  const componentToUse = SubModuleComponent || componentRef.current;
325
365
  if (componentToUse) {
@@ -343,6 +383,9 @@ or directly pass the "basename":
343
383
  setTimeout(() => {
344
384
  var _appRef_current3;
345
385
  (_appRef_current3 = appRef.current) === null || _appRef_current3 === void 0 ? void 0 : _appRef_current3.show();
386
+ setTimeout(() => {
387
+ isRemountingRef.current = false;
388
+ }, 100);
346
389
  }, 10);
347
390
  }
348
391
  }
@@ -32,13 +32,19 @@ function pathJoin() {
32
32
  }, "");
33
33
  return res || "/";
34
34
  }
35
- function deepEqualExcludeFunctions(prev, next) {
35
+ function deepEqualExcludeFunctions(prev, next, visited) {
36
36
  if (prev === next)
37
37
  return true;
38
38
  if (!prev || !next)
39
39
  return false;
40
40
  if ((typeof prev === "undefined" ? "undefined" : _type_of(prev)) !== "object" || (typeof next === "undefined" ? "undefined" : _type_of(next)) !== "object")
41
41
  return false;
42
+ var visitedSet = visited !== null && visited !== void 0 ? visited : /* @__PURE__ */ new WeakSet();
43
+ if (visitedSet.has(prev) || visitedSet.has(next)) {
44
+ return true;
45
+ }
46
+ visitedSet.add(prev);
47
+ visitedSet.add(next);
42
48
  var prevKeys = Object.keys(prev).filter(function(key2) {
43
49
  return typeof prev[key2] !== "function";
44
50
  });
@@ -59,7 +65,7 @@ function deepEqualExcludeFunctions(prev, next) {
59
65
  continue;
60
66
  }
61
67
  if ((typeof prevVal === "undefined" ? "undefined" : _type_of(prevVal)) === "object" && (typeof nextVal === "undefined" ? "undefined" : _type_of(nextVal)) === "object") {
62
- if (!deepEqualExcludeFunctions(prevVal, nextVal)) {
68
+ if (!deepEqualExcludeFunctions(prevVal, nextVal, visitedSet)) {
63
69
  return false;
64
70
  }
65
71
  } else if (prevVal !== nextVal) {
@@ -111,6 +117,8 @@ function getAppInstance(options, appInfo, manifest) {
111
117
  var useHistory = (_props_useHistory = props.useHistory) !== null && _props_useHistory !== void 0 ? _props_useHistory : context === null || context === void 0 ? void 0 : (_context_router3 = context.router) === null || _context_router3 === void 0 ? void 0 : _context_router3.useHistory;
112
118
  var _props_useHistory1;
113
119
  var useHref = (_props_useHistory1 = props.useHistory) !== null && _props_useHistory1 !== void 0 ? _props_useHistory1 : context === null || context === void 0 ? void 0 : (_context_router4 = context.router) === null || _context_router4 === void 0 ? void 0 : _context_router4.useHref;
120
+ var lastPropsUpdateKeyRef = useRef(0);
121
+ var isRemountingRef = useRef(false);
114
122
  var match = useRouteMatch === null || useRouteMatch === void 0 ? void 0 : useRouteMatch();
115
123
  var matchs = useMatches === null || useMatches === void 0 ? void 0 : useMatches();
116
124
  if (!useLocation) {
@@ -165,8 +173,20 @@ or directly pass the "basename":
165
173
  locationPathname
166
174
  ]);
167
175
  useEffect(function() {
176
+ if (previousPropsRef.current === props) {
177
+ return;
178
+ }
168
179
  var prevPropsForCompare = _object_spread({}, previousPropsRef.current);
169
180
  var currentPropsForCompare = _object_spread({}, props);
181
+ var ignoredKeysForRemount = [
182
+ "style",
183
+ "location",
184
+ "match",
185
+ "history",
186
+ "staticContext",
187
+ "guideState",
188
+ "guideConfig"
189
+ ];
170
190
  Object.keys(prevPropsForCompare).forEach(function(key2) {
171
191
  if (typeof prevPropsForCompare[key2] === "function") {
172
192
  delete prevPropsForCompare[key2];
@@ -177,13 +197,29 @@ or directly pass the "basename":
177
197
  delete currentPropsForCompare[key2];
178
198
  }
179
199
  });
180
- if (!deepEqualExcludeFunctions(prevPropsForCompare, currentPropsForCompare)) {
200
+ var prevPropsForDeepCompare = {};
201
+ var currentPropsForDeepCompare = {};
202
+ Object.keys(prevPropsForCompare).forEach(function(key2) {
203
+ if (!ignoredKeysForRemount.includes(key2)) {
204
+ prevPropsForDeepCompare[key2] = prevPropsForCompare[key2];
205
+ }
206
+ });
207
+ Object.keys(currentPropsForCompare).forEach(function(key2) {
208
+ if (!ignoredKeysForRemount.includes(key2)) {
209
+ currentPropsForDeepCompare[key2] = currentPropsForCompare[key2];
210
+ }
211
+ });
212
+ var propsEqual = deepEqualExcludeFunctions(prevPropsForDeepCompare, currentPropsForDeepCompare);
213
+ if (!propsEqual) {
181
214
  previousPropsRef.current = props;
182
215
  propsRef.current = props;
183
216
  propsUpdateCounterRef.current += 1;
184
217
  setPropsUpdateKey(function(prev) {
185
218
  return prev + 1;
186
219
  });
220
+ } else {
221
+ previousPropsRef.current = props;
222
+ propsRef.current = props;
187
223
  }
188
224
  }, [
189
225
  props,
@@ -371,6 +407,10 @@ or directly pass the "basename":
371
407
  useEffect(function() {
372
408
  var _appRef_current;
373
409
  var componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
410
+ if (propsUpdateKey === lastPropsUpdateKeyRef.current || isRemountingRef.current) {
411
+ return;
412
+ }
413
+ lastPropsUpdateKeyRef.current = propsUpdateKey;
374
414
  if (componetRenderMode && ((_appRef_current = appRef.current) === null || _appRef_current === void 0 ? void 0 : _appRef_current.mounted)) {
375
415
  var componentToUse = SubModuleComponent || componentRef.current;
376
416
  if (componentToUse) {
@@ -394,6 +434,9 @@ or directly pass the "basename":
394
434
  setTimeout(function() {
395
435
  var _appRef_current3;
396
436
  (_appRef_current3 = appRef.current) === null || _appRef_current3 === void 0 ? void 0 : _appRef_current3.show();
437
+ setTimeout(function() {
438
+ isRemountingRef.current = false;
439
+ }, 100);
397
440
  }, 10);
398
441
  }
399
442
  }
@@ -21,13 +21,19 @@ function pathJoin(...args) {
21
21
  }, "");
22
22
  return res || "/";
23
23
  }
24
- function deepEqualExcludeFunctions(prev, next) {
24
+ function deepEqualExcludeFunctions(prev, next, visited) {
25
25
  if (prev === next)
26
26
  return true;
27
27
  if (!prev || !next)
28
28
  return false;
29
29
  if (typeof prev !== "object" || typeof next !== "object")
30
30
  return false;
31
+ const visitedSet = visited !== null && visited !== void 0 ? visited : /* @__PURE__ */ new WeakSet();
32
+ if (visitedSet.has(prev) || visitedSet.has(next)) {
33
+ return true;
34
+ }
35
+ visitedSet.add(prev);
36
+ visitedSet.add(next);
31
37
  const prevKeys = Object.keys(prev).filter((key) => typeof prev[key] !== "function");
32
38
  const nextKeys = Object.keys(next).filter((key) => typeof next[key] !== "function");
33
39
  if (prevKeys.length !== nextKeys.length)
@@ -41,7 +47,7 @@ function deepEqualExcludeFunctions(prev, next) {
41
47
  continue;
42
48
  }
43
49
  if (typeof prevVal === "object" && typeof nextVal === "object") {
44
- if (!deepEqualExcludeFunctions(prevVal, nextVal)) {
50
+ if (!deepEqualExcludeFunctions(prevVal, nextVal, visitedSet)) {
45
51
  return false;
46
52
  }
47
53
  } else if (prevVal !== nextVal) {
@@ -79,6 +85,8 @@ function getAppInstance(options, appInfo, manifest) {
79
85
  const useHistory = (_props_useHistory = props.useHistory) !== null && _props_useHistory !== void 0 ? _props_useHistory : context === null || context === void 0 ? void 0 : (_context_router3 = context.router) === null || _context_router3 === void 0 ? void 0 : _context_router3.useHistory;
80
86
  var _props_useHistory1;
81
87
  const useHref = (_props_useHistory1 = props.useHistory) !== null && _props_useHistory1 !== void 0 ? _props_useHistory1 : context === null || context === void 0 ? void 0 : (_context_router4 = context.router) === null || _context_router4 === void 0 ? void 0 : _context_router4.useHref;
88
+ const lastPropsUpdateKeyRef = useRef(0);
89
+ const isRemountingRef = useRef(false);
82
90
  const match = useRouteMatch === null || useRouteMatch === void 0 ? void 0 : useRouteMatch();
83
91
  const matchs = useMatches === null || useMatches === void 0 ? void 0 : useMatches();
84
92
  if (!useLocation) {
@@ -135,12 +143,24 @@ or directly pass the "basename":
135
143
  locationPathname
136
144
  ]);
137
145
  useEffect(() => {
146
+ if (previousPropsRef.current === props) {
147
+ return;
148
+ }
138
149
  const prevPropsForCompare = {
139
150
  ...previousPropsRef.current
140
151
  };
141
152
  const currentPropsForCompare = {
142
153
  ...props
143
154
  };
155
+ const ignoredKeysForRemount = [
156
+ "style",
157
+ "location",
158
+ "match",
159
+ "history",
160
+ "staticContext",
161
+ "guideState",
162
+ "guideConfig"
163
+ ];
144
164
  Object.keys(prevPropsForCompare).forEach((key) => {
145
165
  if (typeof prevPropsForCompare[key] === "function") {
146
166
  delete prevPropsForCompare[key];
@@ -151,11 +171,27 @@ or directly pass the "basename":
151
171
  delete currentPropsForCompare[key];
152
172
  }
153
173
  });
154
- if (!deepEqualExcludeFunctions(prevPropsForCompare, currentPropsForCompare)) {
174
+ const prevPropsForDeepCompare = {};
175
+ const currentPropsForDeepCompare = {};
176
+ Object.keys(prevPropsForCompare).forEach((key) => {
177
+ if (!ignoredKeysForRemount.includes(key)) {
178
+ prevPropsForDeepCompare[key] = prevPropsForCompare[key];
179
+ }
180
+ });
181
+ Object.keys(currentPropsForCompare).forEach((key) => {
182
+ if (!ignoredKeysForRemount.includes(key)) {
183
+ currentPropsForDeepCompare[key] = currentPropsForCompare[key];
184
+ }
185
+ });
186
+ const propsEqual = deepEqualExcludeFunctions(prevPropsForDeepCompare, currentPropsForDeepCompare);
187
+ if (!propsEqual) {
155
188
  previousPropsRef.current = props;
156
189
  propsRef.current = props;
157
190
  propsUpdateCounterRef.current += 1;
158
191
  setPropsUpdateKey((prev) => prev + 1);
192
+ } else {
193
+ previousPropsRef.current = props;
194
+ propsRef.current = props;
159
195
  }
160
196
  }, [
161
197
  props,
@@ -286,6 +322,10 @@ or directly pass the "basename":
286
322
  useEffect(() => {
287
323
  var _appRef_current;
288
324
  const componetRenderMode = manifest === null || manifest === void 0 ? void 0 : manifest.componentRender;
325
+ if (propsUpdateKey === lastPropsUpdateKeyRef.current || isRemountingRef.current) {
326
+ return;
327
+ }
328
+ lastPropsUpdateKeyRef.current = propsUpdateKey;
289
329
  if (componetRenderMode && ((_appRef_current = appRef.current) === null || _appRef_current === void 0 ? void 0 : _appRef_current.mounted)) {
290
330
  const componentToUse = SubModuleComponent || componentRef.current;
291
331
  if (componentToUse) {
@@ -309,6 +349,9 @@ or directly pass the "basename":
309
349
  setTimeout(() => {
310
350
  var _appRef_current3;
311
351
  (_appRef_current3 = appRef.current) === null || _appRef_current3 === void 0 ? void 0 : _appRef_current3.show();
352
+ setTimeout(() => {
353
+ isRemountingRef.current = false;
354
+ }, 100);
312
355
  }, 10);
313
356
  }
314
357
  }
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.68.19-alpha.3",
18
+ "version": "2.68.19-alpha.4",
19
19
  "jsnext:source": "./src/cli/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "typesVersions": {
@@ -70,8 +70,8 @@
70
70
  "garfish": "^1.8.1",
71
71
  "react-loadable": "^5.5.0",
72
72
  "@modern-js/plugin-v2": "2.68.18",
73
- "@modern-js/utils": "2.68.18",
74
- "@modern-js/runtime-utils": "2.68.18"
73
+ "@modern-js/runtime-utils": "2.68.18",
74
+ "@modern-js/utils": "2.68.18"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "@modern-js/runtime": "^2.68.18",
@@ -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.18",
97
96
  "@scripts/build": "2.66.0",
97
+ "@modern-js/app-tools": "2.68.18",
98
+ "@modern-js/core": "2.68.18",
99
+ "@modern-js/types": "2.68.18",
98
100
  "@modern-js/runtime": "2.68.18",
99
101
  "@modern-js/plugin-router-v5": "2.68.18",
100
- "@modern-js/types": "2.68.18",
101
- "@scripts/jest-config": "2.66.0",
102
- "@modern-js/core": "2.68.18"
102
+ "@scripts/jest-config": "2.66.0"
103
103
  },
104
104
  "sideEffects": false,
105
105
  "publishConfig": {