@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.
- package/CHANGELOG.md +10 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/globalProps.test.ts +27 -6
- package/runtime/__test__/element-template/fixtures/gesture/direct/index.tsx +33 -0
- package/runtime/__test__/element-template/fixtures/spread/mts/index.tsx +197 -0
- package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +89 -3
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +8 -3
- package/runtime/__test__/element-template/native/reload.test.ts +87 -0
- package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +5 -5
- package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +1 -1
- package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +70 -0
- package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +3 -4
- package/runtime/__test__/element-template/runtime/background/reload.test.ts +74 -0
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +15 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/gesture-compiled.test.ts +200 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +420 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +527 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +185 -6
- package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +21 -1
- package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +188 -0
- package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.event.test.jsx +2 -2
- package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +3 -3
- package/runtime/__test__/snapshot/ref.test.jsx +30 -0
- package/runtime/lazy/element-template-internal.js +1 -0
- package/runtime/lib/core/globalProps.js +1 -1
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/element-template/background/attr-slots.js +5 -2
- package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js +16 -11
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +23 -0
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/debug/alog.d.ts +1 -1
- package/runtime/lib/element-template/debug/alog.js +4 -1
- package/runtime/lib/element-template/debug/alog.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +1 -1
- package/runtime/lib/element-template/internal.js +1 -1
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/native/callDestroyLifetimeFun.js +6 -1
- package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +1 -1
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.js +1 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js +33 -9
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/gesture.d.ts +23 -0
- package/runtime/lib/element-template/prop-adapters/gesture.js +97 -0
- package/runtime/lib/element-template/prop-adapters/gesture.js.map +1 -0
- package/runtime/lib/element-template/prop-adapters/spread.d.ts +6 -1
- package/runtime/lib/element-template/prop-adapters/spread.js +72 -2
- package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
- package/runtime/lib/element-template/protocol/opcodes.d.ts +1 -0
- package/runtime/lib/element-template/protocol/opcodes.js +1 -0
- package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +7 -1
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +27 -2
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +4 -2
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +7 -2
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +368 -58
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +2 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js +10 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/typed-attributes.js +3 -3
- package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/destroy.js +23 -17
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +5 -0
- package/runtime/lib/snapshot/lifecycle/ref/delay.js +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/src/core/globalProps.ts +1 -1
- package/runtime/src/element-template/background/attr-slots.ts +5 -1
- package/runtime/src/element-template/background/destroy.ts +16 -13
- package/runtime/src/element-template/background/hydrate.ts +23 -0
- package/runtime/src/element-template/debug/alog.ts +5 -2
- package/runtime/src/element-template/internal.ts +1 -0
- package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +5 -1
- package/runtime/src/element-template/native/patch-listener.ts +1 -1
- package/runtime/src/element-template/native/reload-background.ts +1 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +30 -10
- package/runtime/src/element-template/prop-adapters/gesture.ts +144 -0
- package/runtime/src/element-template/prop-adapters/spread.ts +110 -2
- package/runtime/src/element-template/protocol/opcodes.ts +1 -0
- package/runtime/src/element-template/protocol/types.ts +8 -0
- package/runtime/src/element-template/runtime/patch.ts +33 -0
- package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +31 -4
- package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +441 -65
- package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +12 -2
- package/runtime/src/element-template/runtime/template/typed-attributes.ts +3 -3
- package/runtime/src/snapshot/lifecycle/destroy.ts +23 -18
- package/runtime/src/snapshot/lifecycle/ref/delay.ts +1 -1
- package/runtime/types/types.d.ts +2 -1
- package/testing-library/.turbo/turbo-build.log +7 -7
- package/transform/.turbo/turbo-build$colon$wasm.log +205 -91
- package/transform/__test__/fixture.spec.js +11 -11
- package/transform/__test__/main-thread-object-compat.spec.js +111 -0
- package/transform/crates/swc_plugin_element_template/lib.rs +11 -0
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +113 -0
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +7 -9
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +7 -7
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -7
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +8 -8
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +8 -8
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +5 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +5 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +1 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +160 -133
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +180 -293
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Copyright 2026 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 path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
installElementTemplateCommitHook,
|
|
12
|
+
resetElementTemplateCommitState,
|
|
13
|
+
} from '../../../../src/element-template/background/commit-hook.js';
|
|
14
|
+
import {
|
|
15
|
+
installElementTemplateHydrationListener,
|
|
16
|
+
resetElementTemplateHydrationListener,
|
|
17
|
+
} from '../../../../src/element-template/background/hydration-listener.js';
|
|
18
|
+
import {
|
|
19
|
+
installElementTemplatePatchListener,
|
|
20
|
+
resetElementTemplatePatchListener,
|
|
21
|
+
} from '../../../../src/element-template/native/patch-listener.js';
|
|
22
|
+
import type { GestureSlotValue } from '../../../../src/element-template/prop-adapters/gesture.js';
|
|
23
|
+
import {
|
|
24
|
+
installElementTemplateRefInitValueListener,
|
|
25
|
+
resetElementTemplateRefInitValueListener,
|
|
26
|
+
} from '../../../../src/element-template/main-thread-ref-init-value.js';
|
|
27
|
+
import { ElementTemplateLifecycleConstant } from '../../../../src/element-template/protocol/lifecycle-constant.js';
|
|
28
|
+
import { ElementTemplateUpdateOps } from '../../../../src/element-template/protocol/opcodes.js';
|
|
29
|
+
import type { ElementTemplateUpdateCommitContext } from '../../../../src/element-template/protocol/types.js';
|
|
30
|
+
import { parseElementTemplateUpdateEventPayload } from '../../../../src/element-template/protocol/update-event.js';
|
|
31
|
+
import { clearEtAttrPlanMap } from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
|
|
32
|
+
import {
|
|
33
|
+
resetElementTemplateBackgroundFunctionRuntime,
|
|
34
|
+
resetElementTemplateMainThreadBackgroundFunctionRuntime,
|
|
35
|
+
} from '../../../../src/element-template/runtime/template/main-thread-background-function.js';
|
|
36
|
+
import { clearMainThreadDynamicAttrState } from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
|
|
37
|
+
import { initWorklet } from '../../../../src/worklet-runtime/workletRuntime.js';
|
|
38
|
+
import type { Worklet } from '../../../../src/worklet-runtime/bindings/types.js';
|
|
39
|
+
import { loadCompiledFixturePair } from '../../test-utils/debug/compiledFixtureModule.js';
|
|
40
|
+
import {
|
|
41
|
+
renderCompiledFixtureOnBackground,
|
|
42
|
+
renderCompiledFixtureOnMainThread,
|
|
43
|
+
} from '../../test-utils/debug/compiledThreadRunner.js';
|
|
44
|
+
import { ElementTemplateEnvManager } from '../../test-utils/debug/envManager.js';
|
|
45
|
+
import { lastMock } from '../../test-utils/mock/mockNativePapi.js';
|
|
46
|
+
|
|
47
|
+
const fixturePath = path.resolve(
|
|
48
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
49
|
+
'../../fixtures/gesture/direct/index.tsx',
|
|
50
|
+
);
|
|
51
|
+
interface GestureProps {
|
|
52
|
+
label?: string;
|
|
53
|
+
enabled?: boolean;
|
|
54
|
+
show?: boolean;
|
|
55
|
+
onReport?: (label: string, count: number) => string;
|
|
56
|
+
}
|
|
57
|
+
interface FixtureModule {
|
|
58
|
+
App: (props: GestureProps) => JSX.Element;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function firstScreenGesture(): GestureSlotValue {
|
|
62
|
+
for (const entry of lastMock!.nativeLog) {
|
|
63
|
+
if (Array.isArray(entry) && entry[0] === '__CreateElementTemplate' && Array.isArray(entry[3])) {
|
|
64
|
+
const gesture = entry[3].find((value: unknown) =>
|
|
65
|
+
value != null && typeof value === 'object' && (value as GestureSlotValue).type === 'gesture'
|
|
66
|
+
);
|
|
67
|
+
if (gesture) return gesture as GestureSlotValue;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw new Error('No compiled first-screen Gesture slot was created.');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function latestNativeGesture(): GestureSlotValue | null {
|
|
74
|
+
const entry = lastMock!.nativeLog.findLast(value =>
|
|
75
|
+
Array.isArray(value) && value[0] === '__SetAttributeOfElementTemplate'
|
|
76
|
+
) as unknown[] | undefined;
|
|
77
|
+
if (!entry) throw new Error('No Gesture attribute update reached Native.');
|
|
78
|
+
return entry[3] as GestureSlotValue | null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function callback(value: GestureSlotValue): Worklet {
|
|
82
|
+
expect(value.type).toBe('gesture');
|
|
83
|
+
const item = value.value[0]!.callbacks.find(item => item.name === 'onUpdate');
|
|
84
|
+
expect(item).toBeDefined();
|
|
85
|
+
return item!.callback as Worklet;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
describe('Compiled ET direct Gesture worklet lifecycle', () => {
|
|
89
|
+
const env = new ElementTemplateEnvManager();
|
|
90
|
+
let sdk: string | undefined;
|
|
91
|
+
let updates: ElementTemplateUpdateCommitContext[];
|
|
92
|
+
const onUpdate = (event: { data: unknown }) => updates.push(parseElementTemplateUpdateEventPayload(event.data));
|
|
93
|
+
|
|
94
|
+
beforeEach(() => {
|
|
95
|
+
vi.clearAllMocks();
|
|
96
|
+
sdk = SystemInfo.lynxSdkVersion;
|
|
97
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
98
|
+
updates = [];
|
|
99
|
+
resetElementTemplateCommitState();
|
|
100
|
+
clearEtAttrPlanMap();
|
|
101
|
+
clearMainThreadDynamicAttrState();
|
|
102
|
+
resetElementTemplateBackgroundFunctionRuntime();
|
|
103
|
+
env.resetEnv('background');
|
|
104
|
+
env.setUseElementTemplate(true);
|
|
105
|
+
installElementTemplateCommitHook();
|
|
106
|
+
installElementTemplateHydrationListener();
|
|
107
|
+
env.switchToMainThread();
|
|
108
|
+
initWorklet();
|
|
109
|
+
installElementTemplateRefInitValueListener();
|
|
110
|
+
installElementTemplatePatchListener();
|
|
111
|
+
lynx.getJSContext().addEventListener(ElementTemplateLifecycleConstant.update, onUpdate);
|
|
112
|
+
env.switchToBackground();
|
|
113
|
+
vi.stubGlobal('__LoadLepusChunk', vi.fn(() => true));
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
afterEach(() => {
|
|
117
|
+
env.switchToMainThread();
|
|
118
|
+
lynx.getJSContext().removeEventListener(ElementTemplateLifecycleConstant.update, onUpdate);
|
|
119
|
+
resetElementTemplatePatchListener();
|
|
120
|
+
resetElementTemplateRefInitValueListener();
|
|
121
|
+
clearMainThreadDynamicAttrState();
|
|
122
|
+
resetElementTemplateMainThreadBackgroundFunctionRuntime();
|
|
123
|
+
env.switchToBackground();
|
|
124
|
+
resetElementTemplateHydrationListener();
|
|
125
|
+
resetElementTemplateBackgroundFunctionRuntime();
|
|
126
|
+
env.setUseElementTemplate(false);
|
|
127
|
+
SystemInfo.lynxSdkVersion = sdk;
|
|
128
|
+
delete globalThis.lynxWorkletImpl;
|
|
129
|
+
// @ts-expect-error Restore globals installed by the real worklet runtime.
|
|
130
|
+
delete globalThis.registerWorklet;
|
|
131
|
+
// @ts-expect-error Restore globals installed by the real worklet runtime.
|
|
132
|
+
delete globalThis.registerWorkletInternal;
|
|
133
|
+
// @ts-expect-error Restore globals installed by the real worklet runtime.
|
|
134
|
+
delete globalThis.runWorklet;
|
|
135
|
+
vi.unstubAllGlobals();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('replays pre-hydrate background calls and preserves MainThreadRef mutations in the hydrated callback', async () => {
|
|
139
|
+
const { backgroundModule, mainModule } = await loadCompiledFixturePair<FixtureModule>(fixturePath, {
|
|
140
|
+
enableWorkletTransform: true,
|
|
141
|
+
envManager: env,
|
|
142
|
+
});
|
|
143
|
+
const onReport = vi.fn((label: string, count: number) => `${label}:${count}`);
|
|
144
|
+
renderCompiledFixtureOnBackground(backgroundModule, env, { label: 'first', onReport });
|
|
145
|
+
renderCompiledFixtureOnMainThread(mainModule, env, { label: 'first', onReport });
|
|
146
|
+
const first = callback(firstScreenGesture());
|
|
147
|
+
let delayed: Promise<unknown>;
|
|
148
|
+
env.switchToMainThread(() => {
|
|
149
|
+
delayed = globalThis.runWorklet(first, []) as Promise<unknown>;
|
|
150
|
+
expect(onReport).not.toHaveBeenCalled();
|
|
151
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(1);
|
|
152
|
+
});
|
|
153
|
+
expect(updates.at(-1)?.isHydration).toBe(true);
|
|
154
|
+
const hydrated = callback(latestNativeGesture()!);
|
|
155
|
+
expect(hydrated).not.toBe(first);
|
|
156
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
|
|
157
|
+
env.switchToBackground();
|
|
158
|
+
expect(onReport).toHaveBeenCalledWith('first', 1);
|
|
159
|
+
env.switchToMainThread();
|
|
160
|
+
await expect(delayed!).resolves.toBe('first:1');
|
|
161
|
+
const next = globalThis.runWorklet(hydrated, []) as Promise<unknown>;
|
|
162
|
+
env.switchToBackground();
|
|
163
|
+
expect(onReport).toHaveBeenLastCalledWith('first', 2);
|
|
164
|
+
env.switchToMainThread();
|
|
165
|
+
await expect(next).resolves.toBe('first:2');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('uses the latest closure and propagates clearing a Gesture to Native', async () => {
|
|
169
|
+
const { backgroundModule, mainModule } = await loadCompiledFixturePair<FixtureModule>(fixturePath, {
|
|
170
|
+
enableWorkletTransform: true,
|
|
171
|
+
envManager: env,
|
|
172
|
+
});
|
|
173
|
+
const firstReport = vi.fn((label: string) => label);
|
|
174
|
+
const nextReport = vi.fn((label: string) => label);
|
|
175
|
+
const host = renderCompiledFixtureOnBackground(backgroundModule, env, { label: 'first', onReport: firstReport });
|
|
176
|
+
renderCompiledFixtureOnMainThread(mainModule, env, { label: 'first', onReport: firstReport });
|
|
177
|
+
env.switchToMainThread();
|
|
178
|
+
env.switchToBackground();
|
|
179
|
+
updates = [];
|
|
180
|
+
renderCompiledFixtureOnBackground(backgroundModule, env, { label: 'second', onReport: nextReport });
|
|
181
|
+
env.switchToMainThread();
|
|
182
|
+
expect(updates.at(-1)?.ops).toEqual([
|
|
183
|
+
ElementTemplateUpdateOps.setGesture,
|
|
184
|
+
host!.instanceId,
|
|
185
|
+
0,
|
|
186
|
+
expect.objectContaining({ type: 'gesture' }),
|
|
187
|
+
]);
|
|
188
|
+
const result = globalThis.runWorklet(callback(latestNativeGesture()!), []) as Promise<unknown>;
|
|
189
|
+
env.switchToBackground();
|
|
190
|
+
expect(nextReport).toHaveBeenCalledWith('second', 1);
|
|
191
|
+
expect(firstReport).not.toHaveBeenCalled();
|
|
192
|
+
env.switchToMainThread();
|
|
193
|
+
await expect(result).resolves.toBe('second');
|
|
194
|
+
env.switchToBackground();
|
|
195
|
+
renderCompiledFixtureOnBackground(backgroundModule, env, { enabled: false, onReport: nextReport });
|
|
196
|
+
env.switchToMainThread();
|
|
197
|
+
expect(latestNativeGesture()).toBeNull();
|
|
198
|
+
expect(updates.at(-1)?.ops).toEqual([ElementTemplateUpdateOps.setGesture, host!.instanceId, 0, null]);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
// Copyright 2026 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 { afterEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { prepareAttributeSlots } from '../../../../src/element-template/background/attr-slots.js';
|
|
8
|
+
import type { GestureSlotValue } from '../../../../src/element-template/prop-adapters/gesture.js';
|
|
9
|
+
import {
|
|
10
|
+
hydrateGestureCallbacks,
|
|
11
|
+
prepareGestureForNative,
|
|
12
|
+
} from '../../../../src/element-template/prop-adapters/gesture.js';
|
|
13
|
+
import {
|
|
14
|
+
__etAttrPlanMap,
|
|
15
|
+
adaptGestureAttrSlot,
|
|
16
|
+
clearEtAttrPlanMap,
|
|
17
|
+
} from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
|
|
18
|
+
import type { MTEventCtx } from '../../../../src/element-template/runtime/template/main-thread-event-ctx.js';
|
|
19
|
+
import { resetElementTemplateBackgroundFunctionRuntime } from '../../../../src/element-template/runtime/template/main-thread-background-function.js';
|
|
20
|
+
import {
|
|
21
|
+
clearMainThreadDynamicAttrState,
|
|
22
|
+
deleteMainThreadDynamicAttrStateForSubtree,
|
|
23
|
+
initializeMainThreadDynamicAttrSlots,
|
|
24
|
+
prepareMainThreadDynamicAttrSlotsForNative,
|
|
25
|
+
updateGestureAttrSlot,
|
|
26
|
+
} from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
|
|
27
|
+
import { createElementTemplateWithReservedHandle } from '../../../../src/element-template/runtime/template/handle.js';
|
|
28
|
+
import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
|
|
29
|
+
import { applyElementTemplateUpdateCommands } from '../../../../src/element-template/runtime/patch.js';
|
|
30
|
+
import { ElementTemplateUpdateOps } from '../../../../src/element-template/protocol/opcodes.js';
|
|
31
|
+
import { JsFunctionLifecycleManager } from '../../../../src/worklet-runtime/jsFunctionLifecycle.js';
|
|
32
|
+
|
|
33
|
+
function gesture(id: number, type: number, callbacks: Record<string, MTEventCtx> = { onBegin: { _wkltId: 'begin' } }) {
|
|
34
|
+
return { __isGesture: true, id, type, config: { enabled: true }, callbacks };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function slot(...gestures: ReturnType<typeof gesture>[]) {
|
|
38
|
+
return prepareGestureForNative({ __isGesture: true, type: -1, gestures })!;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function installHydrationObserver() {
|
|
42
|
+
const previous = globalThis.lynxWorkletImpl;
|
|
43
|
+
const hydrate = vi.fn();
|
|
44
|
+
globalThis.lynxWorkletImpl = { ...previous, _hydrateCtx: hydrate };
|
|
45
|
+
return { hydrate, restore: () => globalThis.lynxWorkletImpl = previous };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
globalThis.__JS__ = true;
|
|
50
|
+
globalThis.__LEPUS__ = false;
|
|
51
|
+
globalThis.__BACKGROUND__ = true;
|
|
52
|
+
globalThis.__MAIN_THREAD__ = false;
|
|
53
|
+
clearMainThreadDynamicAttrState();
|
|
54
|
+
clearEtAttrPlanMap();
|
|
55
|
+
resetElementTemplateBackgroundFunctionRuntime();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('ET direct Gesture preparation', () => {
|
|
59
|
+
it('flattens nested composition once per detector and preserves its relationships', () => {
|
|
60
|
+
const pan = {
|
|
61
|
+
...gesture(10, 0),
|
|
62
|
+
waitFor: [{ id: 11 }],
|
|
63
|
+
simultaneousWith: [{ id: 12 }],
|
|
64
|
+
continueWith: [{ id: 13 }],
|
|
65
|
+
};
|
|
66
|
+
const tap = gesture(11, 1);
|
|
67
|
+
const prepared = prepareGestureForNative({
|
|
68
|
+
__isGesture: true,
|
|
69
|
+
type: -1,
|
|
70
|
+
gestures: [pan, { type: -1, gestures: [tap, pan] }],
|
|
71
|
+
})!;
|
|
72
|
+
|
|
73
|
+
expect(prepared.type).toBe('gesture');
|
|
74
|
+
expect(prepared.value.map(item => item.id)).toEqual([10, 11]);
|
|
75
|
+
expect(prepared.value[0]).toMatchObject({
|
|
76
|
+
type: 0,
|
|
77
|
+
config: { enabled: true },
|
|
78
|
+
relationMap: { waitFor: [11], simultaneous: [12], continueWith: [13] },
|
|
79
|
+
callbacks: [{ name: 'onBegin', callback: { _wkltId: 'begin' } }],
|
|
80
|
+
});
|
|
81
|
+
expect(prepared.value[0]!.config).not.toBe(pan.config);
|
|
82
|
+
expect(prepared.value[0]!.callbacks[0]!.callback).not.toBe(pan.callbacks.onBegin);
|
|
83
|
+
expect(pan.callbacks.onBegin).toEqual({ _wkltId: 'begin' });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it.each([null, undefined, false])('clears an absent Gesture (%s)', value => {
|
|
87
|
+
expect(adaptGestureAttrSlot(-1, 0, value)).toBeNull();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it.each([true, 'pan', {}, { __isGesture: false }])('rejects an invalid public Gesture value (%j)', value => {
|
|
91
|
+
expect(() => prepareGestureForNative(value)).toThrow(
|
|
92
|
+
'ElementTemplate main-thread:gesture expects a Gesture object.',
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('omits unset callbacks from a serialized Gesture descriptor', () => {
|
|
97
|
+
const prepared = prepareGestureForNative({
|
|
98
|
+
__isSerialized: true,
|
|
99
|
+
id: 1,
|
|
100
|
+
type: 0,
|
|
101
|
+
callbacks: { onBegin: null, onEnd: undefined },
|
|
102
|
+
});
|
|
103
|
+
expect(prepared).toMatchObject({ value: [{ config: {}, callbacks: [] }] });
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('rejects ordinary callbacks before passing an unusable detector to Native', () => {
|
|
107
|
+
expect(() =>
|
|
108
|
+
prepareGestureForNative({
|
|
109
|
+
...gesture(1, 0),
|
|
110
|
+
callbacks: { onBegin: () => {} },
|
|
111
|
+
})
|
|
112
|
+
).toThrow('Gesture callback \'onBegin\' must be a main-thread function.');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('reuses delivered callback contexts during repeated preparation while observing mutable configuration', () => {
|
|
116
|
+
const previousFlags = {
|
|
117
|
+
js: globalThis.__JS__,
|
|
118
|
+
lepus: globalThis.__LEPUS__,
|
|
119
|
+
background: globalThis.__BACKGROUND__,
|
|
120
|
+
main: globalThis.__MAIN_THREAD__,
|
|
121
|
+
};
|
|
122
|
+
const previousSdk = SystemInfo.lynxSdkVersion;
|
|
123
|
+
globalThis.__JS__ = true;
|
|
124
|
+
globalThis.__LEPUS__ = false;
|
|
125
|
+
globalThis.__BACKGROUND__ = true;
|
|
126
|
+
globalThis.__MAIN_THREAD__ = false;
|
|
127
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
128
|
+
__etAttrPlanMap.gesture = [0, adaptGestureAttrSlot];
|
|
129
|
+
const raw = { ...gesture(1, 0), waitFor: [{ id: 2 }] };
|
|
130
|
+
const rawSlots = [raw];
|
|
131
|
+
try {
|
|
132
|
+
const initial = prepareAttributeSlots('gesture', 17, rawSlots);
|
|
133
|
+
const first = (initial[0] as unknown as GestureSlotValue).value[0]!;
|
|
134
|
+
const firstCallback = first.callbacks[0]!.callback;
|
|
135
|
+
expect(firstCallback._execId).toEqual(expect.any(Number));
|
|
136
|
+
const hydration = prepareAttributeSlots('gesture', 17, rawSlots, {
|
|
137
|
+
previousPreparedSlots: initial,
|
|
138
|
+
previousRawSlots: rawSlots,
|
|
139
|
+
});
|
|
140
|
+
expect((hydration[0] as unknown as GestureSlotValue).value[0]!.callbacks[0]!.callback).toBe(firstCallback);
|
|
141
|
+
raw.config.enabled = false;
|
|
142
|
+
raw.waitFor.push({ id: 3 });
|
|
143
|
+
const create = prepareAttributeSlots('gesture', 17, rawSlots, {
|
|
144
|
+
previousPreparedSlots: hydration,
|
|
145
|
+
previousRawSlots: rawSlots,
|
|
146
|
+
});
|
|
147
|
+
const created = (create[0] as unknown as GestureSlotValue).value[0]!;
|
|
148
|
+
expect(created.callbacks[0]!.callback).toBe(firstCallback);
|
|
149
|
+
expect(created.callbacks[0]!.callback._execId).toBe(firstCallback._execId);
|
|
150
|
+
expect(created.config.enabled).toBe(false);
|
|
151
|
+
expect(created.relationMap.waitFor).toEqual([2, 3]);
|
|
152
|
+
expect(first.config.enabled).toBe(true);
|
|
153
|
+
expect(first.relationMap.waitFor).toEqual([2]);
|
|
154
|
+
raw.callbacks.onBegin = { _wkltId: 'replacement' };
|
|
155
|
+
const changed = prepareAttributeSlots('gesture', 17, rawSlots, {
|
|
156
|
+
previousPreparedSlots: create,
|
|
157
|
+
previousRawSlots: rawSlots,
|
|
158
|
+
});
|
|
159
|
+
const changedCallback = (changed[0] as unknown as GestureSlotValue).value[0]!.callbacks[0]!.callback;
|
|
160
|
+
expect(changedCallback).not.toBe(firstCallback);
|
|
161
|
+
expect(changedCallback._execId).not.toBe(firstCallback._execId);
|
|
162
|
+
expect(changedCallback._wkltId).toBe('replacement');
|
|
163
|
+
expect(raw.callbacks.onBegin).not.toHaveProperty('_execId');
|
|
164
|
+
} finally {
|
|
165
|
+
globalThis.__JS__ = previousFlags.js;
|
|
166
|
+
globalThis.__LEPUS__ = previousFlags.lepus;
|
|
167
|
+
globalThis.__BACKGROUND__ = previousFlags.background;
|
|
168
|
+
globalThis.__MAIN_THREAD__ = previousFlags.main;
|
|
169
|
+
SystemInfo.lynxSdkVersion = previousSdk;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('registers each prepared callback without adding exec IDs to the authored Gesture', () => {
|
|
174
|
+
const previousJs = globalThis.__JS__;
|
|
175
|
+
const previousLepus = globalThis.__LEPUS__;
|
|
176
|
+
const previousBackground = globalThis.__BACKGROUND__;
|
|
177
|
+
const previousMain = globalThis.__MAIN_THREAD__;
|
|
178
|
+
const previousSdk = SystemInfo.lynxSdkVersion;
|
|
179
|
+
globalThis.__JS__ = true;
|
|
180
|
+
globalThis.__LEPUS__ = false;
|
|
181
|
+
globalThis.__BACKGROUND__ = true;
|
|
182
|
+
globalThis.__MAIN_THREAD__ = false;
|
|
183
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
184
|
+
const raw = gesture(1, 0, { onBegin: { _wkltId: 'begin' } });
|
|
185
|
+
try {
|
|
186
|
+
const prepared = prepareGestureForNative(raw)!;
|
|
187
|
+
expect(prepared.value[0]!.callbacks[0]!.callback._execId).toEqual(expect.any(Number));
|
|
188
|
+
expect(raw.callbacks.onBegin).not.toHaveProperty('_execId');
|
|
189
|
+
} finally {
|
|
190
|
+
globalThis.__JS__ = previousJs;
|
|
191
|
+
globalThis.__LEPUS__ = previousLepus;
|
|
192
|
+
globalThis.__BACKGROUND__ = previousBackground;
|
|
193
|
+
globalThis.__MAIN_THREAD__ = previousMain;
|
|
194
|
+
SystemInfo.lynxSdkVersion = previousSdk;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('ET Gesture callback handoff and lifecycle', () => {
|
|
200
|
+
it.each(
|
|
201
|
+
[
|
|
202
|
+
['reserved', 'success'],
|
|
203
|
+
['reserved', 'null'],
|
|
204
|
+
['reserved', 'throw'],
|
|
205
|
+
['patch', 'success'],
|
|
206
|
+
['patch', 'null'],
|
|
207
|
+
['patch', 'throw'],
|
|
208
|
+
] as const,
|
|
209
|
+
)('tracks %s create callbacks before Native %s without committing failed state', (mode, outcome) => {
|
|
210
|
+
const previous = globalThis.lynxWorkletImpl;
|
|
211
|
+
const manager = new JsFunctionLifecycleManager();
|
|
212
|
+
const hydrate = vi.fn();
|
|
213
|
+
globalThis.lynxWorkletImpl = { ...previous, _jsFunctionLifecycleManager: manager, _hydrateCtx: hydrate };
|
|
214
|
+
const first = slot(gesture(1, 0, { onBegin: { _wkltId: 'begin' }, onEnd: { _wkltId: 'end' } }));
|
|
215
|
+
first.value[0]!.callbacks[0]!.callback._execId = 41;
|
|
216
|
+
first.value[0]!.callbacks[1]!.callback._execId = 42;
|
|
217
|
+
const retain = vi.spyOn(manager, 'addRef');
|
|
218
|
+
const nativeRef = {} as ElementTemplateHandle;
|
|
219
|
+
const error = new Error('create failed');
|
|
220
|
+
__etAttrPlanMap['__Card__:_et_gesture_reject'] = [0, adaptGestureAttrSlot];
|
|
221
|
+
const create = vi.spyOn(globalThis, '__CreateElementTemplate').mockImplementationOnce((_key, _url, slots) => {
|
|
222
|
+
expect(slots![0]).toBe(first);
|
|
223
|
+
expect(retain).toHaveBeenCalledWith(41, first.value[0]!.callbacks[0]!.callback);
|
|
224
|
+
expect(retain).toHaveBeenCalledWith(42, first.value[0]!.callbacks[1]!.callback);
|
|
225
|
+
expect(elementTemplateRegistry.has(17)).toBe(false);
|
|
226
|
+
if (outcome === 'throw') throw error;
|
|
227
|
+
return outcome === 'null' ? null : nativeRef;
|
|
228
|
+
});
|
|
229
|
+
try {
|
|
230
|
+
const apply = () =>
|
|
231
|
+
mode === 'reserved'
|
|
232
|
+
? createElementTemplateWithReservedHandle(17, '_et_gesture_reject', null, [first], null)
|
|
233
|
+
: applyElementTemplateUpdateCommands([
|
|
234
|
+
ElementTemplateUpdateOps.createTemplate,
|
|
235
|
+
17,
|
|
236
|
+
'_et_gesture_reject',
|
|
237
|
+
null,
|
|
238
|
+
[first],
|
|
239
|
+
null,
|
|
240
|
+
]);
|
|
241
|
+
if (outcome === 'throw') expect(apply).toThrow(error);
|
|
242
|
+
else apply();
|
|
243
|
+
expect(retain).toHaveBeenCalledTimes(2);
|
|
244
|
+
expect(elementTemplateRegistry.has(17)).toBe(outcome === 'success');
|
|
245
|
+
const probe = slot(gesture(2, 0));
|
|
246
|
+
updateGestureAttrSlot(17, 0, probe, true);
|
|
247
|
+
if (outcome === 'success') {
|
|
248
|
+
expect(hydrate).toHaveBeenCalledExactlyOnceWith(
|
|
249
|
+
probe.value[0]!.callbacks[0]!.callback,
|
|
250
|
+
first.value[0]!.callbacks[0]!.callback,
|
|
251
|
+
);
|
|
252
|
+
} else expect(hydrate).not.toHaveBeenCalled();
|
|
253
|
+
} finally {
|
|
254
|
+
create.mockRestore();
|
|
255
|
+
elementTemplateRegistry.delete(17);
|
|
256
|
+
manager.dispose();
|
|
257
|
+
globalThis.lynxWorkletImpl = previous;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it.each([false, true])('tracks setter callbacks before Native and preserves failed state (throws=%s)', throws => {
|
|
262
|
+
const previous = globalThis.lynxWorkletImpl;
|
|
263
|
+
const manager = new JsFunctionLifecycleManager();
|
|
264
|
+
const hydrate = vi.fn();
|
|
265
|
+
globalThis.lynxWorkletImpl = { ...previous, _jsFunctionLifecycleManager: manager, _hydrateCtx: hydrate };
|
|
266
|
+
const first = slot(gesture(1, 0));
|
|
267
|
+
const next = slot(gesture(2, 0));
|
|
268
|
+
const probe = slot(gesture(3, 0));
|
|
269
|
+
next.value[0]!.callbacks[0]!.callback._execId = 51;
|
|
270
|
+
updateGestureAttrSlot(17, 0, first);
|
|
271
|
+
elementTemplateRegistry.set(17, {} as ElementTemplateHandle);
|
|
272
|
+
const retain = vi.spyOn(manager, 'addRef');
|
|
273
|
+
const error = new Error('setter failed');
|
|
274
|
+
const setter = vi.spyOn(globalThis, '__SetAttributeOfElementTemplate').mockImplementationOnce(
|
|
275
|
+
(_handle, _slot, value) => {
|
|
276
|
+
expect(value).toBe(next);
|
|
277
|
+
expect(retain).toHaveBeenCalledExactlyOnceWith(51, next.value[0]!.callbacks[0]!.callback);
|
|
278
|
+
expect(hydrate).not.toHaveBeenCalled();
|
|
279
|
+
if (throws) throw error;
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
try {
|
|
283
|
+
const apply = () => applyElementTemplateUpdateCommands([ElementTemplateUpdateOps.setGesture, 17, 0, next], true);
|
|
284
|
+
if (throws) expect(apply).toThrow(error);
|
|
285
|
+
else apply();
|
|
286
|
+
expect(retain).toHaveBeenCalledExactlyOnceWith(51, next.value[0]!.callbacks[0]!.callback);
|
|
287
|
+
if (throws) expect(hydrate).not.toHaveBeenCalled();
|
|
288
|
+
else {expect(hydrate).toHaveBeenCalledExactlyOnceWith(
|
|
289
|
+
next.value[0]!.callbacks[0]!.callback,
|
|
290
|
+
first.value[0]!.callbacks[0]!.callback,
|
|
291
|
+
);}
|
|
292
|
+
hydrate.mockClear();
|
|
293
|
+
updateGestureAttrSlot(17, 0, probe, true);
|
|
294
|
+
expect(hydrate).toHaveBeenCalledExactlyOnceWith(
|
|
295
|
+
probe.value[0]!.callbacks[0]!.callback,
|
|
296
|
+
(throws ? first : next).value[0]!.callbacks[0]!.callback,
|
|
297
|
+
);
|
|
298
|
+
} finally {
|
|
299
|
+
setter.mockRestore();
|
|
300
|
+
elementTemplateRegistry.delete(17);
|
|
301
|
+
manager.dispose();
|
|
302
|
+
globalThis.lynxWorkletImpl = previous;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('does not mistake colliding IDs allocated on different threads for callback identity', () => {
|
|
307
|
+
const previous = slot(gesture(1, 0), gesture(2, 1));
|
|
308
|
+
const next = slot(gesture(2, 0), gesture(3, 1));
|
|
309
|
+
const { hydrate, restore } = installHydrationObserver();
|
|
310
|
+
try {
|
|
311
|
+
hydrateGestureCallbacks(next, previous);
|
|
312
|
+
expect(hydrate.mock.calls).toEqual([
|
|
313
|
+
[next.value[0]!.callbacks[0]!.callback, previous.value[0]!.callbacks[0]!.callback],
|
|
314
|
+
[next.value[1]!.callbacks[0]!.callback, previous.value[1]!.callbacks[0]!.callback],
|
|
315
|
+
]);
|
|
316
|
+
} finally {
|
|
317
|
+
restore();
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('pairs reordered gesture types and callback names without moving state between detector kinds', () => {
|
|
322
|
+
const previous = slot(gesture(1, 0), gesture(2, 1));
|
|
323
|
+
const next = slot(gesture(1, 1), gesture(2, 0));
|
|
324
|
+
const { hydrate, restore } = installHydrationObserver();
|
|
325
|
+
try {
|
|
326
|
+
hydrateGestureCallbacks(next, previous);
|
|
327
|
+
expect(hydrate.mock.calls).toEqual([
|
|
328
|
+
[next.value[0]!.callbacks[0]!.callback, previous.value[1]!.callbacks[0]!.callback],
|
|
329
|
+
[next.value[1]!.callbacks[0]!.callback, previous.value[0]!.callbacks[0]!.callback],
|
|
330
|
+
]);
|
|
331
|
+
} finally {
|
|
332
|
+
restore();
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('hands off repeated detector types in declaration order without reusing an earlier callback', () => {
|
|
337
|
+
const previous = slot(
|
|
338
|
+
gesture(1, 0, { onBegin: { _wkltId: 'first-pan' } }),
|
|
339
|
+
gesture(2, 0, { onBegin: { _wkltId: 'second-pan' } }),
|
|
340
|
+
);
|
|
341
|
+
const next = slot(
|
|
342
|
+
gesture(3, 0, { onBegin: { _wkltId: 'first-pan' } }),
|
|
343
|
+
gesture(4, 0, { onBegin: { _wkltId: 'second-pan' } }),
|
|
344
|
+
);
|
|
345
|
+
const { hydrate, restore } = installHydrationObserver();
|
|
346
|
+
try {
|
|
347
|
+
hydrateGestureCallbacks(next, previous);
|
|
348
|
+
expect(hydrate.mock.calls).toEqual([
|
|
349
|
+
[next.value[0]!.callbacks[0]!.callback, previous.value[0]!.callbacks[0]!.callback],
|
|
350
|
+
[next.value[1]!.callbacks[0]!.callback, previous.value[1]!.callbacks[0]!.callback],
|
|
351
|
+
]);
|
|
352
|
+
} finally {
|
|
353
|
+
restore();
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('hands off callbacks by name and leaves new callbacks and new detector kinds unhydrated', () => {
|
|
358
|
+
const previous = slot(gesture(1, 0, { onBegin: { _wkltId: 'begin' }, onEnd: { _wkltId: 'end' } }));
|
|
359
|
+
const next = slot(
|
|
360
|
+
gesture(2, 0, { onEnd: { _wkltId: 'end' }, onBegin: { _wkltId: 'begin' }, onUpdate: { _wkltId: 'update' } }),
|
|
361
|
+
gesture(3, 1),
|
|
362
|
+
);
|
|
363
|
+
const { hydrate, restore } = installHydrationObserver();
|
|
364
|
+
try {
|
|
365
|
+
hydrateGestureCallbacks(next, previous);
|
|
366
|
+
expect(hydrate.mock.calls).toEqual([
|
|
367
|
+
[next.value[0]!.callbacks[0]!.callback, previous.value[0]!.callbacks[1]!.callback],
|
|
368
|
+
[next.value[0]!.callbacks[1]!.callback, previous.value[0]!.callbacks[0]!.callback],
|
|
369
|
+
]);
|
|
370
|
+
} finally {
|
|
371
|
+
restore();
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('retains all initial native callback contexts and hydrates only the current slot value', () => {
|
|
376
|
+
const previousRuntime = globalThis.lynxWorkletImpl;
|
|
377
|
+
const addRef = vi.fn();
|
|
378
|
+
const hydrate = vi.fn();
|
|
379
|
+
globalThis.lynxWorkletImpl = {
|
|
380
|
+
...previousRuntime,
|
|
381
|
+
_hydrateCtx: hydrate,
|
|
382
|
+
_jsFunctionLifecycleManager: { addRef },
|
|
383
|
+
} as typeof globalThis.lynxWorkletImpl;
|
|
384
|
+
const first = slot(gesture(1, 0, { onBegin: { _wkltId: 'begin' }, onEnd: { _wkltId: 'end' } }));
|
|
385
|
+
first.value[0]!.callbacks[0]!.callback._execId = 41;
|
|
386
|
+
first.value[0]!.callbacks[1]!.callback._execId = 42;
|
|
387
|
+
const updated = slot(gesture(2, 0));
|
|
388
|
+
const hydrated = slot(gesture(3, 0));
|
|
389
|
+
__etAttrPlanMap.gesture = [0, adaptGestureAttrSlot];
|
|
390
|
+
try {
|
|
391
|
+
prepareMainThreadDynamicAttrSlotsForNative('gesture', [first]);
|
|
392
|
+
initializeMainThreadDynamicAttrSlots(17, 'gesture', [first]);
|
|
393
|
+
expect(addRef).toHaveBeenCalledWith(41, first.value[0]!.callbacks[0]!.callback);
|
|
394
|
+
expect(addRef).toHaveBeenCalledWith(42, first.value[0]!.callbacks[1]!.callback);
|
|
395
|
+
updateGestureAttrSlot(17, 0, updated);
|
|
396
|
+
expect(hydrate).not.toHaveBeenCalled();
|
|
397
|
+
updateGestureAttrSlot(17, 0, hydrated, true);
|
|
398
|
+
expect(hydrate).toHaveBeenCalledWith(
|
|
399
|
+
hydrated.value[0]!.callbacks[0]!.callback,
|
|
400
|
+
updated.value[0]!.callbacks[0]!.callback,
|
|
401
|
+
);
|
|
402
|
+
} finally {
|
|
403
|
+
globalThis.lynxWorkletImpl = previousRuntime;
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it.each(['null', 'subtree', 'runtime'] as const)('drops stale first-screen callback state after %s cleanup', mode => {
|
|
408
|
+
const { hydrate, restore } = installHydrationObserver();
|
|
409
|
+
try {
|
|
410
|
+
updateGestureAttrSlot(17, 0, slot(gesture(1, 0)));
|
|
411
|
+
if (mode === 'null') updateGestureAttrSlot(17, 0, null);
|
|
412
|
+
if (mode === 'subtree') deleteMainThreadDynamicAttrStateForSubtree([17]);
|
|
413
|
+
if (mode === 'runtime') clearMainThreadDynamicAttrState();
|
|
414
|
+
updateGestureAttrSlot(17, 0, slot(gesture(2, 0)), true);
|
|
415
|
+
expect(hydrate).not.toHaveBeenCalled();
|
|
416
|
+
} finally {
|
|
417
|
+
restore();
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
});
|