@lynx-js/react 0.110.1 → 0.111.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.
Files changed (89) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/components/lib/DeferredListItem.d.ts +7 -0
  3. package/components/lib/DeferredListItem.jsx +40 -0
  4. package/components/lib/DeferredListItem.jsx.map +1 -0
  5. package/components/lib/index.d.ts +1 -0
  6. package/components/lib/index.js +1 -0
  7. package/components/lib/index.js.map +1 -1
  8. package/components/src/DeferredListItem.tsx +56 -0
  9. package/components/src/index.ts +1 -0
  10. package/package.json +1 -1
  11. package/refresh/.turbo/turbo-build.log +7 -3
  12. package/refresh/dist/index.js +223 -284
  13. package/refresh/package.json +3 -4
  14. package/refresh/rslib.config.ts +24 -0
  15. package/runtime/lazy/react-lepus.js +1 -0
  16. package/runtime/lazy/react.js +1 -0
  17. package/runtime/lepus/index.d.ts +1 -1
  18. package/runtime/lepus/index.js +44 -0
  19. package/runtime/lib/backgroundSnapshot.d.ts +2 -1
  20. package/runtime/lib/backgroundSnapshot.js +62 -40
  21. package/runtime/lib/backgroundSnapshot.js.map +1 -1
  22. package/runtime/lib/compat/initData.js +10 -0
  23. package/runtime/lib/compat/initData.js.map +1 -1
  24. package/runtime/lib/index.d.ts +2 -2
  25. package/runtime/lib/index.js +2 -2
  26. package/runtime/lib/index.js.map +1 -1
  27. package/runtime/lib/lifecycle/patch/commit.js +5 -5
  28. package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
  29. package/runtime/lib/lifecycle/patch/snapshotPatch.d.ts +9 -9
  30. package/runtime/lib/lifecycle/patch/snapshotPatch.js +9 -10
  31. package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -1
  32. package/runtime/lib/lifecycle/patch/updateMainThread.js +7 -8
  33. package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
  34. package/runtime/lib/lifecycleConstant.d.ts +2 -1
  35. package/runtime/lib/lifecycleConstant.js +1 -0
  36. package/runtime/lib/lifecycleConstant.js.map +1 -1
  37. package/runtime/lib/list.js +102 -12
  38. package/runtime/lib/list.js.map +1 -1
  39. package/runtime/lib/lynx/calledByNative.js +6 -9
  40. package/runtime/lib/lynx/calledByNative.js.map +1 -1
  41. package/runtime/lib/lynx/component.js +11 -14
  42. package/runtime/lib/lynx/component.js.map +1 -1
  43. package/runtime/lib/lynx/env.js +1 -2
  44. package/runtime/lib/lynx/env.js.map +1 -1
  45. package/runtime/lib/lynx/lazy-bundle.js +48 -21
  46. package/runtime/lib/lynx/lazy-bundle.js.map +1 -1
  47. package/runtime/lib/lynx/performance.d.ts +3 -19
  48. package/runtime/lib/lynx/performance.js +25 -26
  49. package/runtime/lib/lynx/performance.js.map +1 -1
  50. package/runtime/lib/lynx/tt.js +10 -5
  51. package/runtime/lib/lynx/tt.js.map +1 -1
  52. package/runtime/lib/lynx-api.d.ts +78 -1
  53. package/runtime/lib/lynx-api.js.map +1 -1
  54. package/runtime/lib/snapshot.d.ts +2 -0
  55. package/runtime/lib/snapshot.js +19 -5
  56. package/runtime/lib/snapshot.js.map +1 -1
  57. package/runtime/lib/utils.d.ts +1 -0
  58. package/runtime/lib/utils.js +6 -0
  59. package/runtime/lib/utils.js.map +1 -1
  60. package/runtime/src/backgroundSnapshot.ts +74 -55
  61. package/runtime/src/compat/initData.ts +10 -0
  62. package/runtime/src/index.ts +2 -0
  63. package/runtime/src/lifecycle/patch/commit.ts +5 -11
  64. package/runtime/src/lifecycle/patch/snapshotPatch.ts +9 -9
  65. package/runtime/src/lifecycle/patch/updateMainThread.ts +7 -8
  66. package/runtime/src/lifecycleConstant.ts +1 -0
  67. package/runtime/src/list.ts +118 -15
  68. package/runtime/src/lynx/calledByNative.ts +6 -8
  69. package/runtime/src/lynx/component.ts +17 -29
  70. package/runtime/src/lynx/env.ts +1 -2
  71. package/runtime/src/lynx/lazy-bundle.ts +55 -20
  72. package/runtime/src/lynx/performance.ts +26 -27
  73. package/runtime/src/lynx/tt.ts +10 -11
  74. package/runtime/src/lynx-api.ts +77 -1
  75. package/runtime/src/snapshot.ts +20 -5
  76. package/runtime/src/utils.ts +9 -0
  77. package/testing-library/dist/env/vitest.js +6 -3
  78. package/testing-library/dist/index.d.ts +4 -1
  79. package/testing-library/dist/pure.js +4 -2
  80. package/testing-library/dist/vitest-global-setup.js +2 -2
  81. package/testing-library/dist/vitest.config.js +38 -1
  82. package/testing-library/types/entry.d.ts +3 -2
  83. package/transform/dist/wasm.cjs +1 -1
  84. package/types/react.d.ts +21 -1
  85. package/types/react.docs.d.ts +1 -1
  86. package/worklet-runtime/dist/dev.js +403 -506
  87. package/worklet-runtime/dist/main.js +1 -517
  88. package/worklet-runtime/lib/workletRuntime.js +5 -5
  89. package/worklet-runtime/lib/workletRuntime.js.map +1 -1
