@lynx-js/react 0.129.1 → 0.129.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 (121) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +1 -1
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/runtime/__test__/core/globalProps.test.ts +27 -6
  6. package/runtime/__test__/element-template/fixtures/gesture/direct/index.tsx +33 -0
  7. package/runtime/__test__/element-template/fixtures/spread/mts/index.tsx +197 -0
  8. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +89 -3
  9. package/runtime/__test__/element-template/native/mts-destroy.test.ts +8 -3
  10. package/runtime/__test__/element-template/native/reload.test.ts +87 -0
  11. package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +5 -5
  12. package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +1 -1
  13. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +70 -0
  14. package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +3 -4
  15. package/runtime/__test__/element-template/runtime/background/reload.test.ts +74 -0
  16. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +15 -0
  17. package/runtime/__test__/element-template/runtime/prop-adapters/gesture-compiled.test.ts +200 -0
  18. package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +420 -0
  19. package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +527 -0
  20. package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +185 -6
  21. package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +21 -1
  22. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +188 -0
  23. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.event.test.jsx +2 -2
  24. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +3 -3
  25. package/runtime/__test__/snapshot/ref.test.jsx +30 -0
  26. package/runtime/lazy/element-template-internal.js +1 -0
  27. package/runtime/lib/core/globalProps.js +1 -1
  28. package/runtime/lib/core/globalProps.js.map +1 -1
  29. package/runtime/lib/element-template/background/attr-slots.js +5 -2
  30. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  31. package/runtime/lib/element-template/background/destroy.js +16 -11
  32. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  33. package/runtime/lib/element-template/background/hydrate.js +23 -0
  34. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  35. package/runtime/lib/element-template/debug/alog.d.ts +1 -1
  36. package/runtime/lib/element-template/debug/alog.js +4 -1
  37. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  38. package/runtime/lib/element-template/internal.d.ts +1 -1
  39. package/runtime/lib/element-template/internal.js +1 -1
  40. package/runtime/lib/element-template/internal.js.map +1 -1
  41. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js +6 -1
  42. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
  43. package/runtime/lib/element-template/native/patch-listener.js +1 -1
  44. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  45. package/runtime/lib/element-template/native/reload-background.js +1 -1
  46. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  47. package/runtime/lib/element-template/native/reload-main-thread.js +33 -9
  48. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  49. package/runtime/lib/element-template/prop-adapters/gesture.d.ts +23 -0
  50. package/runtime/lib/element-template/prop-adapters/gesture.js +97 -0
  51. package/runtime/lib/element-template/prop-adapters/gesture.js.map +1 -0
  52. package/runtime/lib/element-template/prop-adapters/spread.d.ts +6 -1
  53. package/runtime/lib/element-template/prop-adapters/spread.js +72 -2
  54. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  55. package/runtime/lib/element-template/protocol/opcodes.d.ts +1 -0
  56. package/runtime/lib/element-template/protocol/opcodes.js +1 -0
  57. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  58. package/runtime/lib/element-template/protocol/types.d.ts +7 -1
  59. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  60. package/runtime/lib/element-template/runtime/patch.js +27 -2
  61. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  62. package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +4 -2
  63. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
  64. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  65. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +7 -2
  66. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +368 -58
  67. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  68. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +2 -1
  69. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js +10 -1
  70. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  71. package/runtime/lib/element-template/runtime/template/typed-attributes.js +3 -3
  72. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  73. package/runtime/lib/snapshot/lifecycle/destroy.js +23 -17
  74. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  75. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +5 -0
  76. package/runtime/lib/snapshot/lifecycle/ref/delay.js +1 -1
  77. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  78. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  79. package/runtime/src/core/globalProps.ts +1 -1
  80. package/runtime/src/element-template/background/attr-slots.ts +5 -1
  81. package/runtime/src/element-template/background/destroy.ts +16 -13
  82. package/runtime/src/element-template/background/hydrate.ts +23 -0
  83. package/runtime/src/element-template/debug/alog.ts +5 -2
  84. package/runtime/src/element-template/internal.ts +1 -0
  85. package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +5 -1
  86. package/runtime/src/element-template/native/patch-listener.ts +1 -1
  87. package/runtime/src/element-template/native/reload-background.ts +1 -1
  88. package/runtime/src/element-template/native/reload-main-thread.ts +30 -10
  89. package/runtime/src/element-template/prop-adapters/gesture.ts +144 -0
  90. package/runtime/src/element-template/prop-adapters/spread.ts +110 -2
  91. package/runtime/src/element-template/protocol/opcodes.ts +1 -0
  92. package/runtime/src/element-template/protocol/types.ts +8 -0
  93. package/runtime/src/element-template/runtime/patch.ts +33 -0
  94. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +31 -4
  95. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +441 -65
  96. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +12 -2
  97. package/runtime/src/element-template/runtime/template/typed-attributes.ts +3 -3
  98. package/runtime/src/snapshot/lifecycle/destroy.ts +23 -18
  99. package/runtime/src/snapshot/lifecycle/ref/delay.ts +1 -1
  100. package/runtime/types/types.d.ts +2 -1
  101. package/testing-library/.turbo/turbo-build.log +7 -7
  102. package/transform/.turbo/turbo-build$colon$wasm.log +205 -91
  103. package/transform/__test__/fixture.spec.js +11 -11
  104. package/transform/__test__/main-thread-object-compat.spec.js +111 -0
  105. package/transform/crates/swc_plugin_element_template/lib.rs +11 -0
  106. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +113 -0
  107. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +7 -9
  108. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +3 -3
  109. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +3 -3
  110. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +7 -7
  111. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -7
  112. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +8 -8
  113. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +8 -8
  114. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +5 -5
  115. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +5 -5
  116. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +1 -1
  117. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +1 -1
  118. package/transform/dist/wasm.cjs +1 -1
  119. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +160 -133
  120. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  121. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +180 -293
@@ -1,7 +1,10 @@
1
1
  import { afterEach, describe, expect, it, vi } from 'vitest';
2
2
 
3
3
  import { getEventValue } from '../../../../src/element-template/prop-adapters/event-value.js';
4
- import { prepareSpreadAttrSlot } from '../../../../src/element-template/prop-adapters/spread.js';
4
+ import {
5
+ prepareSpreadAttrSlot,
6
+ prepareTypedSpreadAttrSlot,
7
+ } from '../../../../src/element-template/prop-adapters/spread.js';
5
8
 
