@lynx-js/react 0.111.1 → 0.111.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.
Files changed (134) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/components/lib/DeferredListItem.d.ts +3 -1
  3. package/components/lib/DeferredListItem.jsx +4 -2
  4. package/components/lib/DeferredListItem.jsx.map +1 -1
  5. package/components/src/DeferredListItem.tsx +5 -3
  6. package/package.json +6 -1
  7. package/refresh/.turbo/turbo-build.log +1 -1
  8. package/runtime/debug/index.cjs +8 -0
  9. package/runtime/debug/index.d.ts +4 -0
  10. package/runtime/debug/index.js +5 -0
  11. package/runtime/lib/alog/index.d.ts +1 -0
  12. package/runtime/lib/alog/index.js +8 -0
  13. package/runtime/lib/alog/index.js.map +1 -0
  14. package/runtime/lib/alog/render.d.ts +1 -0
  15. package/runtime/lib/alog/render.js +19 -0
  16. package/runtime/lib/alog/render.js.map +1 -0
  17. package/runtime/lib/backgroundSnapshot.d.ts +1 -0
  18. package/runtime/lib/backgroundSnapshot.js +31 -17
  19. package/runtime/lib/backgroundSnapshot.js.map +1 -1
  20. package/runtime/lib/debug/component-stack.d.ts +33 -0
  21. package/runtime/lib/debug/component-stack.js +145 -0
  22. package/runtime/lib/debug/component-stack.js.map +1 -0
  23. package/runtime/lib/debug/formatPatch.d.ts +2 -0
  24. package/runtime/lib/debug/formatPatch.js +27 -0
  25. package/runtime/lib/debug/formatPatch.js.map +1 -0
  26. package/runtime/lib/debug/printSnapshot.d.ts +1 -1
  27. package/runtime/lib/debug/printSnapshot.js +0 -4
  28. package/runtime/lib/debug/printSnapshot.js.map +1 -1
  29. package/runtime/lib/debug/profile.js +1 -3
  30. package/runtime/lib/debug/profile.js.map +1 -1
  31. package/runtime/lib/hydrate.js +11 -7
  32. package/runtime/lib/hydrate.js.map +1 -1
  33. package/runtime/lib/lifecycle/patch/commit.js +1 -1
  34. package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
  35. package/runtime/lib/lifecycle/patch/snapshotPatch.d.ts +4 -0
  36. package/runtime/lib/lifecycle/patch/snapshotPatch.js +28 -0
  37. package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -1
  38. package/runtime/lib/lynx.js +9 -0
  39. package/runtime/lib/lynx.js.map +1 -1
  40. package/runtime/lib/pendingListUpdates.d.ts +2 -1
  41. package/runtime/lib/pendingListUpdates.js +16 -4
  42. package/runtime/lib/pendingListUpdates.js.map +1 -1
  43. package/runtime/lib/renderToOpcodes/constants.d.ts +2 -0
  44. package/runtime/lib/renderToOpcodes/constants.js +2 -0
  45. package/runtime/lib/renderToOpcodes/constants.js.map +1 -1
  46. package/runtime/lib/root.d.ts +6 -0
  47. package/runtime/lib/root.js +4 -0
  48. package/runtime/lib/root.js.map +1 -1
  49. package/runtime/lib/snapshot/platformInfo.js +5 -3
  50. package/runtime/lib/snapshot/platformInfo.js.map +1 -1
  51. package/runtime/lib/snapshot/ref.d.ts +2 -2
  52. package/runtime/lib/snapshot/spread.js +3 -1
  53. package/runtime/lib/snapshot/spread.js.map +1 -1
  54. package/runtime/lib/snapshot.js +13 -7
  55. package/runtime/lib/snapshot.js.map +1 -1
  56. package/runtime/lib/utils.d.ts +2 -0
  57. package/runtime/lib/utils.js +23 -2
  58. package/runtime/lib/utils.js.map +1 -1
  59. package/testing-library/dist/env/vitest.js +12 -4
  60. package/types/react.d.ts +13 -1
  61. package/runtime/src/backgroundSnapshot.ts +0 -501
  62. package/runtime/src/compat/componentIs.ts +0 -30
  63. package/runtime/src/compat/initData.ts +0 -150
  64. package/runtime/src/compat/lynxComponent.ts +0 -79
  65. package/runtime/src/debug/debug.ts +0 -9
  66. package/runtime/src/debug/printSnapshot.ts +0 -28
  67. package/runtime/src/debug/profile.ts +0 -55
  68. package/runtime/src/document.ts +0 -84
  69. package/runtime/src/gesture/processGesture.ts +0 -89
  70. package/runtime/src/gesture/processGestureBagkround.ts +0 -19
  71. package/runtime/src/gesture/types.ts +0 -44
  72. package/runtime/src/hooks/react.ts +0 -62
  73. package/runtime/src/hooks/useLynxGlobalEventListener.ts +0 -59
  74. package/runtime/src/hydrate.ts +0 -368
  75. package/runtime/src/index.ts +0 -94
  76. package/runtime/src/internal.ts +0 -63
  77. package/runtime/src/legacy-react-runtime/index.ts +0 -42
  78. package/runtime/src/lifecycle/destroy.ts +0 -34
  79. package/runtime/src/lifecycle/event/delayEvents.ts +0 -11
  80. package/runtime/src/lifecycle/event/delayLifecycleEvents.ts +0 -15
  81. package/runtime/src/lifecycle/event/jsReady.ts +0 -34
  82. package/runtime/src/lifecycle/pass.ts +0 -14
  83. package/runtime/src/lifecycle/patch/commit.ts +0 -214
  84. package/runtime/src/lifecycle/patch/error.ts +0 -61
  85. package/runtime/src/lifecycle/patch/isMainThreadHydrationFinished.ts +0 -13
  86. package/runtime/src/lifecycle/patch/snapshotPatch.ts +0 -65
  87. package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +0 -145
  88. package/runtime/src/lifecycle/patch/updateMainThread.ts +0 -64
  89. package/runtime/src/lifecycle/ref/delay.ts +0 -99
  90. package/runtime/src/lifecycle/reload.ts +0 -97
  91. package/runtime/src/lifecycle/render.ts +0 -54
  92. package/runtime/src/lifecycleConstant.ts +0 -21
  93. package/runtime/src/list.ts +0 -307
  94. package/runtime/src/listUpdateInfo.ts +0 -221
  95. package/runtime/src/lynx/calledByNative.ts +0 -160
  96. package/runtime/src/lynx/component.ts +0 -113
  97. package/runtime/src/lynx/dynamic-js.ts +0 -36
  98. package/runtime/src/lynx/env.ts +0 -109
  99. package/runtime/src/lynx/injectLepusMethods.ts +0 -53
  100. package/runtime/src/lynx/lazy-bundle.ts +0 -175
  101. package/runtime/src/lynx/performance.ts +0 -148
  102. package/runtime/src/lynx/runWithForce.ts +0 -67
  103. package/runtime/src/lynx/tt.ts +0 -215
  104. package/runtime/src/lynx-api.ts +0 -455
  105. package/runtime/src/lynx.ts +0 -58
  106. package/runtime/src/opcodes.ts +0 -155
  107. package/runtime/src/pendingListUpdates.ts +0 -18
  108. package/runtime/src/renderToOpcodes/constants.ts +0 -24
  109. package/runtime/src/renderToOpcodes/index.ts +0 -306
  110. package/runtime/src/root.ts +0 -23
  111. package/runtime/src/snapshot/dynamicPartType.ts +0 -16
  112. package/runtime/src/snapshot/event.ts +0 -33
  113. package/runtime/src/snapshot/gesture.ts +0 -30
  114. package/runtime/src/snapshot/list.ts +0 -36
  115. package/runtime/src/snapshot/platformInfo.ts +0 -62
  116. package/runtime/src/snapshot/ref.ts +0 -139
  117. package/runtime/src/snapshot/spread.ts +0 -330
  118. package/runtime/src/snapshot/workletEvent.ts +0 -35
  119. package/runtime/src/snapshot/workletRef.ts +0 -88
  120. package/runtime/src/snapshot.ts +0 -634
  121. package/runtime/src/snapshotInstanceHydrationMap.ts +0 -17
  122. package/runtime/src/utils.ts +0 -44
  123. package/runtime/src/worklet/ctx.ts +0 -22
  124. package/runtime/src/worklet/destroy.ts +0 -16
  125. package/runtime/src/worklet/execMap.ts +0 -51
  126. package/runtime/src/worklet/functionCall.ts +0 -42
  127. package/runtime/src/worklet/functionality.ts +0 -29
  128. package/runtime/src/worklet/hmr.ts +0 -34
  129. package/runtime/src/worklet/indexMap.ts +0 -23
  130. package/runtime/src/worklet/runOnBackground.ts +0 -147
  131. package/runtime/src/worklet/runOnMainThread.ts +0 -50
  132. package/runtime/src/worklet/transformToWorklet.ts +0 -26
  133. package/runtime/src/worklet/workletRef.ts +0 -231
  134. package/runtime/src/worklet/workletRefPool.ts +0 -29