@@ -1,311 +1,250 @@
1
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/runtime/catchError.js
2
- import { options } from "@lynx-js/react/internal";
3
-
4
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/constants.js
5
- var VNODE_COMPONENT = "__c";
6
- var NAMESPACE = "__PREFRESH__";
7
- var COMPONENT_HOOKS = "__H";
8
- var HOOKS_LIST = "__";
9
- var EFFECTS_LIST = "__h";
10
- var RERENDER_COUNT = "__r";
11
- var CATCH_ERROR_OPTION = "__e";
12
- var COMPONENT_DIRTY = "__d";
13
- var HOOK_VALUE = "__";
14
- var HOOK_ARGS = "__H";
15
- var HOOK_CLEANUP = "__c";
16
-
17
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/runtime/catchError.js
18
- var oldCatchError = options[CATCH_ERROR_OPTION];
19
- options[CATCH_ERROR_OPTION] = (error, vnode, oldVNode) => {
20
- if (vnode[VNODE_COMPONENT] && vnode[VNODE_COMPONENT][COMPONENT_DIRTY]) {
21
- vnode[VNODE_COMPONENT][COMPONENT_DIRTY] = false;
22
- }
23
- if (oldCatchError) oldCatchError(error, vnode, oldVNode);
1
+ import { Component, options } from "@lynx-js/react/internal";
2
+ const VNODE_COMPONENT = '__c';
3
+ const NAMESPACE = '__PREFRESH__';
4
+ const COMPONENT_HOOKS = '__H';
5
+ const HOOKS_LIST = '__';
6
+ const EFFECTS_LIST = '__h';
7
+ const RERENDER_COUNT = '__r';
8
+ const CATCH_ERROR_OPTION = '__e';
9
+ const COMPONENT_DIRTY = '__d';
10
+ const HOOK_VALUE = '__';
11
+ const HOOK_ARGS = '__H';
12
+ const HOOK_CLEANUP = '__c';
13
+ const oldCatchError = options[CATCH_ERROR_OPTION];
14
+ options[CATCH_ERROR_OPTION] = (error, vnode, oldVNode)=>{
15
+ if (vnode[VNODE_COMPONENT] && vnode[VNODE_COMPONENT][COMPONENT_DIRTY]) vnode[VNODE_COMPONENT][COMPONENT_DIRTY] = false;
16
+ if (oldCatchError) oldCatchError(error, vnode, oldVNode);
24
17
  };
25
-
26
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/runtime/debounceRendering.js
27
- import { options as options2 } from "@lynx-js/react/internal";
28
- var defer = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout;
29
- options2.debounceRendering = (process) => {
30
- defer(() => {
31
- try {
32
- process();
33
- } catch (e) {
34
- process[RERENDER_COUNT] = 0;
35
- throw e;
36
- }
37
- });
38
- };
39
-
40
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/runtime/vnode.js
41
- import { options as options3 } from "@lynx-js/react/internal";
42
-
43
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/runtime/vnodesForComponent.js
44
- var vnodesForComponent = /* @__PURE__ */ new WeakMap();
45
- var mappedVNodes = /* @__PURE__ */ new WeakMap();
46
-
47
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/runtime/vnode.js
48
- var getMappedVnode = (type) => {
49
- if (mappedVNodes.has(type)) {
50
- return getMappedVnode(mappedVNodes.get(type));
51
- }
52
- return type;
18
+ const defer = 'function' == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout;
19
+ options.debounceRendering = (process)=>{
20
+ defer(()=>{
21
+ try {
22
+ process();
23
+ } catch (e) {
24
+ process[RERENDER_COUNT] = 0;
25
+ throw e;
26
+ }
27
+ });
53
28
  };
54
- var BUILT_IN_COMPONENTS = ["Fragment", "Suspense", "SuspenseList"];
55
- var isBuiltIn = (type) => {
56
- return BUILT_IN_COMPONENTS.includes(type.name);
29
+ const vnodesForComponent = new WeakMap();
30
+ const mappedVNodes = new WeakMap();
31
+ const lastSeen = new Map();
32
+ const getMappedVnode = (type)=>{
33
+ if (mappedVNodes.has(type)) return getMappedVnode(mappedVNodes.get(type));
34
+ return type;
57
35
  };
58
- var oldVnode = options3.vnode;
59
- options3.vnode = (vnode) => {
60
- if (vnode && typeof vnode.type === "function" && !isBuiltIn(vnode.type)) {
61
- const vnodes = vnodesForComponent.get(vnode.type);
62
- if (!vnodes) {
63
- vnodesForComponent.set(vnode.type, [vnode]);
64
- } else {
65
- vnodes.push(vnode);
66
- }
67
- const foundType = getMappedVnode(vnode.type);
68
- if (foundType !== vnode.type) {
69
- const vnodes2 = vnodesForComponent.get(foundType);
70
- if (!vnodes2) {
71
- vnodesForComponent.set(foundType, [vnode]);
72
- } else {
73
- vnodes2.push(vnode);
74
- }
75
- }
76
- vnode.type = foundType;
77
- if (vnode[VNODE_COMPONENT] && "prototype" in vnode.type && vnode.type.prototype.render) {
78
- vnode[VNODE_COMPONENT].constructor = vnode.type;
36
+ const BUILT_IN_COMPONENTS = [
37
+ 'Fragment',
38
+ 'Suspense',
39
+ 'SuspenseList'
40
+ ];
41
+ const isBuiltIn = (type)=>BUILT_IN_COMPONENTS.includes(type.name);
42
+ const oldVnode = options.vnode;
43
+ options.vnode = (vnode)=>{
44
+ if (vnode && 'function' == typeof vnode.type && !isBuiltIn(vnode.type)) {
45
+ const vnodes = vnodesForComponent.get(vnode.type);
46
+ if (vnodes) vnodes.push(vnode);
47
+ else vnodesForComponent.set(vnode.type, [
48
+ vnode
49
+ ]);
50
+ const foundType = getMappedVnode(vnode.type);
51
+ if (foundType !== vnode.type) {
52
+ const vnodes = vnodesForComponent.get(foundType);
53
+ if (vnodes) vnodes.push(vnode);
54
+ else vnodesForComponent.set(foundType, [
55
+ vnode
56
+ ]);
57
+ }
58
+ vnode.type = foundType;
59
+ if (vnode[VNODE_COMPONENT] && 'prototype' in vnode.type && vnode.type.prototype.render) vnode[VNODE_COMPONENT].constructor = vnode.type;
79
60
  }
80
- }
81
- if (oldVnode) oldVnode(vnode);
61
+ if (oldVnode) oldVnode(vnode);
82
62
  };
83
- var oldDiffed = options3.diffed;
84
- options3.diffed = (vnode) => {
85
- if (vnode && typeof vnode.type === "function") {
86
- const vnodes = vnodesForComponent.get(vnode.type);
87
- if (vnodes) {
88
- const matchingDom = vnodes.filter((p) => p.__c === vnode.__c);
89
- if (matchingDom.length > 1) {
90
- const i = vnodes.findIndex((p) => p === matchingDom[0]);
91
- vnodes.splice(i, 1);
92
- }
63
+ const oldDiffed = options.diffed;
64
+ options.diffed = (vnode)=>{
65
+ if (vnode && 'function' == typeof vnode.type) {
66
+ const vnodes = vnodesForComponent.get(vnode.type);
67
+ lastSeen.set(vnode.__v, vnode);
68
+ if (vnodes) {
69
+ const matchingDom = vnodes.filter((p)=>p.__c === vnode.__c);
70
+ if (matchingDom.length > 1) {
71
+ const i = vnodes.findIndex((p)=>p === matchingDom[0]);
72
+ vnodes.splice(i, 1);
73
+ }
74
+ }
93
75
  }
94
- }
95
- if (oldDiffed) oldDiffed(vnode);
76
+ if (oldDiffed) oldDiffed(vnode);
96
77
  };
97
-
98
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/runtime/unmount.js
99
- import { options as options4 } from "@lynx-js/react/internal";
100
- var oldUnmount = options4.unmount;
101
- options4.unmount = (vnode) => {
102
- const type = (vnode || {}).type;
103
- if (typeof type === "function" && vnodesForComponent.has(type)) {
104
- const vnodes = vnodesForComponent.get(type);
105
- if (vnodes) {
106
- const index = vnodes.indexOf(vnode);
107
- if (index !== -1) {
108
- vnodes.splice(index, 1);
109
- }
78
+ const oldUnmount = options.unmount;
79
+ options.unmount = (vnode)=>{
80
+ const type = (vnode || {}).type;
81
+ if ('function' == typeof type && vnodesForComponent.has(type)) {
82
+ const vnodes = vnodesForComponent.get(type);
83
+ if (vnodes) {
84
+ const index = vnodes.indexOf(vnode);
85
+ if (-1 !== index) vnodes.splice(index, 1);
86
+ }
110
87
  }
111
- }
112
- if (oldUnmount) oldUnmount(vnode);
88
+ if (oldUnmount) oldUnmount(vnode);
113
89
  };
114
-
115
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/index.js
116
- import { Component } from "@lynx-js/react/internal";
117
-
118
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/runtime/signaturesForType.js
119
- var signaturesForType = /* @__PURE__ */ new WeakMap();
120
-
121
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/computeKey.js
122
- var computeKey = (signature) => {
123
- let fullKey = signature.key;
124
- let hooks;
125
- try {
126
- hooks = signature.getCustomHooks();
127
- } catch (err) {
128
- signature.forceReset = true;
129
- return fullKey;
130
- }
131
- for (let i = 0; i < hooks.length; i++) {
132
- const hook = hooks[i];
133
- if (typeof hook !== "function") {
134
- signature.forceReset = true;
135
- return fullKey;
90
+ const signaturesForType = new WeakMap();
91
+ const computeKey = (signature)=>{
92
+ let fullKey = signature.key;
93
+ let hooks;
94
+ try {
95
+ hooks = signature.getCustomHooks();
96
+ } catch (err) {
97
+ signature.forceReset = true;
98
+ return fullKey;
99
+ }
100
+ for(let i = 0; i < hooks.length; i++){
101
+ const hook = hooks[i];
102
+ if ('function' != typeof hook) {
103
+ signature.forceReset = true;
104
+ break;
105
+ }
106
+ const nestedHookSignature = signaturesForType.get(hook);
107
+ if (void 0 === nestedHookSignature) continue;
108
+ const nestedHookKey = computeKey(nestedHookSignature);
109
+ if (nestedHookSignature.forceReset) signature.forceReset = true;
110
+ fullKey += '\n---\n' + nestedHookKey;
136
111
  }
137
- const nestedHookSignature = signaturesForType.get(hook);
138
- if (nestedHookSignature === void 0) continue;
139
- const nestedHookKey = computeKey(nestedHookSignature);
140
- if (nestedHookSignature.forceReset) signature.forceReset = true;
141
- fullKey += "\n---\n" + nestedHookKey;
142
- }
143
- return fullKey;
112
+ return fullKey;
144
113
  };
145
-
146
- // ../../../node_modules/.pnpm/@prefresh+core@1.5.3_preact@10.23.2/node_modules/@prefresh/core/src/index.js
147
- var typesById = /* @__PURE__ */ new Map();
148
- var pendingUpdates = [];
114
+ let typesById = new Map();
115
+ let pendingUpdates = [];
149
116
  function sign(type, key, forceReset, getCustomHooks, status) {
150
- if (type) {
151
- let signature = signaturesForType.get(type);
152
- if (status === "begin") {
153
- signaturesForType.set(type, {
154
- type,
155
- key,
156
- forceReset,
157
- getCustomHooks: getCustomHooks || (() => [])
158
- });
159
- return "needsHooks";
160
- } else if (status === "needsHooks") {
161
- signature.fullKey = computeKey(signature);
117
+ if (type) {
118
+ let signature = signaturesForType.get(type);
119
+ if ('begin' === status) {
120
+ signaturesForType.set(type, {
121
+ type,
122
+ key,
123
+ forceReset,
124
+ getCustomHooks: getCustomHooks || (()=>[])
125
+ });
126
+ return 'needsHooks';
127
+ }
128
+ if ('needsHooks' === status) signature.fullKey = computeKey(signature);
162
129
  }
163
- }
164
130
  }
165
131
  function replaceComponent(OldType, NewType, resetHookState) {
166
- const vnodes = vnodesForComponent.get(OldType);
167
- if (!vnodes) return;
168
- vnodesForComponent.delete(OldType);
169
- vnodesForComponent.set(NewType, vnodes);
170
- mappedVNodes.set(OldType, NewType);
171
- pendingUpdates = pendingUpdates.filter((p) => p[0] !== OldType);
172
- vnodes.forEach((vnode) => {
173
- if (!vnode.__c || !vnode.__c.__P) return;
174
- vnode.type = NewType;
175
- if (vnode[VNODE_COMPONENT]) {
176
- vnode[VNODE_COMPONENT].constructor = vnode.type;
177
- try {
178
- if (vnode[VNODE_COMPONENT] instanceof OldType) {
179
- const oldInst = vnode[VNODE_COMPONENT];
180
- const newInst = new NewType(
181
- vnode[VNODE_COMPONENT].props,
182
- vnode[VNODE_COMPONENT].context
183
- );
184
- vnode[VNODE_COMPONENT] = newInst;
185
- for (let i in oldInst) {
186
- const type = typeof oldInst[i];
187
- if (!(i in newInst)) {
188
- newInst[i] = oldInst[i];
189
- } else if (type !== "function" && typeof newInst[i] === type) {
190
- if (type === "object" && newInst[i] != null && newInst[i].constructor === oldInst[i].constructor) {
191
- Object.assign(newInst[i], oldInst[i]);
192
- } else {
193
- newInst[i] = oldInst[i];
194
- }
195
- }
196
- }
132
+ const vnodes = vnodesForComponent.get(OldType);
133
+ if (!vnodes) return;
134
+ vnodesForComponent["delete"](OldType);
135
+ vnodesForComponent.set(NewType, vnodes);
136
+ mappedVNodes.set(OldType, NewType);
137
+ pendingUpdates = pendingUpdates.filter((p)=>p[0] !== OldType);
138
+ vnodes.forEach((node)=>{
139
+ let vnode = node;
140
+ if (!vnode.__c) {
141
+ vnode = lastSeen.get(vnode.__v, vnode);
142
+ lastSeen["delete"](vnode.__v);
197
143
  }
198
- } catch (e) {
199
- vnode[VNODE_COMPONENT].constructor = NewType;
200
- }
201
- if (resetHookState) {
202
- if (vnode[VNODE_COMPONENT][COMPONENT_HOOKS] && vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST] && vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST].length) {
203
- vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST].forEach(
204
- (possibleEffect) => {
205
- if (possibleEffect[HOOK_CLEANUP] && typeof possibleEffect[HOOK_CLEANUP] === "function") {
206
- possibleEffect[HOOK_CLEANUP]();
207
- possibleEffect[HOOK_CLEANUP] = void 0;
208
- } else if (possibleEffect[HOOK_ARGS] && possibleEffect[HOOK_VALUE] && Object.keys(possibleEffect).length === 3) {
209
- const cleanupKey = Object.keys(possibleEffect).find(
210
- (key) => key !== HOOK_ARGS && key !== HOOK_VALUE
211
- );
212
- if (cleanupKey && typeof possibleEffect[cleanupKey] == "function") {
213
- possibleEffect[cleanupKey]();
214
- possibleEffect[cleanupKey] = void 0;
144
+ if (!vnode || !vnode.__c || !vnode.__c.__P) return;
145
+ vnode.type = NewType;
146
+ if (vnode[VNODE_COMPONENT]) {
147
+ vnode[VNODE_COMPONENT].constructor = vnode.type;
148
+ try {
149
+ if (vnode[VNODE_COMPONENT] instanceof OldType) {
150
+ const oldInst = vnode[VNODE_COMPONENT];
151
+ const newInst = new NewType(vnode[VNODE_COMPONENT].props, vnode[VNODE_COMPONENT].context);
152
+ vnode[VNODE_COMPONENT] = newInst;
153
+ for(let i in oldInst){
154
+ const type = typeof oldInst[i];
155
+ if (i in newInst) {
156
+ if ('function' !== type && typeof newInst[i] === type) if ('object' === type && null != newInst[i] && newInst[i].constructor === oldInst[i].constructor) Object.assign(newInst[i], oldInst[i]);
157
+ else newInst[i] = oldInst[i];
158
+ } else newInst[i] = oldInst[i];
159
+ }
215
160
  }
216
- }
161
+ } catch (e) {
162
+ vnode[VNODE_COMPONENT].constructor = NewType;
217
163
  }
218
- );
219
- }
220
- vnode[VNODE_COMPONENT][COMPONENT_HOOKS] = {
221
- [HOOKS_LIST]: [],
222
- [EFFECTS_LIST]: []
223
- };
224
- } else if (vnode[VNODE_COMPONENT][COMPONENT_HOOKS] && vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST] && vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST].length) {
225
- vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST].forEach(
226
- (possibleEffect) => {
227
- if (possibleEffect[HOOK_CLEANUP] && typeof possibleEffect[HOOK_CLEANUP] === "function") {
228
- possibleEffect[HOOK_CLEANUP]();
229
- possibleEffect[HOOK_CLEANUP] = void 0;
230
- } else if (possibleEffect[HOOK_ARGS] && possibleEffect[HOOK_VALUE] && Object.keys(possibleEffect).length === 3) {
231
- const cleanupKey = Object.keys(possibleEffect).find(
232
- (key) => key !== HOOK_ARGS && key !== HOOK_VALUE
233
- );
234
- if (cleanupKey && typeof possibleEffect[cleanupKey] == "function")
235
- possibleEffect[cleanupKey]();
236
- possibleEffect[cleanupKey] = void 0;
164
+ if (resetHookState) {
165
+ if (vnode[VNODE_COMPONENT][COMPONENT_HOOKS] && vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST] && vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST].length) vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST].forEach((possibleEffect)=>{
166
+ if (possibleEffect[HOOK_CLEANUP] && 'function' == typeof possibleEffect[HOOK_CLEANUP]) {
167
+ possibleEffect[HOOK_CLEANUP]();
168
+ possibleEffect[HOOK_CLEANUP] = void 0;
169
+ } else if (possibleEffect[HOOK_ARGS] && possibleEffect[HOOK_VALUE] && 3 === Object.keys(possibleEffect).length) {
170
+ const cleanupKey = Object.keys(possibleEffect).find((key)=>key !== HOOK_ARGS && key !== HOOK_VALUE);
171
+ if (cleanupKey && 'function' == typeof possibleEffect[cleanupKey]) {
172
+ possibleEffect[cleanupKey]();
173
+ possibleEffect[cleanupKey] = void 0;
174
+ }
175
+ }
176
+ });
177
+ vnode[VNODE_COMPONENT][COMPONENT_HOOKS] = {
178
+ [HOOKS_LIST]: [],
179
+ [EFFECTS_LIST]: []
180
+ };
181
+ } else if (vnode[VNODE_COMPONENT][COMPONENT_HOOKS] && vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST] && vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST].length) {
182
+ vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST].forEach((possibleEffect)=>{
183
+ if (possibleEffect[HOOK_CLEANUP] && 'function' == typeof possibleEffect[HOOK_CLEANUP]) {
184
+ possibleEffect[HOOK_CLEANUP]();
185
+ possibleEffect[HOOK_CLEANUP] = void 0;
186
+ } else if (possibleEffect[HOOK_ARGS] && possibleEffect[HOOK_VALUE] && 3 === Object.keys(possibleEffect).length) {
187
+ const cleanupKey = Object.keys(possibleEffect).find((key)=>key !== HOOK_ARGS && key !== HOOK_VALUE);
188
+ if (cleanupKey && 'function' == typeof possibleEffect[cleanupKey]) possibleEffect[cleanupKey]();
189
+ possibleEffect[cleanupKey] = void 0;
190
+ }
191
+ });
192
+ vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST].forEach((hook)=>{
193
+ if (hook.__H && Array.isArray(hook.__H)) hook.__H = void 0;
194
+ });
237
195
  }
238
- }
239
- );
240
- vnode[VNODE_COMPONENT][COMPONENT_HOOKS][HOOKS_LIST].forEach((hook) => {
241
- if (hook.__H && Array.isArray(hook.__H)) {
242
- hook.__H = void 0;
243
- }
244
- });
245
- }
246
- Component.prototype.forceUpdate.call(vnode[VNODE_COMPONENT]);
247
- }
248
- });
196
+ Component.prototype.forceUpdate.call(vnode[VNODE_COMPONENT]);
197
+ }
198
+ });
249
199
  }
250
200
  globalThis[NAMESPACE] = {
251
- getSignature: (type) => signaturesForType.get(type),
252
- register: (type, id) => {
253
- if (typeof type !== "function") return;
254
- if (typesById.has(id)) {
255
- const existing = typesById.get(id);
256
- if (existing !== type) {
257
- pendingUpdates.push([existing, type]);
258
- typesById.set(id, type);
259
- }
260
- } else {
261
- typesById.set(id, type);
262
- }
263
- if (!signaturesForType.has(type)) {
264
- signaturesForType.set(type, {
265
- getCustomHooks: () => [],
266
- type
267
- });
268
- }
269
- },
270
- getPendingUpdates: () => pendingUpdates,
271
- flush: () => {
272
- pendingUpdates = [];
273
- },
274
- replaceComponent,
275
- sign,
276
- computeKey
201
+ getSignature: (type)=>signaturesForType.get(type),
202
+ register: (type, id)=>{
203
+ if ('function' != typeof type) return;
204
+ if (typesById.has(id)) {
205
+ const existing = typesById.get(id);
206
+ if (existing !== type) {
207
+ pendingUpdates.push([
208
+ existing,
209
+ type
210
+ ]);
211
+ typesById.set(id, type);
212
+ }
213
+ } else typesById.set(id, type);
214
+ if (!signaturesForType.has(type)) signaturesForType.set(type, {
215
+ getCustomHooks: ()=>[],
216
+ type
217
+ });
218
+ },
219
+ getPendingUpdates: ()=>pendingUpdates,
220
+ flush: ()=>{
221
+ pendingUpdates = [];
222
+ },
223
+ replaceComponent,
224
+ sign,
225
+ computeKey: computeKey
277
226
  };
278
-
279
- // ../../../node_modules/.pnpm/@prefresh+utils@1.2.0/node_modules/@prefresh/utils/src/index.js
280
- var compareSignatures = (prev, next) => {
281
- const prevSignature = globalThis.__PREFRESH__.getSignature(prev) || {};
282
- const nextSignature = globalThis.__PREFRESH__.getSignature(next) || {};
283
- if (prevSignature.key !== nextSignature.key || globalThis.__PREFRESH__.computeKey(prevSignature) !== globalThis.__PREFRESH__.computeKey(nextSignature) || nextSignature.forceReset) {
284
- globalThis.__PREFRESH__.replaceComponent(prev, next, true);
285
- } else {
286
- globalThis.__PREFRESH__.replaceComponent(prev, next, false);
287
- }
227
+ const compareSignatures = (prev, next)=>{
228
+ const prevSignature = globalThis.__PREFRESH__.getSignature(prev) || {};
229
+ const nextSignature = globalThis.__PREFRESH__.getSignature(next) || {};
230
+ if (prevSignature.key !== nextSignature.key || globalThis.__PREFRESH__.computeKey(prevSignature) !== globalThis.__PREFRESH__.computeKey(nextSignature) || nextSignature.forceReset) globalThis.__PREFRESH__.replaceComponent(prev, next, true);
231
+ else globalThis.__PREFRESH__.replaceComponent(prev, next, false);
288
232
  };
289
- var flush = () => {
290
- const pending = [...globalThis.__PREFRESH__.getPendingUpdates()];
291
- globalThis.__PREFRESH__.flush();
292
- if (pending.length > 0) {
293
- pending.forEach(([prev, next]) => {
294
- compareSignatures(prev, next);
233
+ const flush = ()=>{
234
+ const pending = [
235
+ ...globalThis.__PREFRESH__.getPendingUpdates()
236
+ ];
237
+ globalThis.__PREFRESH__.flush();
238
+ if (pending.length > 0) pending.forEach(([prev, next])=>{
239
+ compareSignatures(prev, next);
295
240
  });
296
- }
297
241
  };
298
- var isComponent = (exportValue) => {
299
- if (typeof exportValue === "function") {
300
- if (exportValue.prototype != null && exportValue.prototype.isReactComponent) {
301
- return true;
242
+ const isComponent = (exportValue)=>{
243
+ if ('function' == typeof exportValue) {
244
+ if (null != exportValue.prototype && exportValue.prototype.isReactComponent) return true;
245
+ const name = exportValue.name || exportValue.displayName;
246
+ return 'string' == typeof name && name[0] && name[0] == name[0].toUpperCase();
302
247
  }
303
- const name = exportValue.name || exportValue.displayName;
304
- return typeof name === "string" && name[0] && name[0] == name[0].toUpperCase();
305
- }
306
- return false;
307
- };
308
- export {
309
- flush,
310
- isComponent
248
+ return false;
311
249
  };
250
+ export { flush, isComponent };
@@ -10,12 +10,11 @@
10
10
  "src"
11
11
  ],
12
12
  "scripts": {
13
- "build": "esbuild --bundle src/index.ts --outfile=dist/index.js --external:@lynx-js/react --define:self=globalThis --format=esm --alias:preact=@lynx-js/react/internal --alias:preact/hooks=@lynx-js/react"
13
+ "build": "rslib build"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@lynx-js/react": "workspace:*",
17
- "@prefresh/core": "^1.5.3",
18
- "@prefresh/utils": "^1.2.0",
19
- "esbuild": "^0.25.5"
17
+ "@prefresh/core": "^1.5.5",
18
+ "@prefresh/utils": "^1.2.1"
20
19
  }
21
20
  }
@@ -0,0 +1,24 @@
1
+ // Copyright 2025 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import { defineConfig } from '@rslib/core';
6
+
7
+ export default defineConfig({
8
+ lib: [
9
+ { format: 'esm', syntax: 'es2019' },
10
+ ],
11
+ output: {
12
+ externals: [
13
+ {
14
+ 'preact': '@lynx-js/react/internal',
15
+ 'preact/hooks': '@lynx-js/react',
16
+ },
17
+ ],
18
+ },
19
+ source: {
20
+ define: {
21
+ self: 'globalThis',
22
+ },
23
+ },
24
+ });
@@ -6,4 +6,5 @@ import { sExportsReactLepus, target } from './target';
6
6
 
7
7
  export const {
8
8
  createElement,
9
+ cloneElement,
9
10
  } = target[sExportsReactLepus];
@@ -13,6 +13,7 @@ export const {
13
13
  MainThreadRef,
14
14
  PureComponent,
15
15
  Suspense,
16
+ cloneElement,
16
17
  createContext,
17
18
  createElement,
18
19
  createRef,
@@ -1,4 +1,4 @@
1
1
  // Copyright 2024 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
- export { createElement } from 'react';
4
+ export { cloneElement, createElement } from 'react';