6
9
  afterEach(() => {
7
10
  lynx.__runtime_configs__ = { transformBuiltinAttributeNames: false };
@@ -74,7 +77,7 @@ describe('ElementTemplate spread prop adapter', () => {
74
77
  __spread: true,
75
78
  ref,
76
79
  bindtap: handleTap,
77
- 'main-thread:bindtap': unsupportedWorkletEvent,
80
+ 'worklet:bindtap': unsupportedWorkletEvent,
78
81
  onReady: unsupportedFunctionProp,
79
82
  },
80
83
  );
@@ -145,16 +148,192 @@ describe('ElementTemplate spread prop adapter', () => {
145
148
  expect(prepareSpreadAttrSlot(-4, 0, false)).toBeNull();
146
149
  });
147
150
 
148
- it('ignores non-host spread props', () => {
151
+ it('ignores non-host spread props and isolates typed host spreads from main-thread capabilities', () => {
149
152
  const prepared = prepareSpreadAttrSlot(-5, 0, {
150
153
  'worklet:ref': vi.fn(),
151
- 'main-thread:ref': vi.fn(),
152
- 'main-thread:bindtap': vi.fn(),
153
- 'main-thread:gesture': {},
154
+ 'worklet:bindtap': vi.fn(),
155
+ 'worklet:gesture': {},
156
+ 'main-thread:custom': () => {},
154
157
  onReady: vi.fn(),
155
158
  title: 'hello',
156
159
  });
157
160
 
158
161
  expect(prepared).toEqual({ title: 'hello' });
162
+
163
+ const typedPrepared = prepareTypedSpreadAttrSlot(-5, 0, {
164
+ 'main-thread:ref': { _wvid: 1 },
165
+ 'main-thread:bindtap': { _wkltId: 'tap' },
166
+ 'main-thread:gesture': { __isGesture: true, id: 1, type: 0, callbacks: {} },
167
+ title: 'typed',
168
+ });
169
+
170
+ expect(typedPrepared).toEqual({ title: 'typed' });
171
+ });
172
+
173
+ it('prepares main-thread events, MTRef, and Gesture in compiled spread slots while ignoring inherited keys', () => {
174
+ const tapWorklet = { _wkltId: 'tap-wklt' };
175
+ const captureCatchWorklet = { _wkltId: 'capture-catch-wklt' };
176
+ const globalWorklet = { _wkltId: 'global-wklt' };
177
+ const mtRef = { _wvid: 9 };
178
+ const panGesture = {
179
+ __isGesture: true,
180
+ id: 3,
181
+ type: 0,
182
+ config: { minDistance: 8 },
183
+ callbacks: { onUpdate: { _wkltId: 'pan-update' } },
184
+ };
185
+
186
+ const rawSpread = Object.assign(
187
+ Object.create({
188
+ 'main-thread:bindinherited': { _wkltId: 'inherited-event' },
189
+ 'main-thread:ref': { _wvid: 99 },
190
+ 'main-thread:gesture': panGesture,
191
+ }) as Record<string, unknown>,
192
+ {
193
+ id: 'card',
194
+ 'main-thread:bindtap': tapWorklet,
195
+ 'main-thread:capture-catchtouchmove': captureCatchWorklet,
196
+ 'main-thread:global-bindCustom': globalWorklet,
197
+ 'main-thread:catchtouchend': null,
198
+ 'main-thread:ref': mtRef,
199
+ 'main-thread:gesture': panGesture,
200
+ },
201
+ );
202
+
203
+ const firstPrepared = prepareSpreadAttrSlot(-6, 1, rawSpread) as Record<string, any>;
204
+ expect(firstPrepared).toMatchObject({
205
+ id: 'card',
206
+ 'main-thread:bindtap': { type: 'worklet', value: { _wkltId: 'tap-wklt' } },
207
+ 'main-thread:capture-catchtouchmove': { type: 'worklet', value: { _wkltId: 'capture-catch-wklt' } },
208
+ 'main-thread:global-bindCustom': { type: 'worklet', value: { _wkltId: 'global-wklt' } },
209
+ 'main-thread:catchtouchend': null,
210
+ 'main-thread:ref': { type: 'main-thread-ref', value: mtRef },
211
+ 'main-thread:gesture': {
212
+ type: 'gesture',
213
+ value: [{ id: 3, type: 0, config: { minDistance: 8 } }],
214
+ },
215
+ });
216
+ expect(firstPrepared).not.toHaveProperty('main-thread:bindinherited');
217
+
218
+ // Re-preparing with identical raw callback identities reuses prepared wrappers.
219
+ const nextRawSpread = { ...rawSpread, id: 'card-next' };
220
+ const secondPrepared = prepareSpreadAttrSlot(-6, 1, nextRawSpread, {
221
+ previousPreparedSlots: [null, firstPrepared],
222
+ previousRawSlots: [null, rawSpread],
223
+ }) as Record<string, any>;
224
+ expect(secondPrepared['main-thread:bindtap']).toBe(firstPrepared['main-thread:bindtap']);
225
+ expect(secondPrepared['main-thread:ref']).toBe(firstPrepared['main-thread:ref']);
226
+ expect(
227
+ secondPrepared['main-thread:gesture'].value[0].callbacks[0].callback,
228
+ ).toBe(firstPrepared['main-thread:gesture'].value[0].callbacks[0].callback);
229
+
230
+ expect(
231
+ prepareSpreadAttrSlot(-6, 1, {
232
+ 'main-thread:ref': undefined,
233
+ 'main-thread:gesture': false,
234
+ 'main-thread:bindtap': undefined,
235
+ }),
236
+ ).toEqual({
237
+ 'main-thread:ref': null,
238
+ 'main-thread:gesture': null,
239
+ 'main-thread:bindtap': null,
240
+ });
241
+
242
+ expect(() => prepareSpreadAttrSlot(-6, 1, { 'main-thread:ref': vi.fn() })).toThrow(
243
+ 'ElementTemplate main-thread:ref expects a MainThreadRef object or a main-thread function.',
244
+ );
245
+ expect(() => prepareSpreadAttrSlot(-6, 1, { 'main-thread:gesture': {} })).toThrow(
246
+ 'ElementTemplate main-thread:gesture expects a Gesture object.',
247
+ );
248
+
249
+ const inheritedOnlySpread = Object.create({
250
+ 'main-thread:ref': mtRef,
251
+ 'main-thread:gesture': panGesture,
252
+ 'main-thread:bindtap': tapWorklet,
253
+ }) as Record<string, unknown>;
254
+ inheritedOnlySpread.id = 'own-only';
255
+ const inheritedPrepared = prepareSpreadAttrSlot(-6, 1, inheritedOnlySpread) as Record<string, any>;
256
+ expect(inheritedPrepared).toEqual({ id: 'own-only' });
257
+
258
+ const addedMtsRaw = {
259
+ id: 'added-mts',
260
+ 'main-thread:ref': mtRef,
261
+ 'main-thread:gesture': panGesture,
262
+ 'main-thread:bindtap': tapWorklet,
263
+ };
264
+ const addedFromEmpty = prepareSpreadAttrSlot(-6, 1, addedMtsRaw, {
265
+ previousPreparedSlots: [null, { id: 'own-only', 'main-thread:gesture': null }],
266
+ previousRawSlots: [null, { id: 'own-only', 'main-thread:gesture': null }],
267
+ }) as Record<string, any>;
268
+ expect(addedFromEmpty['main-thread:ref']).toEqual({ type: 'main-thread-ref', value: mtRef });
269
+ expect(addedFromEmpty['main-thread:gesture']).toMatchObject({ type: 'gesture' });
270
+ expect(addedFromEmpty['main-thread:bindtap']).toMatchObject({ type: 'worklet' });
271
+ });
272
+
273
+ it('reports invalid main-thread event handlers in development and normalizes them to null', () => {
274
+ const oldReportError = lynx.reportError;
275
+ const reportError = vi.fn();
276
+ lynx.reportError = reportError;
277
+ const originalDev = globalThis.__DEV__;
278
+
279
+ try {
280
+ globalThis.__DEV__ = true;
281
+ expect(prepareSpreadAttrSlot(-7, 2, { 'main-thread:bindtap': () => {} })).toEqual({
282
+ 'main-thread:bindtap': null,
283
+ });
284
+ expect(reportError).toHaveBeenCalledTimes(1);
285
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
286
+ 'ElementTemplate main-thread event slot -7:2 (main-thread:bindtap) expects a worklet ctx object.',
287
+ );
288
+
289
+ reportError.mockClear();
290
+ globalThis.__DEV__ = false;
291
+ expect(prepareSpreadAttrSlot(-7, 2, { 'main-thread:bindtap': () => {} })).toEqual({
292
+ 'main-thread:bindtap': null,
293
+ });
294
+ expect(reportError).not.toHaveBeenCalled();
295
+ } finally {
296
+ globalThis.__DEV__ = originalDev;
297
+ lynx.reportError = oldReportError;
298
+ }
299
+ });
300
+
301
+ it('re-prepares MTEvent, MTRef, and Gesture when caller mutates a reused spread object in place', () => {
302
+ const firstTap = { _wkltId: 'first-tap' };
303
+ const nextTap = { _wkltId: 'next-tap' };
304
+ const firstRef = { _wvid: 1 };
305
+ const nextRef = { _wvid: 2 };
306
+ const firstGestureCb = { _wkltId: 'first-pan' };
307
+ const nextGestureCb = { _wkltId: 'next-pan' };
308
+
309
+ const spread: Record<string, any> = {
310
+ id: 'mutable',
311
+ 'main-thread:bindtap': firstTap,
312
+ 'main-thread:ref': firstRef,
313
+ 'main-thread:gesture': {
314
+ __isGesture: true,
315
+ id: 1,
316
+ type: 0,
317
+ callbacks: { onUpdate: firstGestureCb },
318
+ },
319
+ };
320
+
321
+ const firstPrepared = prepareSpreadAttrSlot(1, 0, spread) as Record<string, any>;
322
+
323
+ // Mutate the same spread object and nested gesture callbacks in place.
324
+ spread['main-thread:bindtap'] = nextTap;
325
+ spread['main-thread:ref'] = nextRef;
326
+ spread['main-thread:gesture'].callbacks.onUpdate = nextGestureCb;
327
+
328
+ const secondPrepared = prepareSpreadAttrSlot(1, 0, spread, {
329
+ previousRawSlots: [spread],
330
+ previousPreparedSlots: [firstPrepared],
331
+ }) as Record<string, any>;
332
+
333
+ expect(secondPrepared['main-thread:bindtap']).not.toBe(firstPrepared['main-thread:bindtap']);
334
+ expect(secondPrepared['main-thread:bindtap'].value._wkltId).toBe('next-tap');
335
+ expect(secondPrepared['main-thread:ref']).not.toBe(firstPrepared['main-thread:ref']);
336
+ expect(secondPrepared['main-thread:ref'].value._wvid).toBe(2);
337
+ expect(secondPrepared['main-thread:gesture'].value[0].callbacks[0].callback._wkltId).toBe('next-pan');
159
338
  });
160
339
  });
@@ -512,7 +512,7 @@ describe('direct renderer native contracts', () => {
512
512
  __etAttrPlanMap._et_spread = [0, adaptSpreadAttrSlot];
513
513
 
514
514
  renderToElementTemplate(
515
- h('_et_spread', { attributeSlots: [{ id: 'cta', ref, 'main-thread:ref': vi.fn(), 'worklet:ref': vi.fn() }] }),
515
+ h('_et_spread', { attributeSlots: [{ id: 'cta', ref, 'custom:ref': vi.fn(), 'worklet:ref': vi.fn() }] }),
516
516
  );
517
517
 
518
518
  expect(createElementTemplate).toHaveBeenCalledWith(
@@ -524,4 +524,24 @@ describe('direct renderer native contracts', () => {
524
524
  );
525
525
  expect(ref).not.toHaveBeenCalled();
526
526
  });
527
+
528
+ it('strips spread main-thread:ref from native create while adding layout-only and flatten guards', () => {
529
+ const rootRef = { kind: 'root-ref' };
530
+ const mtRef = { _wvid: 1 };
531
+ createElementTemplate.mockReturnValue(rootRef);
532
+ __etAttrPlanMap['__Card__:_et_spread'] = [0, adaptSpreadAttrSlot];
533
+
534
+ const rendered = renderToElementTemplate(
535
+ h('__Card__:_et_spread', { attributeSlots: [{ id: 'cta', 'main-thread:ref': mtRef }] }),
536
+ );
537
+
538
+ expect(createElementTemplate).toHaveBeenCalledWith(
539
+ '_et_spread',
540
+ null,
541
+ [{ id: 'cta', 'has-react-ref': true, flatten: false }],
542
+ null,
543
+ -1,
544
+ );
545
+ expect(rendered.rootSubtreeHandles).toEqual([[{ uid: -1, ref: rootRef }]]);
546
+ });
527
547
  });
@@ -9,6 +9,7 @@ import {
9
9
  __etAttrPlanMap,
10
10
  adaptMTEventAttrSlot,
11
11
  adaptMTRefAttrSlot,
12
+ adaptSpreadAttrSlot,
12
13
  clearEtAttrPlanMap,
13
14
  } from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
14
15
  import {
@@ -19,9 +20,12 @@ import {
19
20
  detachMainThreadDynamicAttrRefsForSubtree,
20
21
  getMainThreadDynamicAttrState,
21
22
  initializeMainThreadDynamicAttrSlots,
23
+ isSpreadDynamicAttrSlot,
22
24
  prepareMainThreadDynamicAttrSlotsForNative,
25
+ prepareSpreadAttrSlotForNative,
23
26
  updateMainThreadEventAttrSlot as setMTEventSlot,
24
27
  updateMainThreadRefAttrSlot as setMTRefSlotImpl,
28
+ updateSpreadAttrSlot,
25
29
  } from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
26
30
 
27
31
  import { retainMainThreadBackgroundFunctionCtx } from '../../../../src/element-template/runtime/template/main-thread-background-function.js';
@@ -659,4 +663,188 @@ describe('main-thread dynamic attr state', () => {
659
663
  globalThis.lynxWorkletImpl = previousWorkletImpl;
660
664
  }
661
665
  });
666
+
667
+ it('retains spread MTEvent, Gesture, and callback MTRef once before Native and keeps state intact on Native rejection', () => {
668
+ const { addRef, restore } = installJsFunctionLifecycleManager();
669
+ const { updateWorkletRef, restore: restoreRefs } = installRefRuntime();
670
+ const eventCtx = { _execId: 201, _wkltId: 'spread-tap' };
671
+ const gestureCb = { _execId: 202, _wkltId: 'spread-pan' };
672
+ const refCb = { _execId: 203, _wkltId: 'spread-ref-cb' };
673
+ const initialObjectRef = { _wvid: 55 };
674
+ __etAttrPlanMap._et_spread_retain = [0, adaptSpreadAttrSlot];
675
+
676
+ try {
677
+ const initialSlot = {
678
+ id: 'card',
679
+ 'main-thread:bindtap': { type: 'worklet', value: eventCtx },
680
+ 'main-thread:gesture': {
681
+ type: 'gesture',
682
+ value: [{
683
+ id: 1,
684
+ type: 0,
685
+ config: {},
686
+ callbacks: [{ name: 'onUpdate', callback: gestureCb }],
687
+ relationMap: { waitFor: [], simultaneous: [], continueWith: [] },
688
+ }],
689
+ },
690
+ 'main-thread:ref': { type: 'main-thread-ref', value: initialObjectRef },
691
+ };
692
+
693
+ const nativeSlots = prepareMainThreadDynamicAttrSlotsForNative('_et_spread_retain', [initialSlot]);
694
+ expect(nativeSlots?.[0]).toEqual({
695
+ id: 'card',
696
+ 'main-thread:bindtap': { type: 'worklet', value: eventCtx },
697
+ 'main-thread:gesture': initialSlot['main-thread:gesture'],
698
+ 'has-react-ref': true,
699
+ flatten: false,
700
+ });
701
+ expect(addRef.mock.calls).toEqual([
702
+ [201, eventCtx],
703
+ [202, gestureCb],
704
+ ]);
705
+
706
+ initializeMainThreadDynamicAttrSlots(17, '_et_spread_retain', [initialSlot]);
707
+ expect(isSpreadDynamicAttrSlot(17, 0)).toBe(true);
708
+ expect(addRef).toHaveBeenCalledTimes(2);
709
+ attachAndComplete([{ uid: 17, ref: TEST_NATIVE_REF }]);
710
+ expect(updateWorkletRef).toHaveBeenCalledExactlyOnceWith(initialObjectRef, TEST_ELEMENT_REF);
711
+ updateWorkletRef.mockClear();
712
+
713
+ // prepareSpreadAttrSlotForNative retains callbacks and strips main-thread:ref without mutating attached ref state.
714
+ const unappliedNextSlot = {
715
+ id: 'card-rejected',
716
+ 'main-thread:ref': { type: 'main-thread-ref', value: refCb },
717
+ };
718
+ expect(prepareSpreadAttrSlotForNative(null)).toBeNull();
719
+ const preparedForNative = prepareSpreadAttrSlotForNative(unappliedNextSlot);
720
+ expect(preparedForNative).toEqual({
721
+ id: 'card-rejected',
722
+ 'has-react-ref': true,
723
+ flatten: false,
724
+ });
725
+ expect(addRef).toHaveBeenLastCalledWith(203, refCb);
726
+ expect(updateWorkletRef).not.toHaveBeenCalled();
727
+
728
+ // If hydration completes without a setAttribute op for this spread slot (because BTS omitted
729
+ // 'main-thread:ref' and remaining keys matched Native), the unhydrated first-screen ref is cleaned up.
730
+ applyPendingMainThreadRefAttachments(true);
731
+ expect(updateWorkletRef).toHaveBeenCalledExactlyOnceWith(initialObjectRef, null);
732
+ updateWorkletRef.mockClear();
733
+
734
+ deleteMainThreadDynamicAttrStateForSubtree([17]);
735
+ expect(updateWorkletRef).not.toHaveBeenCalled();
736
+ } finally {
737
+ restoreRefs();
738
+ restore();
739
+ }
740
+ });
741
+
742
+ it('reconciles multi-slot MTRef overrides, key-deletion fallbacks, and JSON.parse sibling updates without disturbing distinct elements', () => {
743
+ const previousRunWorklet = globalThis.runWorklet;
744
+ const { updateWorkletRef, restore } = installRefRuntime();
745
+ const sharedElement = { id: 'shared-el' } as unknown as ElementRef;
746
+ const distinctElement = { id: 'distinct-el' } as unknown as ElementRef;
747
+ vi.mocked(__GetElementByAttrSlot).mockImplementation((_handle, slot) =>
748
+ slot === 3 ? distinctElement : sharedElement
749
+ );
750
+
751
+ const directRef = { _wvid: 1 };
752
+ const distinctRef = { _wvid: 99 };
753
+ const spread1Cleanup = vi.fn();
754
+ const spread1Cb = { _wkltId: 'spread1-cb', _execId: 301 };
755
+ const spread2Ref = { _wvid: 2 };
756
+ globalThis.runWorklet = vi.fn(() => spread1Cleanup);
757
+
758
+ __etAttrPlanMap._et_multi_mtref = [
759
+ 0,
760
+ adaptMTRefAttrSlot,
761
+ 1,
762
+ adaptSpreadAttrSlot,
763
+ 2,
764
+ adaptSpreadAttrSlot,
765
+ 3,
766
+ adaptSpreadAttrSlot,
767
+ ];
768
+
769
+ try {
770
+ initializeMainThreadDynamicAttrSlots(21, '_et_multi_mtref', [
771
+ { type: 'main-thread-ref', value: directRef },
772
+ { id: 's1', 'main-thread:ref': { type: 'main-thread-ref', value: spread1Cb } },
773
+ { id: 's2', 'main-thread:ref': { type: 'main-thread-ref', value: spread2Ref } },
774
+ { id: 's3', 'main-thread:ref': { type: 'main-thread-ref', value: distinctRef } },
775
+ ]);
776
+ attachAndComplete([{ uid: 21, ref: TEST_NATIVE_REF }]);
777
+
778
+ // Slot 2 overrides slots 0 & 1 on sharedElement; slot 3 attaches independently on distinctElement.
779
+ expect(updateWorkletRef.mock.calls).toEqual([
780
+ [spread2Ref, sharedElement],
781
+ [distinctRef, distinctElement],
782
+ ]);
783
+ expect(globalThis.runWorklet).not.toHaveBeenCalled();
784
+ updateWorkletRef.mockClear();
785
+
786
+ // Explicit null in slot 2 ({ 'main-thread:ref': undefined }) detaches sharedElement without falling back.
787
+ updateSpreadAttrSlot(21, 2, { id: 's2', 'main-thread:ref': null }, TEST_NATIVE_REF);
788
+ completeRefAttachments();
789
+ expect(updateWorkletRef.mock.calls).toEqual([[spread2Ref, null]]);
790
+ expect(globalThis.runWorklet).not.toHaveBeenCalled();
791
+ updateWorkletRef.mockClear();
792
+
793
+ // Omitting 'main-thread:ref' from slot 2 falls back to slot 1's callback ref.
794
+ updateSpreadAttrSlot(21, 2, { id: 's2-no-ref' }, TEST_NATIVE_REF);
795
+ completeRefAttachments();
796
+ expect(globalThis.runWorklet).toHaveBeenCalledExactlyOnceWith(spread1Cb, [{ elementRefptr: sharedElement }]);
797
+ expect(spread1Cleanup).not.toHaveBeenCalled();
798
+ vi.mocked(globalThis.runWorklet).mockClear();
799
+
800
+ // Sibling update in slot 1 arriving as a fresh JSON.parse clone with the same _execId does NOT remount spread1Cb.
801
+ const jsonParsedSameCbClone = JSON.parse(JSON.stringify({
802
+ id: 's1-updated',
803
+ 'main-thread:ref': { type: 'main-thread-ref', value: { _wkltId: 'spread1-cb', _execId: 301 } },
804
+ }));
805
+ updateSpreadAttrSlot(21, 1, jsonParsedSameCbClone, TEST_NATIVE_REF);
806
+ completeRefAttachments();
807
+ expect(spread1Cleanup).not.toHaveBeenCalled();
808
+ expect(globalThis.runWorklet).not.toHaveBeenCalled();
809
+
810
+ // Clearing slot 1 entirely runs spread1Cleanup synchronously and falls back to direct slot 0!
811
+ updateSpreadAttrSlot(21, 1, null, TEST_NATIVE_REF);
812
+ expect(spread1Cleanup).toHaveBeenCalledTimes(1);
813
+ completeRefAttachments();
814
+ expect(updateWorkletRef.mock.calls).toEqual([[directRef, sharedElement]]);
815
+ updateWorkletRef.mockClear();
816
+
817
+ // Subtree deletion cleans both sharedElement (directRef) and distinctElement (distinctRef).
818
+ deleteMainThreadDynamicAttrStateForSubtree([21]);
819
+ expect(updateWorkletRef.mock.calls).toEqual(expect.arrayContaining([
820
+ [directRef, null],
821
+ [distinctRef, null],
822
+ ]));
823
+ expect(updateWorkletRef).toHaveBeenCalledTimes(2);
824
+ expect(spread1Cleanup).toHaveBeenCalledTimes(1);
825
+
826
+ // Masking an attached callback ref via a later spread's explicit null cleans it once
827
+ // and does not re-run cleanup on subtree deletion.
828
+ const maskedCleanup = vi.fn();
829
+ const maskedCb = { _wkltId: 'masked-cb', _execId: 302 };
830
+ globalThis.runWorklet = vi.fn(() => maskedCleanup);
831
+ __etAttrPlanMap._et_masked_destroy = [0, adaptSpreadAttrSlot, 1, adaptSpreadAttrSlot];
832
+ initializeMainThreadDynamicAttrSlots(77, '_et_masked_destroy', [
833
+ { 'main-thread:ref': { type: 'main-thread-ref', value: maskedCb } },
834
+ {},
835
+ ]);
836
+ attachAndComplete([{ uid: 77, ref: TEST_NATIVE_REF }]);
837
+ expect(maskedCleanup).toHaveBeenCalledTimes(0);
838
+
839
+ updateSpreadAttrSlot(77, 1, { 'main-thread:ref': null }, TEST_NATIVE_REF);
840
+ completeRefAttachments();
841
+ expect(maskedCleanup).toHaveBeenCalledTimes(1);
842
+
843
+ deleteMainThreadDynamicAttrStateForSubtree([77]);
844
+ expect(maskedCleanup).toHaveBeenCalledTimes(1);
845
+ } finally {
846
+ globalThis.runWorklet = previousRunWorklet;
847
+ restore();
848
+ }
849
+ });
662
850
  });