@@ -1,330 +0,0 @@
1
- // Copyright 2024 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
- /**
6
- * Handles JSX spread operator in the snapshot system.
7
- *
8
- * Spread operators in JSX (e.g., <div {...props}>) are transformed into
9
- * optimized attribute updates at compile time, avoiding runtime object spreads.
10
- */
11
-
12
- import type { Element, Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';
13
-
14
- import type { BackgroundSnapshotInstance } from '../backgroundSnapshot.js';
15
- import { ListUpdateInfoRecording } from '../listUpdateInfo.js';
16
- import { __pendingListUpdates } from '../pendingListUpdates.js';
17
- import { SnapshotInstance } from '../snapshot.js';
18
- import { isDirectOrDeepEqual, isEmptyObject, pick } from '../utils.js';
19
- import { updateEvent } from './event.js';
20
- import { updateGesture } from './gesture.js';
21
- import { platformInfoAttributes, updateListItemPlatformInfo } from './platformInfo.js';
22
- import { transformRef, updateRef } from './ref.js';
23
- import { updateWorkletEvent } from './workletEvent.js';
24
- import { updateWorkletRef } from './workletRef.js';
25
-
26
- // eslint-disable-next-line regexp/no-unused-capturing-group
27
- const eventRegExp = /^(([A-Za-z-]*):)?(bind|catch|capture-bind|capture-catch|global-bind)([A-Za-z]+)$/;
28
- const eventTypeMap: Record<string, string> = {
29
- bind: 'bindEvent',
30
- catch: 'catchEvent',
31
- 'capture-bind': 'capture-bind',
32
- 'capture-catch': 'capture-catch',
33
- 'global-bind': 'global-bindEvent',
34
- };
35
- const noFlattenAttributes = /* @__PURE__ */ new Set<string>([
36
- 'name',
37
- 'clip-radius',
38
- 'overlap',
39
- 'exposure-scene',
40
- 'exposure-id',
41
- ]);
42
-
43
- function updateSpread(
44
- snapshot: SnapshotInstance,
45
- index: number,
46
- oldValue: Record<string, unknown> | undefined | null,
47
- elementIndex: number,
48
- ): void {
49
- oldValue ??= {};
50
- let newValue: Record<string, unknown> = snapshot.__values![index] as Record<string, unknown>; // compiler guarantee this must be an object;
51
-
52
- const list = snapshot.parentNode;
53
- if (list?.__snapshot_def.isListHolder) {
54
- const oldPlatformInfo = pick(oldValue, platformInfoAttributes);
55
- const platformInfo = pick(newValue, platformInfoAttributes);
56
- if (!isDirectOrDeepEqual(oldPlatformInfo, platformInfo)) {
57
- (__pendingListUpdates.values[list.__id] ??= new ListUpdateInfoRecording(list)).onSetAttribute(
58
- snapshot,
59
- platformInfo,
60
- oldPlatformInfo,
61
- );
62
- snapshot.__listItemPlatformInfo = platformInfo;
63
-
64
- // The fakeSnapshot is missing `__parent`, so no `ListUpdateInfoRecording#onSetAttribute` will be called
65
- const fakeSnapshot = {
66
- __values: {
67
- get [index]() {
68
- return platformInfo;
69
- },
70
- },
71
- __id: snapshot.__id,
72
- __elements: snapshot.__elements,
73
- } as SnapshotInstance;
74
- updateListItemPlatformInfo(fakeSnapshot, index, oldPlatformInfo, elementIndex);
75
- }
76
- }
77
-
78
- if (!snapshot.__elements) {
79
- return;
80
- }
81
-
82
- if ('__spread' in newValue) {
83
- // first screen
84
- newValue = transformSpread(snapshot, index, newValue);
85
- snapshot.__values![index] = newValue;
86
- }
87
-
88
- const dataset: Record<string, unknown> = {};
89
- let match: RegExpMatchArray | null = null;
90
- for (const key in newValue) {
91
- const v = newValue[key];
92
- if (v !== oldValue[key]) {
93
- if (key === 'className') {
94
- __SetClasses(snapshot.__elements[elementIndex]!, v as string);
95
- } else if (key === 'style') {
96
- __SetInlineStyles(snapshot.__elements[elementIndex]!, v as string);
97
- } else if (key === 'id') {
98
- __SetID(snapshot.__elements[elementIndex]!, v as string);
99
- } else if (key.startsWith('data-')) {
100
- // collected below
101
- } else if (key === 'ref') {
102
- const fakeSnapshot = {
103
- __values: {
104
- get [index]() {
105
- return v;
106
- },
107
- set [index](value: unknown) {
108
- // Modifications to the ref value should be reflected in the corresponding position of the spread.
109
- newValue[key] = value;
110
- },
111
- },
112
- __id: snapshot.__id,
113
- __elements: snapshot.__elements,
114
- } as SnapshotInstance;
115
- updateRef(fakeSnapshot, index, oldValue[key] as string | null, elementIndex);
116
- } else if (key.endsWith(':ref')) {
117
- snapshot.__worklet_ref_set ??= new Set();
118
- const fakeSnapshot = {
119
- __values: {
120
- get [index]() {
121
- return v;
122
- },
123
- },
124
- __id: snapshot.__id,
125
- __elements: snapshot.__elements,
126
- __worklet_ref_set: snapshot.__worklet_ref_set,
127
- } as SnapshotInstance;
128
- updateWorkletRef(
129
- fakeSnapshot,
130
- index,
131
- oldValue[key] as WorkletRefImpl<Element> | Worklet | null | undefined,
132
- elementIndex,
133
- key.slice(0, -4),
134
- );
135
- } else if (key.endsWith(':gesture')) {
136
- const workletType = key.slice(0, -8);
137
- const fakeSnapshot = {
138
- __values: {
139
- get [index]() {
140
- return v;
141
- },
142
- },
143
- __id: snapshot.__id,
144
- __elements: snapshot.__elements,
145
- } as SnapshotInstance;
146
- updateGesture(fakeSnapshot, index, oldValue[key], elementIndex, workletType);
147
- } else if ((match = eventRegExp.exec(key))) {
148
- const workletType = match[2];
149
- const eventType = eventTypeMap[match[3]!]!;
150
- const eventName = match[4]!;
151
- const fakeSnapshot = {
152
- __values: {
153
- get [index]() {
154
- return v;
155
- },
156
- set [index](value: unknown) {
157
- // Modifications to the event value should be reflected in the corresponding position of the spread.
158
- newValue[key] = value;
159
- },
160
- },
161
- __id: snapshot.__id,
162
- __elements: snapshot.__elements,
163
- } as SnapshotInstance;
164
- if (workletType) {
165
- updateWorkletEvent(
166
- fakeSnapshot,
167
- index,
168
- oldValue[key] as Worklet,
169
- elementIndex,
170
- workletType,
171
- eventType,
172
- eventName,
173
- );
174
- } else {
175
- updateEvent(fakeSnapshot, index, oldValue[key], elementIndex, eventType, eventName, key);
176
- }
177
- } else if (platformInfoAttributes.has(key)) {
178
- // ignore
179
- } else {
180
- __SetAttribute(snapshot.__elements[elementIndex]!, key, v);
181
- }
182
- }
183
-
184
- // collect data regardless of whether it has changed
185
- if (key.startsWith('data-')) {
186
- dataset[key.slice(5)] = v;
187
- }
188
- }
189
-
190
- let hasOldDataset = false;
191
- for (const key in oldValue) {
192
- if (!(key in newValue)) {
193
- if (key === 'className') {
194
- __SetClasses(snapshot.__elements[elementIndex]!, '');
195
- } else if (key === 'style') {
196
- __SetInlineStyles(snapshot.__elements[elementIndex]!, '');
197
- } else if (key === 'id') {
198
- __SetID(snapshot.__elements[elementIndex]!, null);
199
- } else if (key.startsWith('data-')) {
200
- // collected below
201
- } else if (key === 'ref') {
202
- const fakeSnapshot = {
203
- __values: {
204
- get [index]() {
205
- return undefined;
206
- },
207
- set [index](value: unknown) {
208
- // Modifications to the ref value should be reflected in the corresponding position of the spread.
209
- newValue[key] = value;
210
- },
211
- },
212
- __id: snapshot.__id,
213
- __elements: snapshot.__elements,
214
- } as SnapshotInstance;
215
- updateRef(fakeSnapshot, index, oldValue[key] as string | null, elementIndex);
216
- } else if (key.endsWith(':ref')) {
217
- snapshot.__worklet_ref_set ??= new Set();
218
- const fakeSnapshot = {
219
- __values: {
220
- get [index]() {
221
- return undefined;
222
- },
223
- },
224
- __id: snapshot.__id,
225
- __elements: snapshot.__elements,
226
- __worklet_ref_set: snapshot.__worklet_ref_set,
227
- } as SnapshotInstance;
228
- updateWorkletRef(
229
- fakeSnapshot,
230
- index,
231
- oldValue[key] as WorkletRefImpl<Element> | Worklet | null | undefined,
232
- elementIndex,
233
- key.slice(0, -4),
234
- );
235
- } else if (key.endsWith(':gesture')) {
236
- const workletType = key.slice(0, -8);
237
- const fakeSnapshot = {
238
- __values: {
239
- get [index]() {
240
- return undefined;
241
- },
242
- },
243
- __id: snapshot.__id,
244
- __elements: snapshot.__elements,
245
- } as SnapshotInstance;
246
- updateGesture(fakeSnapshot, index, oldValue[key], elementIndex, workletType);
247
- } else if ((match = eventRegExp.exec(key))) {
248
- const workletType = match[2];
249
- const eventType = eventTypeMap[match[3]!]!;
250
- const eventName = match[4]!;
251
- const fakeSnapshot = {
252
- __values: {
253
- get [index]() {
254
- return undefined;
255
- },
256
- set [index](value: unknown) {
257
- newValue[key] = value;
258
- },
259
- },
260
- __id: snapshot.__id,
261
- __elements: snapshot.__elements,
262
- } as SnapshotInstance;
263
- if (workletType) {
264
- updateWorkletEvent(
265
- fakeSnapshot,
266
- index,
267
- oldValue[key] as Worklet,
268
- elementIndex,
269
- workletType,
270
- eventType,
271
- eventName,
272
- );
273
- } else {
274
- updateEvent(fakeSnapshot, index, oldValue[key], elementIndex, eventType, eventName, key);
275
- }
276
- } else if (platformInfoAttributes.has(key)) {
277
- // ignore
278
- } else {
279
- __SetAttribute(snapshot.__elements[elementIndex]!, key, null);
280
- }
281
- }
282
-
283
- // collect data regardless of whether it has changed
284
- if (key.startsWith('data-')) {
285
- hasOldDataset = true;
286
- }
287
- }
288
-
289
- // TODO: compare dataset before commit it to native?
290
- if (hasOldDataset || !isEmptyObject(dataset)) {
291
- __SetDataset(snapshot.__elements[elementIndex]!, dataset);
292
- }
293
- }
294
-
295
- function transformSpread(
296
- snapshot: BackgroundSnapshotInstance | SnapshotInstance,
297
- index: number,
298
- spread: Record<string, unknown>,
299
- ): Record<string, unknown> {
300
- const result: Record<string, unknown> = {};
301
- let hasNoFlattenAttributes = false;
302
- for (const key in spread) {
303
- let value = spread[key];
304
- if (key === '__spread') {}
305
- else if (key === 'class' || key === 'className') {
306
- value ??= '';
307
- result['className'] = value;
308
- } else if (key === 'ref') {
309
- if (__LEPUS__) {
310
- result[key] = value ? 1 : undefined;
311
- } else {
312
- result[key] = transformRef(value)?.__ref;
313
- }
314
- } else if (typeof value === 'function') {
315
- result[key] = `${snapshot.__id}:${index}:${key}`;
316
- } else {
317
- if (!hasNoFlattenAttributes && noFlattenAttributes.has(key)) {
318
- hasNoFlattenAttributes = true;
319
- }
320
- result[key] = value;
321
- }
322
- }
323
-
324
- if (hasNoFlattenAttributes) {
325
- result['flatten'] = false;
326
- }
327
- return result;
328
- }
329
-
330
- export { transformSpread, updateSpread };
@@ -1,35 +0,0 @@
1
- // Copyright 2024 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
- import { onWorkletCtxUpdate } from '@lynx-js/react/worklet-runtime/bindings';
5
- import type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';
6
-
7
- import { isMainThreadHydrationFinished } from '../lifecycle/patch/isMainThreadHydrationFinished.js';
8
- import { SnapshotInstance } from '../snapshot.js';
9
-
10
- function updateWorkletEvent(
11
- snapshot: SnapshotInstance,
12
- expIndex: number,
13
- oldValue: Worklet,
14
- elementIndex: number,
15
- workletType: string,
16
- eventType: string,
17
- eventName: string,
18
- ): void {
19
- if (!snapshot.__elements) {
20
- return;
21
- }
22
- const value = (snapshot.__values![expIndex] as Worklet || undefined) ?? {};
23
- value._workletType = workletType;
24
-
25
- if (workletType === 'main-thread') {
26
- onWorkletCtxUpdate(value, oldValue, !isMainThreadHydrationFinished, snapshot.__elements[elementIndex]!);
27
- const event = {
28
- type: 'worklet',
29
- value,
30
- };
31
- __AddEvent(snapshot.__elements[elementIndex]!, eventType, eventName, event);
32
- }
33
- }
34
-
35
- export { updateWorkletEvent };
@@ -1,88 +0,0 @@
1
- // Copyright 2024 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 { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef as update } from '@lynx-js/react/worklet-runtime/bindings';
6
- import type { Element, Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';
7
-
8
- import { isMainThreadHydrationFinished } from '../lifecycle/patch/isMainThreadHydrationFinished.js';
9
- import type { SnapshotInstance } from '../snapshot.js';
10
-
11
- let mtRefQueue: (WorkletRefImpl<Element> | Worklet | Element)[] = [];
12
-
13
- export function applyRefQueue(): void {
14
- const queue = mtRefQueue;
15
- mtRefQueue = [];
16
- for (let i = 0; i < queue.length; i += 2) {
17
- const worklet = queue[i] as Worklet | WorkletRefImpl<Element>;
18
- const element = queue[i + 1] as Element;
19
- if ('_wvid' in worklet) {
20
- update(worklet as WorkletRefImpl<Element>, element);
21
- } else if ('_wkltId' in worklet) {
22
- worklet._unmount = runWorkletCtx(worklet, [{ elementRefptr: element }]) as () => void;
23
- }
24
- }
25
- }
26
-
27
- function addToRefQueue(worklet: Worklet | WorkletRefImpl<Element>, element: Element): void {
28
- mtRefQueue.push(worklet, element);
29
- }
30
-
31
- export function workletUnRef(value: Worklet | WorkletRefImpl<Element>): void {
32
- if ('_wvid' in value) {
33
- update(value as WorkletRefImpl<Element>, null);
34
- } else if ('_wkltId' in value) {
35
- if (typeof value._unmount == 'function') {
36
- (value._unmount as () => void)();
37
- } else {
38
- runWorkletCtx(value, [null]);
39
- }
40
- }
41
- }
42
-
43
- export function updateWorkletRef(
44
- snapshot: SnapshotInstance,
45
- expIndex: number,
46
- oldValue: WorkletRefImpl<Element> | Worklet | null | undefined,
47
- elementIndex: number,
48
- _workletType: string,
49
- ): void {
50
- if (!snapshot.__elements) {
51
- return;
52
- }
53
-
54
- if (oldValue && snapshot.__worklet_ref_set?.has(oldValue)) {
55
- workletUnRef(oldValue);
56
- snapshot.__worklet_ref_set?.delete(oldValue);
57
- }
58
-
59
- const value = snapshot.__values![expIndex] as (WorkletRefImpl<Element> | Worklet | undefined);
60
- if (value === null || value === undefined) {
61
- // do nothing
62
- } else if (value._wvid) {
63
- const element = snapshot.__elements[elementIndex]! as Element;
64
- addToRefQueue(value as Worklet, element);
65
- } else if ((value as Worklet)._wkltId) {
66
- const element = snapshot.__elements[elementIndex]! as Element;
67
- onWorkletCtxUpdate(
68
- value as Worklet,
69
- oldValue as Worklet | undefined,
70
- !isMainThreadHydrationFinished,
71
- element,
72
- );
73
- addToRefQueue(value as Worklet, element);
74
- /* v8 ignore next 3 */
75
- } else if (value._type === '__LEPUS__' || (value as Worklet)._lepusWorkletHash) {
76
- // for pre-0.99 compatibility
77
- // During the initial render, we will not update the WorkletRef because the background thread is not ready yet.
78
- } else {
79
- throw new Error('MainThreadRef: main-thread:ref must be of type MainThreadRef or main-thread function.');
80
- }
81
-
82
- if (value) {
83
- snapshot.__worklet_ref_set ??= new Set();
84
- snapshot.__worklet_ref_set.add(value);
85
- }
86
- // Add an arbitrary attribute to avoid this element being layout-only
87
- __SetAttribute(snapshot.__elements[elementIndex]!, 'has-react-ref', true);
88
- }