@lynx-js/react 0.129.4 → 0.129.5
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 +22 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -1
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/lynx/env.test.ts +146 -0
- package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +47 -4
- package/runtime/__test__/element-template/native/index.test.ts +9 -9
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +55 -2
- package/runtime/__test__/element-template/native/reload.test.ts +15 -5
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +1 -1
- package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +1 -1
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +33 -0
- package/runtime/__test__/element-template/vitest.config.ts +1 -1
- package/runtime/__test__/snapshot/debug/profile.test.jsx +147 -26
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +54 -0
- package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +98 -6
- package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +214 -9
- package/runtime/__test__/snapshot/lynx/suspense.test.jsx +48 -0
- package/runtime/__test__/snapshot/utils/envManager.ts +2 -0
- package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +21 -0
- package/runtime/__test__/worklet-runtime/lifecycle.test.js +297 -0
- package/runtime/__test__/worklet-runtime/profile.test.js +12 -6
- package/runtime/lazy/element-template-internal.js +1 -0
- package/runtime/lib/core/compat/componentIs.d.ts +1 -0
- package/runtime/lib/core/compat/componentIs.js +20 -0
- package/runtime/lib/core/compat/componentIs.js.map +1 -0
- package/runtime/lib/core/lynx/env.d.ts +1 -0
- package/runtime/lib/{element-template → core}/lynx/env.js +3 -2
- package/runtime/lib/core/lynx/env.js.map +1 -0
- package/runtime/lib/core/thread-function-call/main-thread.d.ts +1 -0
- package/runtime/lib/core/thread-function-call/main-thread.js +4 -1
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/element-template/background/commit-event.d.ts +6 -0
- package/runtime/lib/element-template/background/commit-event.js +36 -0
- package/runtime/lib/element-template/background/commit-event.js.map +1 -0
- package/runtime/lib/element-template/background/commit-hook.js +3 -23
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js +1 -1
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +1 -2
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js +5 -25
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.js +4 -4
- package/runtime/lib/element-template/background/main-thread-function.js.map +1 -0
- package/runtime/lib/element-template/index.d.ts +1 -1
- package/runtime/lib/element-template/index.js +1 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.js +3 -0
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/native/index.js +2 -2
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.d.ts +2 -1
- package/runtime/lib/element-template/native/mts-destroy.js +15 -4
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js +2 -2
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +4 -11
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.d.ts +1 -1
- package/runtime/lib/element-template/runtime/template/handle.js +2 -2
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.d.ts +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +7 -2
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
- package/runtime/lib/internal.js +4 -10
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js +27 -62
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.js +2 -2
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/lynx/env.js +2 -32
- package/runtime/lib/snapshot/lynx/env.js.map +1 -1
- package/runtime/lib/snapshot/transfer.d.ts +6 -0
- package/runtime/lib/snapshot/transfer.js +154 -11
- package/runtime/lib/snapshot/transfer.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/lifecycle.d.ts +19 -0
- package/runtime/lib/worklet-runtime/bindings/lifecycle.js +49 -0
- package/runtime/lib/worklet-runtime/bindings/lifecycle.js.map +1 -0
- package/runtime/lib/worklet-runtime/delayWorkletEvent.d.ts +1 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js +9 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/profile.js +1 -3
- package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
- package/runtime/src/core/compat/componentIs.ts +32 -0
- package/runtime/src/{element-template → core}/lynx/env.ts +6 -4
- package/runtime/src/core/thread-function-call/main-thread.ts +5 -1
- package/runtime/src/element-template/background/commit-event.ts +52 -0
- package/runtime/src/element-template/background/commit-hook.ts +4 -31
- package/runtime/src/element-template/background/destroy.ts +1 -1
- package/runtime/src/element-template/background/hydrate.ts +5 -3
- package/runtime/src/element-template/background/hydration-listener.ts +7 -32
- package/runtime/src/element-template/{runtime/template → background}/main-thread-function.ts +4 -7
- package/runtime/src/element-template/index.ts +1 -1
- package/runtime/src/element-template/internal.ts +4 -0
- package/runtime/src/element-template/native/index.ts +2 -2
- package/runtime/src/element-template/native/mts-destroy.ts +21 -4
- package/runtime/src/element-template/native/reload-main-thread.ts +2 -2
- package/runtime/src/element-template/runtime/patch.ts +20 -35
- package/runtime/src/element-template/runtime/template/handle.ts +2 -0
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -2
- package/runtime/src/internal.ts +4 -13
- package/runtime/src/snapshot/debug/profileHooks.ts +30 -91
- package/runtime/src/snapshot/lifecycle/reload.ts +2 -3
- package/runtime/src/snapshot/lynx/env.ts +3 -43
- package/runtime/src/snapshot/transfer.ts +169 -13
- package/runtime/src/worklet-runtime/bindings/lifecycle.ts +51 -0
- package/runtime/src/worklet-runtime/delayWorkletEvent.ts +10 -2
- package/runtime/src/worklet-runtime/utils/profile.ts +1 -3
- package/runtime/types/internal-preact.d.ts +2 -0
- package/runtime/vitest.config.ts +0 -1
- package/testing-library/.turbo/turbo-build.log +7 -7
- package/testing-library/src/__tests__/events.test.jsx +1 -1
- package/testing-library/src/fire-event.ts +1 -1
- package/transform/.turbo/turbo-build$colon$wasm.log +67 -66
- package/transform/__test__/fixture.spec.js +1 -1
- package/transform/cjs/browser.cjs +11 -0
- package/transform/crates/swc_plugin_compat/lib.rs +20 -2
- package/transform/crates/swc_plugin_compat/napi.rs +7 -0
- package/transform/crates/swc_plugin_dynamic_import/lib.rs +15 -4
- package/transform/crates/swc_plugin_element_template/attr_name.rs +0 -3
- package/transform/crates/swc_plugin_element_template/extractor.rs +0 -8
- package/transform/crates/swc_plugin_element_template/lib.rs +12 -1
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +35 -0
- package/transform/crates/swc_plugin_worklet/lib.rs +11 -7
- package/transform/dist/wasm.cjs +1 -1
- package/transform/rspack-napi/lib/index.js +1 -4
- package/transform/rspack-napi/lib/index.js.map +1 -1
- package/transform/rspack-napi/src/index.ts +1 -4
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/lib.rs +394 -27
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +413 -105
- package/transform/swc-plugin-reactlynx/src/lib.rs +99 -22
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +28 -359
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/runtime/__test__/element-template/lynx/env.test.ts +0 -242
- package/runtime/lib/element-template/lynx/env.d.ts +0 -1
- package/runtime/lib/element-template/lynx/env.js.map +0 -1
- package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +0 -1
- package/runtime/lib/snapshot/compat/componentIs.d.ts +0 -4
- package/runtime/lib/snapshot/compat/componentIs.js +0 -20
- package/runtime/lib/snapshot/compat/componentIs.js.map +0 -1
- package/runtime/src/snapshot/compat/componentIs.ts +0 -30
- /package/runtime/__test__/element-template/runtime/{template → background}/main-thread-function.test.ts +0 -0
- /package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.d.ts +0 -0
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import { JsFunctionLifecycleManager } from '../../../src/worklet-runtime/run-on-background/lifecycle.js';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
installOnMtsDestruction,
|
|
6
|
+
onMtsDestruction,
|
|
7
|
+
retireElementTemplateMainThreadForReload,
|
|
8
|
+
} from '../../../src/element-template/native/mts-destroy.js';
|
|
5
9
|
import {
|
|
6
10
|
composeElementTemplateListAttributes,
|
|
7
11
|
createElementTemplateListState,
|
|
@@ -97,18 +101,66 @@ describe('mts-destroy', () => {
|
|
|
97
101
|
}
|
|
98
102
|
});
|
|
99
103
|
|
|
100
|
-
it('
|
|
104
|
+
it('disposes callback owners without allocating a replacement manager on terminal destruction', () => {
|
|
101
105
|
const previousWorkletImpl = globalThis.lynxWorkletImpl;
|
|
102
106
|
const previous = new JsFunctionLifecycleManager();
|
|
107
|
+
const clearFirstScreenWorkletRefMap = vi.fn();
|
|
108
|
+
const clearDelayedWorklets = vi.fn();
|
|
103
109
|
const oldCtx = { _wkltId: 'tap', _execId: 3 };
|
|
104
110
|
previous.addRef(3, oldCtx);
|
|
105
111
|
globalThis.lynxWorkletImpl = {
|
|
106
112
|
...previousWorkletImpl,
|
|
107
113
|
_jsFunctionLifecycleManager: previous,
|
|
114
|
+
_refImpl: {
|
|
115
|
+
clearFirstScreenWorkletRefMap,
|
|
116
|
+
},
|
|
117
|
+
_eventDelayImpl: {
|
|
118
|
+
clearDelayedWorklets,
|
|
119
|
+
},
|
|
108
120
|
} as typeof globalThis.lynxWorkletImpl;
|
|
109
121
|
const dispatch = vi.spyOn(lynx.getJSContext(), 'dispatchEvent');
|
|
110
122
|
try {
|
|
111
123
|
onMtsDestruction();
|
|
124
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager).toBeUndefined();
|
|
125
|
+
expect(clearFirstScreenWorkletRefMap).toHaveBeenCalledTimes(1);
|
|
126
|
+
expect(clearDelayedWorklets).toHaveBeenCalledTimes(1);
|
|
127
|
+
previous.removeRef(3);
|
|
128
|
+
previous.fire();
|
|
129
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
130
|
+
} finally {
|
|
131
|
+
dispatch.mockRestore();
|
|
132
|
+
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('retires callback owners and recreates a fresh manager when retiring for entry reload', () => {
|
|
137
|
+
const g = globalThis as LynxWithNative;
|
|
138
|
+
const originalGetNative = g.lynx.getNative;
|
|
139
|
+
const removeEventListener = vi.fn();
|
|
140
|
+
g.lynx.getNative = () => ({ addEventListener: vi.fn(), removeEventListener });
|
|
141
|
+
|
|
142
|
+
const previousWorkletImpl = globalThis.lynxWorkletImpl;
|
|
143
|
+
const previous = new JsFunctionLifecycleManager();
|
|
144
|
+
const clearFirstScreenWorkletRefMap = vi.fn();
|
|
145
|
+
const clearDelayedWorklets = vi.fn();
|
|
146
|
+
const oldCtx = { _wkltId: 'tap', _execId: 3 };
|
|
147
|
+
previous.addRef(3, oldCtx);
|
|
148
|
+
globalThis.lynxWorkletImpl = {
|
|
149
|
+
...previousWorkletImpl,
|
|
150
|
+
_jsFunctionLifecycleManager: previous,
|
|
151
|
+
_refImpl: {
|
|
152
|
+
clearFirstScreenWorkletRefMap,
|
|
153
|
+
},
|
|
154
|
+
_eventDelayImpl: {
|
|
155
|
+
clearDelayedWorklets,
|
|
156
|
+
},
|
|
157
|
+
} as typeof globalThis.lynxWorkletImpl;
|
|
158
|
+
const dispatch = vi.spyOn(lynx.getJSContext(), 'dispatchEvent');
|
|
159
|
+
try {
|
|
160
|
+
retireElementTemplateMainThreadForReload();
|
|
161
|
+
expect(removeEventListener).toHaveBeenCalledWith('__DestroyLifetime', onMtsDestruction);
|
|
162
|
+
expect(clearFirstScreenWorkletRefMap).toHaveBeenCalledTimes(1);
|
|
163
|
+
expect(clearDelayedWorklets).toHaveBeenCalledTimes(1);
|
|
112
164
|
const current = globalThis.lynxWorkletImpl._jsFunctionLifecycleManager!;
|
|
113
165
|
const next = { _wkltId: 'tap', _execId: 3 };
|
|
114
166
|
current.addRef(3, next);
|
|
@@ -125,6 +177,7 @@ describe('mts-destroy', () => {
|
|
|
125
177
|
} finally {
|
|
126
178
|
dispatch.mockRestore();
|
|
127
179
|
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
180
|
+
g.lynx.getNative = originalGetNative;
|
|
128
181
|
}
|
|
129
182
|
});
|
|
130
183
|
|
|
@@ -7,7 +7,7 @@ import { installElementTemplateHydrationListener } from '../../../src/element-te
|
|
|
7
7
|
import { BackgroundPageRootInstance } from '../../../src/element-template/background/instance.js';
|
|
8
8
|
import { profileEnd, profileStart } from '../../../src/element-template/debug/profile.js';
|
|
9
9
|
import { reloadBackground } from '../../../src/element-template/native/reload-background.js';
|
|
10
|
-
import {
|
|
10
|
+
import { retireElementTemplateMainThreadForReload } from '../../../src/element-template/native/mts-destroy.js';
|
|
11
11
|
import { completeMainThreadReload, reloadMainThread } from '../../../src/element-template/native/reload-main-thread.js';
|
|
12
12
|
import { resetEventStateForRuntime } from '../../../src/element-template/prop-adapters/event.js';
|
|
13
13
|
import { destroyAllElementTemplateListStates } from '../../../src/element-template/runtime/list/list.js';
|
|
@@ -112,7 +112,7 @@ vi.mock('../../../src/element-template/background/instance.js', () => {
|
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
vi.mock('../../../src/element-template/native/mts-destroy.js', () => ({
|
|
115
|
-
|
|
115
|
+
retireElementTemplateMainThreadForReload: vi.fn(),
|
|
116
116
|
}));
|
|
117
117
|
|
|
118
118
|
vi.mock('../../../src/element-template/debug/profile.js', () => ({
|
|
@@ -328,7 +328,7 @@ describe('ElementTemplate reloadMainThread', () => {
|
|
|
328
328
|
return { pageAttributes: null, rootRefs: [rootRef], rootSubtreeHandles: [[{ uid: -1, ref: rootRef }]] };
|
|
329
329
|
});
|
|
330
330
|
lynx.__initData = { kept: 'yes', count: 1 };
|
|
331
|
-
vi.mocked(
|
|
331
|
+
vi.mocked(retireElementTemplateMainThreadForReload).mockImplementation(() => events.push('retire'));
|
|
332
332
|
vi.mocked(increaseReloadVersion).mockImplementationOnce(() => {
|
|
333
333
|
events.push('advance-version');
|
|
334
334
|
return 2;
|
|
@@ -398,8 +398,10 @@ describe('ElementTemplate reloadMainThread', () => {
|
|
|
398
398
|
expect(__SerializeElementTemplate).toHaveBeenCalledTimes(2);
|
|
399
399
|
});
|
|
400
400
|
|
|
401
|
-
it('clears delayed runOnBackground tasks during main-thread reload', () => {
|
|
401
|
+
it('clears delayed runOnBackground tasks, aborted first-screen refs, and legacy delayed events during main-thread reload', () => {
|
|
402
402
|
const delayedBackgroundFunctionArray = [{ task: vi.fn() }];
|
|
403
|
+
const clearFirstScreenWorkletRefMap = vi.fn();
|
|
404
|
+
const clearDelayedWorklets = vi.fn();
|
|
403
405
|
globalThis.lynxWorkletImpl = {
|
|
404
406
|
...(globalThis.lynxWorkletImpl ?? {}),
|
|
405
407
|
_runOnBackgroundDelayImpl: {
|
|
@@ -408,6 +410,12 @@ describe('ElementTemplate reloadMainThread', () => {
|
|
|
408
410
|
delayedBackgroundFunctionArray.length = 0;
|
|
409
411
|
}),
|
|
410
412
|
},
|
|
413
|
+
_refImpl: {
|
|
414
|
+
clearFirstScreenWorkletRefMap,
|
|
415
|
+
},
|
|
416
|
+
_eventDelayImpl: {
|
|
417
|
+
clearDelayedWorklets,
|
|
418
|
+
},
|
|
411
419
|
} as typeof globalThis.lynxWorkletImpl;
|
|
412
420
|
mockedState.root = { __jsx: null };
|
|
413
421
|
vi.mocked(mockRender).mockReturnValue({
|
|
@@ -421,6 +429,8 @@ describe('ElementTemplate reloadMainThread', () => {
|
|
|
421
429
|
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.clearDelayedBackgroundFunctions).toHaveBeenCalledTimes(
|
|
422
430
|
1,
|
|
423
431
|
);
|
|
432
|
+
expect(clearFirstScreenWorkletRefMap).toHaveBeenCalledTimes(1);
|
|
433
|
+
expect(clearDelayedWorklets).toHaveBeenCalledTimes(1);
|
|
424
434
|
expect(delayedBackgroundFunctionArray).toHaveLength(0);
|
|
425
435
|
});
|
|
426
436
|
|
|
@@ -636,7 +646,7 @@ describe('ElementTemplate reloadMainThread', () => {
|
|
|
636
646
|
} as ReturnType<typeof __SerializeElementTemplate>);
|
|
637
647
|
try {
|
|
638
648
|
expect(() => reloadMainThread(undefined, { reloadTemplate: true })).toThrow(firstCleanupError);
|
|
639
|
-
expect(
|
|
649
|
+
expect(retireElementTemplateMainThreadForReload).toHaveBeenCalledTimes(1);
|
|
640
650
|
expect(reloader).not.toHaveBeenCalled();
|
|
641
651
|
} finally {
|
|
642
652
|
delete host[supportsReEvalKey];
|
|
@@ -26,7 +26,7 @@ import { ElementTemplateUpdateOps } from '../../../../../src/element-template/pr
|
|
|
26
26
|
import type { ElementTemplateUpdateCommitContext } from '../../../../../src/element-template/protocol/types.js';
|
|
27
27
|
import { parseElementTemplateUpdateEventPayload } from '../../../../../src/element-template/protocol/update-event.js';
|
|
28
28
|
import { clearEtAttrPlanMap } from '../../../../../src/element-template/runtime/template/attr-slot-plan.js';
|
|
29
|
-
import { resetElementTemplateMainThreadFunctionRuntime } from '../../../../../src/element-template/
|
|
29
|
+
import { resetElementTemplateMainThreadFunctionRuntime } from '../../../../../src/element-template/background/main-thread-function.js';
|
|
30
30
|
import {
|
|
31
31
|
installElementTemplatePatchListener,
|
|
32
32
|
resetElementTemplatePatchListener,
|
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
enqueueDelayedRunOnMainThreadData,
|
|
62
62
|
takeDelayedRunOnMainThreadData,
|
|
63
63
|
} from '../../../../src/core/thread-function-call/main-thread.js';
|
|
64
|
-
import { runOnMainThread } from '../../../../src/element-template/
|
|
64
|
+
import { runOnMainThread } from '../../../../src/element-template/background/main-thread-function.js';
|
|
65
65
|
import { resetFunctionCallReturnListener } from '../../../../src/core/thread-function-call/return-value.js';
|
|
66
66
|
import { ElementTemplateEnvManager } from '../../test-utils/debug/envManager.js';
|
|
67
67
|
|
|
@@ -390,6 +390,7 @@ describe('render transform contract', () => {
|
|
|
390
390
|
}));
|
|
391
391
|
expect(rootRef).not.toHaveProperty('attributes.component-at-indexes');
|
|
392
392
|
expect(typedCreateLog[2]).not.toHaveProperty('component-at-indexes');
|
|
393
|
+
expect(typedCreateLog[2]).not.toHaveProperty('css-id');
|
|
393
394
|
expect(typedCreateLog[3]).toEqual([[expect.objectContaining({ tag: 'list-item' })]]);
|
|
394
395
|
expect(typedCreateLog[5]).toEqual({});
|
|
395
396
|
|
|
@@ -407,6 +408,38 @@ describe('render transform contract', () => {
|
|
|
407
408
|
});
|
|
408
409
|
});
|
|
409
410
|
|
|
411
|
+
it('passes scoped css-id to a nested typed list after spread attributes', async () => {
|
|
412
|
+
await compileAndRender(
|
|
413
|
+
`
|
|
414
|
+
import './style.css';
|
|
415
|
+
|
|
416
|
+
export function App() {
|
|
417
|
+
const listProps = { 'css-id': 1 };
|
|
418
|
+
return (
|
|
419
|
+
<view>
|
|
420
|
+
<list className="horizontal-list" scroll-orientation="horizontal" {...listProps}>
|
|
421
|
+
<list-item item-key="first" />
|
|
422
|
+
</list>
|
|
423
|
+
</view>
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
`,
|
|
427
|
+
{ cssScopeAll: true },
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
const typedCreateLog = lastMock!.nativeLog.find((entry) =>
|
|
431
|
+
Array.isArray(entry)
|
|
432
|
+
&& entry[0] === '__CreateTypedElementTemplate'
|
|
433
|
+
&& entry[1] === 'list'
|
|
434
|
+
) as unknown[] | undefined;
|
|
435
|
+
|
|
436
|
+
expect(typedCreateLog?.[2]).toMatchObject({
|
|
437
|
+
class: 'horizontal-list',
|
|
438
|
+
'css-id': 1460700,
|
|
439
|
+
'scroll-orientation': 'horizontal',
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
|
|
410
443
|
it('keeps transformed deferred list items outside ET list phase 1 support', async () => {
|
|
411
444
|
const source = `
|
|
412
445
|
export function App() {
|
|
@@ -113,7 +113,7 @@ const config: UserConfigExport = defineConfig({
|
|
|
113
113
|
include: ['**/__test__/element-template/**/*.{test,spec}.{js,ts,jsx,tsx}'],
|
|
114
114
|
coverage: {
|
|
115
115
|
reportsDirectory: 'coverage/element-template',
|
|
116
|
-
include: ['src/element-template/**', 'lazy/element-template*.js'],
|
|
116
|
+
include: ['src/element-template/**', 'src/core/compat/componentIs.ts', 'lazy/element-template*.js'],
|
|
117
117
|
exclude: [
|
|
118
118
|
'src/element-template/**/*.d.ts',
|
|
119
119
|
'src/element-template/protocol/types.ts',
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
4
4
|
// LICENSE file in the root directory of this source tree.
|
|
5
5
|
*/
|
|
6
|
-
import { render, options, Component, createElement } from 'preact';
|
|
6
|
+
import { render, options, Component, createElement, process } from 'preact';
|
|
7
7
|
import { beforeAll, beforeEach, describe, expect, onTestFinished, test, vi } from 'vitest';
|
|
8
8
|
|
|
9
9
|
import { setupDocument } from '../../../src/document';
|
|
10
10
|
import { setupPage, snapshotInstanceManager } from '../../../src/snapshot';
|
|
11
11
|
import { initProfileHook } from '../../../src/snapshot/debug/profileHooks';
|
|
12
|
+
import { globalPatchOptions } from '../../../src/snapshot/lifecycle/patch/commit';
|
|
12
13
|
import { useState } from '../../../src/index';
|
|
13
14
|
import {
|
|
14
15
|
COMMIT,
|
|
@@ -228,12 +229,7 @@ describe('profile', () => {
|
|
|
228
229
|
"ReactLynx::setState",
|
|
229
230
|
{
|
|
230
231
|
"args": {
|
|
231
|
-
"changed (shallow diff) state keys": "["count"]",
|
|
232
232
|
"componentName": "ClassComponent",
|
|
233
|
-
"current state keys": "["count"]",
|
|
234
|
-
"currentValue": "{"count":0}",
|
|
235
|
-
"next state keys": "["count"]",
|
|
236
|
-
"nextValue": "{"count":1}",
|
|
237
233
|
},
|
|
238
234
|
"flowId": 666,
|
|
239
235
|
},
|
|
@@ -292,13 +288,8 @@ describe('profile', () => {
|
|
|
292
288
|
"ReactLynx::hooks::setState",
|
|
293
289
|
{
|
|
294
290
|
"args": {
|
|
295
|
-
"changed (shallow diff) state keys": "[]",
|
|
296
291
|
"componentName": "App",
|
|
297
|
-
"current state keys": "[]",
|
|
298
|
-
"currentValue": "0",
|
|
299
292
|
"hookIdx": "0",
|
|
300
|
-
"next state keys": "[]",
|
|
301
|
-
"nextValue": "1",
|
|
302
293
|
},
|
|
303
294
|
"flowId": 666,
|
|
304
295
|
},
|
|
@@ -307,13 +298,8 @@ describe('profile', () => {
|
|
|
307
298
|
"ReactLynx::hooks::setState",
|
|
308
299
|
{
|
|
309
300
|
"args": {
|
|
310
|
-
"changed (shallow diff) state keys": "["count","newKey"]",
|
|
311
301
|
"componentName": "App",
|
|
312
|
-
"current state keys": "["count","unchanged"]",
|
|
313
|
-
"currentValue": "{"count":0,"unchanged":"unchanged"}",
|
|
314
302
|
"hookIdx": "1",
|
|
315
|
-
"next state keys": "["count","unchanged","newKey"]",
|
|
316
|
-
"nextValue": "{"count":1,"unchanged":"unchanged","newKey":"newValue"}",
|
|
317
303
|
},
|
|
318
304
|
"flowId": 666,
|
|
319
305
|
},
|
|
@@ -322,13 +308,8 @@ describe('profile', () => {
|
|
|
322
308
|
"ReactLynx::hooks::setState",
|
|
323
309
|
{
|
|
324
310
|
"args": {
|
|
325
|
-
"changed (shallow diff) state keys": "["count"]",
|
|
326
311
|
"componentName": "App",
|
|
327
|
-
"current state keys": "["count","circularKey"]",
|
|
328
|
-
"currentValue": "{"count":0,"circularKey":"[Unserializable: Circular]"}",
|
|
329
312
|
"hookIdx": "2",
|
|
330
|
-
"next state keys": "["count","circularKey"]",
|
|
331
|
-
"nextValue": "{"count":1,"circularKey":{"count":0,"circularKey":"[Unserializable: Circular]"}}",
|
|
332
313
|
},
|
|
333
314
|
"flowId": 666,
|
|
334
315
|
},
|
|
@@ -361,13 +342,8 @@ describe('profile', () => {
|
|
|
361
342
|
"ReactLynx::hooks::setState",
|
|
362
343
|
{
|
|
363
344
|
"args": {
|
|
364
|
-
"changed (shallow diff) state keys": "[]",
|
|
365
345
|
"componentName": "App",
|
|
366
|
-
"current state keys": "[]",
|
|
367
|
-
"currentValue": ""() => \\"A\\""",
|
|
368
346
|
"hookIdx": "0",
|
|
369
|
-
"next state keys": "[]",
|
|
370
|
-
"nextValue": ""() => \\"B\\""",
|
|
371
347
|
},
|
|
372
348
|
"flowId": 666,
|
|
373
349
|
},
|
|
@@ -376,6 +352,151 @@ describe('profile', () => {
|
|
|
376
352
|
`);
|
|
377
353
|
});
|
|
378
354
|
|
|
355
|
+
test('associates batched Hook updates with one render and commit flow', () => {
|
|
356
|
+
process();
|
|
357
|
+
let update;
|
|
358
|
+
const rendered = [];
|
|
359
|
+
function App() {
|
|
360
|
+
const [value, setValue] = useState(0);
|
|
361
|
+
rendered.push(value);
|
|
362
|
+
update = setValue;
|
|
363
|
+
return <view />;
|
|
364
|
+
}
|
|
365
|
+
const previousFlowIds = globalPatchOptions.flowIds;
|
|
366
|
+
onTestFinished(() => {
|
|
367
|
+
globalPatchOptions.flowIds = previousFlowIds;
|
|
368
|
+
});
|
|
369
|
+
globalPatchOptions.flowIds = undefined;
|
|
370
|
+
render(<App />, scratch);
|
|
371
|
+
lynx.performance.profileMark.mockClear();
|
|
372
|
+
lynx.performance.profileFlowId.mockClear();
|
|
373
|
+
lynx.performance.profileFlowId.mockReturnValueOnce(701).mockReturnValueOnce(702);
|
|
374
|
+
lynx.performance.profileStart.mockClear();
|
|
375
|
+
lynx.performance.profileEnd.mockClear();
|
|
376
|
+
|
|
377
|
+
update(value => value + 1);
|
|
378
|
+
update(value => value + 1);
|
|
379
|
+
expect(rendered).toEqual([0]);
|
|
380
|
+
expect(lynx.performance.profileMark.mock.calls).toEqual([
|
|
381
|
+
['ReactLynx::hooks::setState', { flowId: 701, args: { componentName: 'App', hookIdx: '0' } }],
|
|
382
|
+
['ReactLynx::hooks::setState', { flowId: 701, args: { componentName: 'App', hookIdx: '0' } }],
|
|
383
|
+
]);
|
|
384
|
+
expect(lynx.performance.profileFlowId).toHaveBeenCalledTimes(1);
|
|
385
|
+
|
|
386
|
+
process();
|
|
387
|
+
expect(rendered).toEqual([0, 2]);
|
|
388
|
+
expect(lynx.performance.profileStart).toHaveBeenCalledWith('ReactLynx::diff::App', { flowId: 701 });
|
|
389
|
+
expect(lynx.performance.profileStart).toHaveBeenCalledWith('ReactLynx::commit', {
|
|
390
|
+
flowId: 701,
|
|
391
|
+
flowIds: [701],
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
update(value => value + 1);
|
|
395
|
+
expect(lynx.performance.profileMark).toHaveBeenLastCalledWith('ReactLynx::hooks::setState', {
|
|
396
|
+
flowId: 702,
|
|
397
|
+
args: { componentName: 'App', hookIdx: '0' },
|
|
398
|
+
});
|
|
399
|
+
process();
|
|
400
|
+
expect(rendered).toEqual([0, 2, 3]);
|
|
401
|
+
expect(lynx.performance.profileFlowId).toHaveBeenCalledTimes(2);
|
|
402
|
+
|
|
403
|
+
lynx.performance.profileMark.mockClear();
|
|
404
|
+
update(value => value);
|
|
405
|
+
process();
|
|
406
|
+
expect(rendered).toEqual([0, 2, 3]);
|
|
407
|
+
expect(lynx.performance.profileMark).not.toHaveBeenCalled();
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
test('records only metadata without inspecting Hook state', () => {
|
|
411
|
+
let update;
|
|
412
|
+
let rendered;
|
|
413
|
+
function App() {
|
|
414
|
+
const [value, setValue] = useState(null);
|
|
415
|
+
rendered = value;
|
|
416
|
+
update = setValue;
|
|
417
|
+
return <view />;
|
|
418
|
+
}
|
|
419
|
+
render(<App />, scratch);
|
|
420
|
+
|
|
421
|
+
const inspect = vi.fn(() => {
|
|
422
|
+
throw new Error('state must not be inspected');
|
|
423
|
+
});
|
|
424
|
+
const record = { toJSON: inspect };
|
|
425
|
+
Object.defineProperty(record, 'getter', { enumerable: true, get: inspect });
|
|
426
|
+
const opaque = new Proxy({}, {
|
|
427
|
+
ownKeys: inspect,
|
|
428
|
+
get: inspect,
|
|
429
|
+
getOwnPropertyDescriptor: inspect,
|
|
430
|
+
getPrototypeOf: inspect,
|
|
431
|
+
has: inspect,
|
|
432
|
+
});
|
|
433
|
+
const revoked = Proxy.revocable({}, {});
|
|
434
|
+
revoked.revoke();
|
|
435
|
+
const circular = [];
|
|
436
|
+
circular.push(circular);
|
|
437
|
+
const values = [
|
|
438
|
+
'x'.repeat(65536),
|
|
439
|
+
Object.fromEntries(Array.from({ length: 1000 }, (_, i) => [`key${i}`, i])),
|
|
440
|
+
record,
|
|
441
|
+
opaque,
|
|
442
|
+
revoked.proxy,
|
|
443
|
+
circular,
|
|
444
|
+
1n,
|
|
445
|
+
Symbol('state'),
|
|
446
|
+
undefined,
|
|
447
|
+
() => 'function state',
|
|
448
|
+
];
|
|
449
|
+
|
|
450
|
+
for (const value of values) {
|
|
451
|
+
lynx.performance.profileMark.mockClear();
|
|
452
|
+
update(() => value);
|
|
453
|
+
expect(lynx.performance.profileMark.mock.calls).toEqual([
|
|
454
|
+
['ReactLynx::hooks::setState', { flowId: 666, args: { componentName: 'App', hookIdx: '0' } }],
|
|
455
|
+
]);
|
|
456
|
+
process();
|
|
457
|
+
expect(rendered).toBe(value);
|
|
458
|
+
}
|
|
459
|
+
expect(inspect).not.toHaveBeenCalled();
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
test.each(['hook', 'class'])('continues a %s update when trace emission throws', kind => {
|
|
463
|
+
let update;
|
|
464
|
+
let rendered;
|
|
465
|
+
function HookComponent() {
|
|
466
|
+
const [value, setValue] = useState(0);
|
|
467
|
+
rendered = value;
|
|
468
|
+
update = setValue;
|
|
469
|
+
return <view />;
|
|
470
|
+
}
|
|
471
|
+
class ClassComponent extends Component {
|
|
472
|
+
state = { value: 0 };
|
|
473
|
+
render() {
|
|
474
|
+
rendered = this.state.value;
|
|
475
|
+
update = value => this.setState({ value });
|
|
476
|
+
return <view />;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
render(kind === 'hook' ? <HookComponent /> : <ClassComponent />, scratch);
|
|
480
|
+
|
|
481
|
+
const sinkError = vi.fn(() => {
|
|
482
|
+
throw new Error('trace sink failed');
|
|
483
|
+
});
|
|
484
|
+
lynx.performance.profileMark.mockImplementationOnce(sinkError);
|
|
485
|
+
update(1n);
|
|
486
|
+
process();
|
|
487
|
+
expect(sinkError).toHaveBeenCalledTimes(1);
|
|
488
|
+
expect(rendered).toBe(1n);
|
|
489
|
+
|
|
490
|
+
const flowError = vi.fn(() => {
|
|
491
|
+
throw new Error('flow allocation failed');
|
|
492
|
+
});
|
|
493
|
+
lynx.performance.profileFlowId.mockImplementationOnce(flowError);
|
|
494
|
+
update(2n);
|
|
495
|
+
process();
|
|
496
|
+
expect(flowError).toHaveBeenCalledTimes(1);
|
|
497
|
+
expect(rendered).toBe(2n);
|
|
498
|
+
});
|
|
499
|
+
|
|
379
500
|
test('should handle missing component instance', async () => {
|
|
380
501
|
let capturedComponent;
|
|
381
502
|
|
|
@@ -9,7 +9,13 @@ import { getReloadVersion } from '../../../src/core/reload-version.js';
|
|
|
9
9
|
import { resetFunctionCallReturnListener } from '../../../src/core/thread-function-call/return-value.js';
|
|
10
10
|
import { __root } from '../../../src/root.js';
|
|
11
11
|
import { setupPage } from '../../../src/snapshot/index.js';
|
|
12
|
+
import { initEventDelay } from '../../../src/worklet-runtime/delayWorkletEvent.js';
|
|
12
13
|
import { initRunOnBackgroundDelay } from '../../../src/worklet-runtime/run-on-background/index.js';
|
|
14
|
+
import {
|
|
15
|
+
getFromWorkletRefMap,
|
|
16
|
+
initWorkletRef,
|
|
17
|
+
updateWorkletRefInitValueChanges,
|
|
18
|
+
} from '../../../src/worklet-runtime/workletRef.js';
|
|
13
19
|
import { globalEnvManager } from '../utils/envManager.js';
|
|
14
20
|
import { elementTree } from '../utils/nativeMethod.js';
|
|
15
21
|
|
|
@@ -61,3 +67,51 @@ it('clears old delayed background calls before rendering and preserves new calls
|
|
|
61
67
|
SystemInfo.lynxSdkVersion = previousSdkVersion;
|
|
62
68
|
}
|
|
63
69
|
});
|
|
70
|
+
|
|
71
|
+
it('clears aborted first-screen refs and delayed worklet events on pre-hydration reload while keeping positive refs', () => {
|
|
72
|
+
const previousImpl = globalThis.lynxWorkletImpl;
|
|
73
|
+
const previousSdkVersion = SystemInfo.lynxSdkVersion;
|
|
74
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
75
|
+
const delay = initRunOnBackgroundDelay();
|
|
76
|
+
const refImpl = initWorkletRef();
|
|
77
|
+
const eventDelayImpl = initEventDelay();
|
|
78
|
+
const preservedWorklet = vi.fn();
|
|
79
|
+
globalThis.lynxWorkletImpl = {
|
|
80
|
+
...previousImpl,
|
|
81
|
+
_workletMap: { preserved: preservedWorklet },
|
|
82
|
+
_runOnBackgroundDelayImpl: delay,
|
|
83
|
+
_refImpl: refImpl,
|
|
84
|
+
_eventDelayImpl: eventDelayImpl,
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
updateWorkletRefInitValueChanges([[1, 'positive-ref']]);
|
|
88
|
+
const abortedFirstScreenRef = getFromWorkletRefMap({ _wvid: -1, _initValue: 'before-reload' });
|
|
89
|
+
abortedFirstScreenRef.current = 'mutated-before-reload';
|
|
90
|
+
eventDelayImpl.delayExecUntilJsReady('legacy-hash', [{ currentTarget: {} }]);
|
|
91
|
+
|
|
92
|
+
__root.__jsx = createElement(() => {
|
|
93
|
+
void runOnBackground(Object.assign(() => {}, { _isFirstScreen: true }))();
|
|
94
|
+
return null;
|
|
95
|
+
});
|
|
96
|
+
renderPage({});
|
|
97
|
+
expect(refImpl._firstScreenWorkletRefMap[-1]).toBe(abortedFirstScreenRef);
|
|
98
|
+
expect(eventDelayImpl._delayedWorkletParamsMap.size).toBe(1);
|
|
99
|
+
|
|
100
|
+
// Reload before hydration finishes.
|
|
101
|
+
updatePage({}, { reloadTemplate: true });
|
|
102
|
+
|
|
103
|
+
expect(refImpl._firstScreenWorkletRefMap).toEqual({});
|
|
104
|
+
expect(eventDelayImpl._delayedWorkletParamsMap.size).toBe(0);
|
|
105
|
+
expect(getFromWorkletRefMap({ _wvid: 1 }).current).toBe('positive-ref');
|
|
106
|
+
expect(globalThis.lynxWorkletImpl._workletMap.preserved).toBe(preservedWorklet);
|
|
107
|
+
|
|
108
|
+
const freshFirstScreenRef = getFromWorkletRefMap({ _wvid: -1, _initValue: 'after-reload' });
|
|
109
|
+
expect(freshFirstScreenRef).not.toBe(abortedFirstScreenRef);
|
|
110
|
+
expect(freshFirstScreenRef.current).toBe('after-reload');
|
|
111
|
+
} finally {
|
|
112
|
+
delay.clearDelayedBackgroundFunctions();
|
|
113
|
+
resetFunctionCallReturnListener();
|
|
114
|
+
globalThis.lynxWorkletImpl = previousImpl;
|
|
115
|
+
SystemInfo.lynxSdkVersion = previousSdkVersion;
|
|
116
|
+
}
|
|
117
|
+
});
|