@@ -15,13 +15,13 @@ beforeAll(() => {
15
15
 
16
16
  beforeEach(() => {
17
17
  globalEnvManager.resetEnv();
18
- globalThis.__GLOBAL_PROPS_MODE__ = 'event';
18
+ lynx.__runtime_configs__ = { globalPropsMode: 'event' };
19
19
  });
20
20
 
21
21
  afterEach(() => {
22
22
  elementTree.clear();
23
23
  vi.restoreAllMocks();
24
- globalThis.__GLOBAL_PROPS_MODE__ = 'reactive';
24
+ lynx.__runtime_configs__ = { globalPropsMode: 'reactive' };
25
25
  });
26
26
 
27
27
  async function renderWithCurrentPreact(element, root) {
@@ -24,7 +24,7 @@ beforeEach(() => {
24
24
  afterEach(() => {
25
25
  elementTree.clear();
26
26
  vi.restoreAllMocks();
27
- globalThis.__GLOBAL_PROPS_MODE__ = 'reactive';
27
+ lynx.__runtime_configs__ = { globalPropsMode: 'reactive' };
28
28
  });
29
29
 
30
30
  async function renderWithCurrentPreact(element, root) {
@@ -308,8 +308,8 @@ describe('updateGlobalProps', () => {
308
308
  }
309
309
  });
310
310
 
311
- it('should not trigger re-render when __GLOBAL_PROPS_MODE__ is event', async () => {
312
- globalThis.__GLOBAL_PROPS_MODE__ = 'event';
311
+ it('should not trigger re-render when globalPropsMode is event', async () => {
312
+ lynx.__runtime_configs__ = { globalPropsMode: 'event' };
313
313
 
314
314
  lynx.__globalProps = { theme: 'dark' };
315
315
  const Comp = () => {
@@ -7,6 +7,7 @@ import { render } from 'preact';
7
7
  import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
8
8
 
9
9
  import { RefProxy, runDelayedUiOps, shouldDelayUiOps } from '../../src/snapshot/lifecycle/ref/delay';
10
+ import { destroyBackground } from '../../src/snapshot/lifecycle/destroy';
10
11
 
11
12
  import { Component, createRef, useState } from '../../src/index';
12
13
  import { clearCommitTaskId, replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit';
@@ -2365,4 +2366,33 @@ describe('runDelayedUiOps helper', () => {
2365
2366
  runDelayedUiOps();
2366
2367
  expect(shouldDelayUiOps.value).toBe(false);
2367
2368
  });
2369
+
2370
+ it('should clear pre-hydration delayed UI operations on destroyBackground even when unmount cleanup throws', () => {
2371
+ shouldDelayUiOps.value = true;
2372
+ const invoke = vi.fn();
2373
+ vi.spyOn(lynx, 'createSelectorQuery').mockReturnValue({
2374
+ selectUniqueID: () => ({ invoke }),
2375
+ });
2376
+
2377
+ const proxy = new RefProxy([1, 0]);
2378
+ proxy.invoke({ method: 'focus' }).exec();
2379
+ expect(invoke).not.toHaveBeenCalled();
2380
+
2381
+ class ThrowingUnmount extends Component {
2382
+ componentWillUnmount() {
2383
+ throw new Error('unmount boom');
2384
+ }
2385
+ render() {
2386
+ return <view />;
2387
+ }
2388
+ }
2389
+
2390
+ globalEnvManager.switchToBackground();
2391
+ render(<ThrowingUnmount />, __root);
2392
+
2393
+ expect(() => destroyBackground()).toThrow('unmount boom');
2394
+ runDelayedUiOps();
2395
+
2396
+ expect(invoke).not.toHaveBeenCalled();
2397
+ });
2368
2398
  });
@@ -26,6 +26,7 @@ export const {
26
26
  __etHost,
27
27
  __root,
28
28
  adaptEventAttrSlot,
29
+ adaptGestureAttrSlot,
29
30
  adaptMTEventAttrSlot,
30
31
  adaptMTRefAttrSlot,
31
32
  adaptRefAttrSlot,
@@ -1,6 +1,6 @@
1
1
  import { factory } from './initData.js';
2
2
  export function isGlobalPropsEventMode() {
3
- return typeof __GLOBAL_PROPS_MODE__ !== 'undefined' && __GLOBAL_PROPS_MODE__ === 'event';
3
+ return lynx.__runtime_configs__?.globalPropsMode === 'event';
4
4
  }
5
5
  export function createGlobalProps(deps) {
6
6
  return isGlobalPropsEventMode()
@@ -1 +1 @@
1
- {"version":3,"file":"globalProps.js","sourceRoot":"","sources":["../../src/core/globalProps.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAiCxC,MAAM,UAAU,sBAAsB;IACpC,OAAO,OAAO,qBAAqB,KAAK,WAAW,IAAI,qBAAqB,KAAK,OAAO,CAAC;AAC3F,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAA4B;IAE5B,OAAO,sBAAsB,EAAE;QAC7B,CAAC,CAAC,eAAe,CAAC,OAAO,CACvB,IAAI,EACJ,eAAe,EACf,sBAAsB,CACvB;QACD,CAAC,CAAC,eAAe,CAAC,yBAAyB,CAAO,IAAI,CAAC,0BAA0B,CAAC,CAAC;AACvF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,OAA4B,EAC5B,EAAE,aAAa,KAA+B,EAAE;IAEhD,IAAI,sBAAsB,EAAE,EAAE,CAAC;QAC7B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AAE,QAAQ,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,gBAAgB;QAChC,QAAQ,EAAE,GAAG,EAAE,CAAC,gBAAkC;QAClD,GAAG,EAAE,GAAG,EAAE,CAAC,sBAAoC;QAC/C,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport type { ComponentChildren, Consumer, Provider } from 'preact';\n\nimport type { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';\nimport { factory } from './initData.js';\n\ntype Getter<T> = {\n [key in keyof T]: () => T[key];\n};\n\ninterface GlobalPropsRuntimeDeps {\n createContext: typeof import('preact').createContext;\n useState: typeof import('preact/hooks').useState;\n createElement: typeof import('preact/compat').createElement;\n useLynxGlobalEventListener: typeof useLynxGlobalEventListener;\n}\n\ninterface GlobalPropsApi<Data> {\n Provider: Provider<Data>;\n Consumer: Consumer<Data>;\n use: () => Data;\n useChanged: (callback: (data: Data) => void) => void;\n}\n\n/**\n * The interface you can extends so that the `useGlobalProps` returning value can be customized\n *\n * @public\n *\n * @group Types\n */\nexport interface GlobalProps {}\n\nexport interface UpdateGlobalPropsOptions {\n forceRerender?: (() => void) | undefined;\n}\n\nexport function isGlobalPropsEventMode(): boolean {\n return typeof __GLOBAL_PROPS_MODE__ !== 'undefined' && __GLOBAL_PROPS_MODE__ === 'event';\n}\n\nexport function createGlobalProps<Data = GlobalProps>(\n deps: GlobalPropsRuntimeDeps,\n): Getter<GlobalPropsApi<Data>> {\n return isGlobalPropsEventMode()\n ? /* @__PURE__ */ factory<Data>(\n deps,\n '__globalProps',\n 'onGlobalPropsChanged',\n )\n : /* @__PURE__ */ createFallbackGlobalProps<Data>(deps.useLynxGlobalEventListener);\n}\n\nexport function updateGlobalProps(\n newData: Record<string, any>,\n { forceRerender }: UpdateGlobalPropsOptions = {},\n): void {\n if (isGlobalPropsEventMode()) {\n // COW keeps Provider / Consumer state readers aligned in event mode.\n lynx.__globalProps = Object.assign({}, lynx.__globalProps, newData);\n } else {\n Object.assign(lynx.__globalProps, newData);\n if (forceRerender) {\n void Promise.resolve().then(forceRerender);\n }\n }\n\n lynx.getApp().GlobalEventEmitter.emit('onGlobalPropsChanged', [lynx.__globalProps]);\n}\n\nfunction warnGlobalPropsMode(): void {\n if (typeof __LEPUS__ !== 'undefined' && !__LEPUS__ && typeof __DEV__ !== 'undefined' && __DEV__) {\n console.warn(\n `No need to use this API when 'globalPropsMode' is not 'event', `\n + `updates will be triggered automatically by full re-render. `\n + `Please set 'globalPropsMode' to 'event' to enable optimized updates.`,\n );\n }\n}\n\nfunction FallbackProvider({ children }: { children?: ComponentChildren | undefined }): ComponentChildren {\n warnGlobalPropsMode();\n return children;\n}\n\nfunction FallbackConsumer<Data>({ children }: { children: (data: Data) => ComponentChildren }): ComponentChildren {\n warnGlobalPropsMode();\n return children(lynx.__globalProps as Data);\n}\n\nfunction useFallbackGlobalProps<Data>(): Data {\n warnGlobalPropsMode();\n return lynx.__globalProps as Data;\n}\n\nfunction createFallbackGlobalProps<Data>(\n useListener: typeof useLynxGlobalEventListener,\n): Getter<GlobalPropsApi<Data>> {\n const useChanged = (callback: (data: Data) => void): void => {\n if (typeof __LEPUS__ === 'undefined' || !__LEPUS__) {\n useListener('onGlobalPropsChanged', callback);\n }\n };\n\n return {\n Provider: () => FallbackProvider,\n Consumer: () => FallbackConsumer as Consumer<Data>,\n use: () => useFallbackGlobalProps as () => Data,\n useChanged: () => useChanged,\n };\n}\n"]}
1
+ {"version":3,"file":"globalProps.js","sourceRoot":"","sources":["../../src/core/globalProps.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAiCxC,MAAM,UAAU,sBAAsB;IACpC,OAAO,IAAI,CAA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gBAAgB,CAAO,EAAE,QAAQ,EAAmD;IAC3F,mBAAmB,EAAE,CAAC;IACtB,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAqB,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,sBAAsB;IAC7B,mBAAmB,EAAE,CAAC;IACtB,OAAO,IAAI,CAAC,aAAqB,CAAC;AACpC,CAAC;AAED,SAAS,yBAAyB,CAChC,WAA8C;IAE9C,MAAM,UAAU,GAAG,CAAC,QAA8B,EAAQ,EAAE;QAC1D,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,EAAE,CAAC;YACnD,WAAW,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,gBAAgB;QAChC,QAAQ,EAAE,GAAG,EAAE,CAAC,gBAAkC;QAClD,GAAG,EAAE,GAAG,EAAE,CAAC,sBAAoC;QAC/C,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport type { ComponentChildren, Consumer, Provider } from 'preact';\n\nimport type { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';\nimport { factory } from './initData.js';\n\ntype Getter<T> = {\n [key in keyof T]: () => T[key];\n};\n\ninterface GlobalPropsRuntimeDeps {\n createContext: typeof import('preact').createContext;\n useState: typeof import('preact/hooks').useState;\n createElement: typeof import('preact/compat').createElement;\n useLynxGlobalEventListener: typeof useLynxGlobalEventListener;\n}\n\ninterface GlobalPropsApi<Data> {\n Provider: Provider<Data>;\n Consumer: Consumer<Data>;\n use: () => Data;\n useChanged: (callback: (data: Data) => void) => void;\n}\n\n/**\n * The interface you can extends so that the `useGlobalProps` returning value can be customized\n *\n * @public\n *\n * @group Types\n */\nexport interface GlobalProps {}\n\nexport interface UpdateGlobalPropsOptions {\n forceRerender?: (() => void) | undefined;\n}\n\nexport function isGlobalPropsEventMode(): boolean {\n return lynx.__runtime_configs__?.globalPropsMode === 'event';\n}\n\nexport function createGlobalProps<Data = GlobalProps>(\n deps: GlobalPropsRuntimeDeps,\n): Getter<GlobalPropsApi<Data>> {\n return isGlobalPropsEventMode()\n ? /* @__PURE__ */ factory<Data>(\n deps,\n '__globalProps',\n 'onGlobalPropsChanged',\n )\n : /* @__PURE__ */ createFallbackGlobalProps<Data>(deps.useLynxGlobalEventListener);\n}\n\nexport function updateGlobalProps(\n newData: Record<string, any>,\n { forceRerender }: UpdateGlobalPropsOptions = {},\n): void {\n if (isGlobalPropsEventMode()) {\n // COW keeps Provider / Consumer state readers aligned in event mode.\n lynx.__globalProps = Object.assign({}, lynx.__globalProps, newData);\n } else {\n Object.assign(lynx.__globalProps, newData);\n if (forceRerender) {\n void Promise.resolve().then(forceRerender);\n }\n }\n\n lynx.getApp().GlobalEventEmitter.emit('onGlobalPropsChanged', [lynx.__globalProps]);\n}\n\nfunction warnGlobalPropsMode(): void {\n if (typeof __LEPUS__ !== 'undefined' && !__LEPUS__ && typeof __DEV__ !== 'undefined' && __DEV__) {\n console.warn(\n `No need to use this API when 'globalPropsMode' is not 'event', `\n + `updates will be triggered automatically by full re-render. `\n + `Please set 'globalPropsMode' to 'event' to enable optimized updates.`,\n );\n }\n}\n\nfunction FallbackProvider({ children }: { children?: ComponentChildren | undefined }): ComponentChildren {\n warnGlobalPropsMode();\n return children;\n}\n\nfunction FallbackConsumer<Data>({ children }: { children: (data: Data) => ComponentChildren }): ComponentChildren {\n warnGlobalPropsMode();\n return children(lynx.__globalProps as Data);\n}\n\nfunction useFallbackGlobalProps<Data>(): Data {\n warnGlobalPropsMode();\n return lynx.__globalProps as Data;\n}\n\nfunction createFallbackGlobalProps<Data>(\n useListener: typeof useLynxGlobalEventListener,\n): Getter<GlobalPropsApi<Data>> {\n const useChanged = (callback: (data: Data) => void): void => {\n if (typeof __LEPUS__ === 'undefined' || !__LEPUS__) {\n useListener('onGlobalPropsChanged', callback);\n }\n };\n\n return {\n Provider: () => FallbackProvider,\n Consumer: () => FallbackConsumer as Consumer<Data>,\n use: () => useFallbackGlobalProps as () => Data,\n useChanged: () => useChanged,\n };\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { getSpreadRefFromValue, queueRefAttrUpdate } from '../prop-adapters/ref.js';
5
5
  import { ElementTemplateUpdateOps } from '../protocol/opcodes.js';
6
- import { __etAttrPlanMap, adaptRefAttrSlot, adaptSpreadAttrSlot, getMainThreadDynamicAttrSlotKinds, } from '../runtime/template/attr-slot-plan.js';
6
+ import { __etAttrPlanMap, adaptRefAttrSlot, adaptSpreadAttrSlot, adaptTypedSpreadAttrSlot, getMainThreadDynamicAttrSlotKinds, } from '../runtime/template/attr-slot-plan.js';
7
7
  function normalizeAttributeSlots(rawSlots) {
8
8
  let normalizedSlots;
9
9
  for (let slotIndex = 0; slotIndex < rawSlots.length; slotIndex += 1) {
@@ -24,7 +24,7 @@ function queuePlannedRefAttributeSlotUpdates(instance, attrPlan, previousRawSlot
24
24
  queueRefAttrUpdate(previousRawSlots?.[attrSlotIndex], nextRawSlots?.[attrSlotIndex], instance, attrSlotIndex);
25
25
  continue;
26
26
  }
27
- if (adapter === adaptSpreadAttrSlot) {
27
+ if (adapter === adaptSpreadAttrSlot || adapter === adaptTypedSpreadAttrSlot) {
28
28
  const previousSpreadRef = getSpreadRefFromValue(previousRawSlots?.[attrSlotIndex]);
29
29
  const nextSpreadRef = getSpreadRefFromValue(nextRawSlots?.[attrSlotIndex]);
30
30
  if (previousSpreadRef === undefined && nextSpreadRef === undefined) {
@@ -68,6 +68,9 @@ export function queueRefAttributeSlotUpdates(templateKey, instance, previousRawS
68
68
  }
69
69
  export function getAttributeSlotUpdateOp(templateType, attrSlotIndex) {
70
70
  const kind = getMainThreadDynamicAttrSlotKinds(templateType)?.get(attrSlotIndex);
71
+ if (kind === 'gesture') {
72
+ return ElementTemplateUpdateOps.setGesture;
73
+ }
71
74
  if (kind === 'mt-event') {
72
75
  return ElementTemplateUpdateOps.setMainThreadEvent;
73
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"attr-slots.js","sourceRoot":"","sources":["../../../src/element-template/background/attr-slots.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,iCAAiC,GAClC,MAAM,uCAAuC,CAAC;AAS/C,SAAS,uBAAuB,CAAC,QAA4B;IAC3D,IAAI,eAAgD,CAAC;IACrD,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,EAAE,CAAC;QACpE,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,SAAS;QACX,CAAC;QACD,eAAe,KAAK,QAAQ,CAAC,KAAK,EAAyB,CAAC;QAC5D,eAAe,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;IACpC,CAAC;IACD,OAAO,eAAe,IAAI,QAA+B,CAAC;AAC5D,CAAC;AAED,SAAS,mCAAmC,CAC1C,QAAyC,EACzC,QAA6C,EAC7C,gBAAqC,EACrC,YAAiC;IAEjC,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,EAAE,CAAC;QACpE,MAAM,aAAa,GAAG,QAAQ,CAAC,SAAS,CAAW,CAAC;QACpD,MAAM,OAAO,GAAG,QAAQ,CAAC,S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nD,CAAC;IACD,OAAO,wBAAwB,CAAC,YAAY,CAAC;AAC/C,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { getSpreadRefFromValue, queueRefAttrUpdate } from '../prop-adapters/ref.js';\nimport { ElementTemplateUpdateOps } from '../protocol/opcodes.js';\nimport type { ElementTemplateUpdateOp } from '../protocol/opcodes.js';\nimport type { SerializableValue } from '../protocol/types.js';\nimport {\n __etAttrPlanMap,\n adaptRefAttrSlot,\n adaptSpreadAttrSlot,\n getMainThreadDynamicAttrSlotKinds,\n} from '../runtime/template/attr-slot-plan.js';\nimport type { EtAttrAdapter, EtAttrAdapterContext, EtAttrPlan } from '../runtime/template/attr-slot-plan.js';\n\nexport interface PrepareAttributeSlotsOptions {\n previousPreparedSlots?: readonly unknown[];\n previousRawSlots?: readonly unknown[];\n attributePlan?: EtAttrPlan | undefined;\n}\n\nfunction normalizeAttributeSlots(rawSlots: readonly unknown[]): SerializableValue[] {\n let normalizedSlots: SerializableValue[] | undefined;\n for (let slotIndex = 0; slotIndex < rawSlots.length; slotIndex += 1) {\n const rawSlot = rawSlots[slotIndex];\n if (rawSlot !== undefined) {\n continue;\n }\n normalizedSlots ??= rawSlots.slice() as SerializableValue[];\n normalizedSlots[slotIndex] = null;\n }\n return normalizedSlots ?? rawSlots as SerializableValue[];\n}\n\nfunction queuePlannedRefAttributeSlotUpdates(\n instance: { readonly instanceId: number },\n attrPlan: readonly (number | EtAttrAdapter)[],\n previousRawSlots?: readonly unknown[],\n nextRawSlots?: readonly unknown[],\n): void {\n for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {\n const attrSlotIndex = attrPlan[planIndex] as number;\n const adapter = attrPlan[planIndex + 1] as EtAttrAdapter;\n\n if (adapter === adaptRefAttrSlot) {\n queueRefAttrUpdate(\n previousRawSlots?.[attrSlotIndex],\n nextRawSlots?.[attrSlotIndex],\n instance,\n attrSlotIndex,\n );\n continue;\n }\n\n if (adapter === adaptSpreadAttrSlot) {\n const previousSpreadRef = getSpreadRefFromValue(previousRawSlots?.[attrSlotIndex]);\n const nextSpreadRef = getSpreadRefFromValue(nextRawSlots?.[attrSlotIndex]);\n if (previousSpreadRef === undefined && nextSpreadRef === undefined) {\n continue;\n }\n queueRefAttrUpdate(\n previousSpreadRef,\n nextSpreadRef ?? null,\n instance,\n attrSlotIndex,\n );\n }\n }\n}\n\nexport function prepareAttributeSlots(\n templateKey: string,\n handleId: number,\n rawSlots: readonly unknown[],\n options?: PrepareAttributeSlotsOptions,\n): SerializableValue[] {\n const attrPlan = options?.attributePlan ?? __etAttrPlanMap[templateKey];\n if (!attrPlan || attrPlan.length === 0) {\n return normalizeAttributeSlots(rawSlots);\n }\n\n const normalizedSlots = normalizeAttributeSlots(rawSlots);\n const preparedSlots = normalizedSlots === rawSlots\n ? rawSlots.slice() as SerializableValue[]\n : normalizedSlots;\n const previousPreparedSlots = options?.previousPreparedSlots;\n const previousRawSlots = options?.previousRawSlots;\n const adapterContext: EtAttrAdapterContext | undefined = previousPreparedSlots && previousRawSlots\n ? {\n previousPreparedSlots,\n previousRawSlots,\n }\n : undefined;\n for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {\n const attrSlotIndex = attrPlan[planIndex] as number;\n const adapter = attrPlan[planIndex + 1] as EtAttrAdapter;\n const rawValue = rawSlots[attrSlotIndex];\n preparedSlots[attrSlotIndex] = adapter(handleId, attrSlotIndex, rawValue, adapterContext);\n }\n\n return preparedSlots;\n}\n\nexport function queueRefAttributeSlotUpdates(\n templateKey: string,\n instance: { readonly instanceId: number },\n previousRawSlots?: readonly unknown[],\n nextRawSlots?: readonly unknown[],\n attributePlan?: EtAttrPlan,\n): void {\n const attrPlan = attributePlan ?? __etAttrPlanMap[templateKey];\n if (!attrPlan || attrPlan.length === 0) {\n return;\n }\n\n queuePlannedRefAttributeSlotUpdates(instance, attrPlan, previousRawSlots, nextRawSlots);\n}\n\nexport function getAttributeSlotUpdateOp(\n templateType: string,\n attrSlotIndex: number,\n): ElementTemplateUpdateOp {\n const kind = getMainThreadDynamicAttrSlotKinds(templateType)?.get(attrSlotIndex);\n if (kind === 'mt-event') {\n return ElementTemplateUpdateOps.setMainThreadEvent;\n }\n if (kind === 'mt-ref') {\n return ElementTemplateUpdateOps.setMainThreadRef;\n }\n return ElementTemplateUpdateOps.setAttribute;\n}\n"]}
1
+ {"version":3,"file":"attr-slots.js","sourceRoot":"","sources":["../../../src/element-template/background/attr-slots.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,iCAAiC,GAClC,MAAM,uCAAuC,CAAC;AAS/C,SAAS,uBAAuB,CAAC,QAA4B;IAC3D,IAAI,eAAgD,CAAC;IACrD,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,EAAE,CAAC;QACpE,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,SAAS;QACX,CAAC;QACD,eAAe,KAAK,QAAQ,CAAC,KAAK,EAAyB,CAAC;QAC5D,eAAe,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;IACpC,CAAC;IACD,OAAO,eAAe,IAAI,QAA+B,CAAC;AAC5D,CAAC;AAED,SAAS,mCAAmC,CAC1C,QAAyC,EACzC,QAA6C,EAC7C,gBAAqC,EACrC,YAAiC;IAEjC,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC,MAAM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K,SAAS,EAAE,CAAC;QACvB,OAAO,wBAAwB,CAAC,UAAU,CAAC;IAC7C,CAAC;IACD,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,OAAO,wBAAwB,CAAC,kBAAkB,CAAC;IACrD,CAAC;IACD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,OAAO,wBAAwB,CAAC,gBAAgB,CAAC;IACnD,CAAC;IACD,OAAO,wBAAwB,CAAC,YAAY,CAAC;AAC/C,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { getSpreadRefFromValue, queueRefAttrUpdate } from '../prop-adapters/ref.js';\nimport { ElementTemplateUpdateOps } from '../protocol/opcodes.js';\nimport type { ElementTemplateUpdateOp } from '../protocol/opcodes.js';\nimport type { SerializableValue } from '../protocol/types.js';\nimport {\n __etAttrPlanMap,\n adaptRefAttrSlot,\n adaptSpreadAttrSlot,\n adaptTypedSpreadAttrSlot,\n getMainThreadDynamicAttrSlotKinds,\n} from '../runtime/template/attr-slot-plan.js';\nimport type { EtAttrAdapter, EtAttrAdapterContext, EtAttrPlan } from '../runtime/template/attr-slot-plan.js';\n\nexport interface PrepareAttributeSlotsOptions {\n previousPreparedSlots?: readonly unknown[];\n previousRawSlots?: readonly unknown[];\n attributePlan?: EtAttrPlan | undefined;\n}\n\nfunction normalizeAttributeSlots(rawSlots: readonly unknown[]): SerializableValue[] {\n let normalizedSlots: SerializableValue[] | undefined;\n for (let slotIndex = 0; slotIndex < rawSlots.length; slotIndex += 1) {\n const rawSlot = rawSlots[slotIndex];\n if (rawSlot !== undefined) {\n continue;\n }\n normalizedSlots ??= rawSlots.slice() as SerializableValue[];\n normalizedSlots[slotIndex] = null;\n }\n return normalizedSlots ?? rawSlots as SerializableValue[];\n}\n\nfunction queuePlannedRefAttributeSlotUpdates(\n instance: { readonly instanceId: number },\n attrPlan: readonly (number | EtAttrAdapter)[],\n previousRawSlots?: readonly unknown[],\n nextRawSlots?: readonly unknown[],\n): void {\n for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {\n const attrSlotIndex = attrPlan[planIndex] as number;\n const adapter = attrPlan[planIndex + 1] as EtAttrAdapter;\n\n if (adapter === adaptRefAttrSlot) {\n queueRefAttrUpdate(\n previousRawSlots?.[attrSlotIndex],\n nextRawSlots?.[attrSlotIndex],\n instance,\n attrSlotIndex,\n );\n continue;\n }\n\n if (adapter === adaptSpreadAttrSlot || adapter === adaptTypedSpreadAttrSlot) {\n const previousSpreadRef = getSpreadRefFromValue(previousRawSlots?.[attrSlotIndex]);\n const nextSpreadRef = getSpreadRefFromValue(nextRawSlots?.[attrSlotIndex]);\n if (previousSpreadRef === undefined && nextSpreadRef === undefined) {\n continue;\n }\n queueRefAttrUpdate(\n previousSpreadRef,\n nextSpreadRef ?? null,\n instance,\n attrSlotIndex,\n );\n }\n }\n}\n\nexport function prepareAttributeSlots(\n templateKey: string,\n handleId: number,\n rawSlots: readonly unknown[],\n options?: PrepareAttributeSlotsOptions,\n): SerializableValue[] {\n const attrPlan = options?.attributePlan ?? __etAttrPlanMap[templateKey];\n if (!attrPlan || attrPlan.length === 0) {\n return normalizeAttributeSlots(rawSlots);\n }\n\n const normalizedSlots = normalizeAttributeSlots(rawSlots);\n const preparedSlots = normalizedSlots === rawSlots\n ? rawSlots.slice() as SerializableValue[]\n : normalizedSlots;\n const previousPreparedSlots = options?.previousPreparedSlots;\n const previousRawSlots = options?.previousRawSlots;\n const adapterContext: EtAttrAdapterContext | undefined = previousPreparedSlots && previousRawSlots\n ? {\n previousPreparedSlots,\n previousRawSlots,\n }\n : undefined;\n for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {\n const attrSlotIndex = attrPlan[planIndex] as number;\n const adapter = attrPlan[planIndex + 1] as EtAttrAdapter;\n const rawValue = rawSlots[attrSlotIndex];\n preparedSlots[attrSlotIndex] = adapter(handleId, attrSlotIndex, rawValue, adapterContext);\n }\n\n return preparedSlots;\n}\n\nexport function queueRefAttributeSlotUpdates(\n templateKey: string,\n instance: { readonly instanceId: number },\n previousRawSlots?: readonly unknown[],\n nextRawSlots?: readonly unknown[],\n attributePlan?: EtAttrPlan,\n): void {\n const attrPlan = attributePlan ?? __etAttrPlanMap[templateKey];\n if (!attrPlan || attrPlan.length === 0) {\n return;\n }\n\n queuePlannedRefAttributeSlotUpdates(instance, attrPlan, previousRawSlots, nextRawSlots);\n}\n\nexport function getAttributeSlotUpdateOp(\n templateType: string,\n attrSlotIndex: number,\n): ElementTemplateUpdateOp {\n const kind = getMainThreadDynamicAttrSlotKinds(templateType)?.get(attrSlotIndex);\n if (kind === 'gesture') {\n return ElementTemplateUpdateOps.setGesture;\n }\n if (kind === 'mt-event') {\n return ElementTemplateUpdateOps.setMainThreadEvent;\n }\n if (kind === 'mt-ref') {\n return ElementTemplateUpdateOps.setMainThreadRef;\n }\n return ElementTemplateUpdateOps.setAttribute;\n}\n"]}