@lynx-js/react 0.129.0 → 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 +24 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/globalProps.test.ts +27 -6
- package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
- 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/imports/no-legacy-imports.test.ts +7 -6
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
- package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +89 -3
- package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +88 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +3 -0
- package/runtime/__test__/element-template/native/reload.test.ts +118 -2
- 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/background/update-timing.test.ts +15 -0
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +212 -7
- package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
- 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/render/render-direct-suspense.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
- package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
- package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +309 -26
- package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
- package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
- package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
- package/runtime/__test__/shared/component-stack.test.ts +211 -0
- package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
- package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
- 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/lynx/timing.test.jsx +3 -0
- package/runtime/__test__/snapshot/preact.test.jsx +0 -3
- package/runtime/__test__/snapshot/ref.test.jsx +30 -0
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +12 -0
- package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
- package/runtime/lazy/element-template-internal.js +1 -1
- package/runtime/lazy/internal.js +1 -1
- package/runtime/lazy/jsx-dev-runtime.js +1 -1
- package/runtime/lazy/jsx-runtime.js +1 -1
- package/runtime/lazy/legacy-react-runtime.js +1 -1
- package/runtime/lazy/react-lepus.js +1 -1
- package/runtime/lazy/react.js +1 -1
- package/runtime/lib/core/capture-main-thread-object.js +2 -1
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/globalProps.js +1 -1
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
- package/runtime/lib/core/lynx-data-processors.js +3 -0
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.js +1 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/document.js +0 -5
- package/runtime/lib/document.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/commit-hook.js +11 -12
- package/runtime/lib/element-template/background/commit-hook.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/client/root.d.ts +1 -1
- package/runtime/lib/element-template/client/root.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/index.d.ts +2 -2
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +2 -2
- package/runtime/lib/element-template/internal.js +1 -14
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.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/flush.d.ts +1 -0
- package/runtime/lib/element-template/native/flush.js +9 -0
- package/runtime/lib/element-template/native/flush.js.map +1 -0
- package/runtime/lib/element-template/native/main-thread-api.js +3 -7
- package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js +8 -2
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +57 -50
- 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 +35 -10
- 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/page/root-instance.d.ts +0 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +31 -2
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.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-background-function.js +8 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +7 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +380 -50
- 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 +3 -2
- 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/internal.d.ts +1 -1
- package/runtime/lib/internal.js +1 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +2 -125
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/shared/component-stack.d.ts +0 -4
- package/runtime/lib/shared/component-stack.js +21 -5
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js +23 -17
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.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/snapshot/list/listUpdateInfo.js +0 -30
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +11 -8
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +6 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/capture-main-thread-object.ts +2 -1
- package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
- package/runtime/src/core/globalProps.ts +1 -1
- package/runtime/src/core/lynx/lazy-bundle.ts +1 -1
- package/runtime/src/core/lynx-data-processors.ts +124 -1
- package/runtime/src/core/runtime-destroy.ts +1 -1
- package/runtime/src/document.ts +0 -6
- package/runtime/src/element-template/background/attr-slots.ts +5 -1
- package/runtime/src/element-template/background/commit-hook.ts +18 -12
- 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/client/root.ts +1 -3
- package/runtime/src/element-template/debug/alog.ts +5 -2
- package/runtime/src/element-template/index.ts +2 -2
- package/runtime/src/element-template/internal.ts +1 -20
- package/runtime/src/element-template/lynx/env.ts +1 -1
- package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +5 -1
- package/runtime/src/element-template/native/flush.ts +10 -0
- package/runtime/src/element-template/native/main-thread-api.ts +3 -6
- package/runtime/src/element-template/native/mts-destroy.ts +7 -2
- package/runtime/src/element-template/native/patch-listener.ts +62 -57
- package/runtime/src/element-template/native/reload-background.ts +1 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +32 -11
- 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 -13
- package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
- package/runtime/src/element-template/runtime/patch.ts +38 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
- package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +31 -4
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
- package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +456 -50
- package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +14 -4
- package/runtime/src/element-template/runtime/template/typed-attributes.ts +3 -3
- package/runtime/src/element-template/types.d.ts +6 -0
- package/runtime/src/internal.ts +1 -1
- package/runtime/src/lynx-api.ts +2 -124
- package/runtime/src/shared/component-stack.ts +22 -5
- package/runtime/src/snapshot/lifecycle/destroy.ts +23 -18
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
- package/runtime/src/snapshot/lifecycle/ref/delay.ts +1 -1
- package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
- package/runtime/src/snapshot/lynx/calledByNative.ts +11 -9
- package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
- package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
- package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
- package/runtime/src/worklet-runtime/README.md +30 -10
- package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
- package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +6 -0
- package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
- package/runtime/types/types.d.ts +2 -1
- package/runtime/vitest.config.ts +0 -2
- package/testing-library/.turbo/turbo-build.log +7 -7
- package/testing-library/src/__tests__/act.test.jsx +0 -7
- package/testing-library/src/__tests__/alog.test.jsx +12 -54
- package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
- package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
- package/testing-library/src/__tests__/worklet.test.jsx +49 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +133 -297
- package/transform/__test__/defines.spec.js +30 -0
- package/transform/__test__/fixture.spec.js +11 -11
- package/transform/__test__/main-thread-object-compat.spec.js +111 -0
- package/transform/__test__/object-methods.spec.js +79 -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/extract_ident.rs +99 -49
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +63 -57
- package/transform/crates/swc_plugin_worklet/lib.rs +393 -589
- package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
- 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 +11 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +12 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +14 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +17 -6
- 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/package.json +0 -1
- package/transform/src/lib.rs +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +167 -69
- package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +226 -132
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
- package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/hmr.js +0 -28
- package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
- package/runtime/src/snapshot/worklet/hmr.ts +0 -34
- /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
- /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
|
@@ -64,6 +64,19 @@ function walkFiles(dir: string, pattern = /\.(?:[cm]?[jt]sx?)$/): string[] {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
function getResolvedRelativeImports(file: string): string[] {
|
|
68
|
+
const source = fs.readFileSync(file, 'utf8');
|
|
69
|
+
const relativeImportPattern = /(?:from\s+|import\s*\(\s*|import\s+)['"](\.[^'"]+)['"]/g;
|
|
70
|
+
return Array.from(
|
|
71
|
+
source.matchAll(relativeImportPattern),
|
|
72
|
+
(match) => path.resolve(path.dirname(file), match[1]!),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function stripModuleExtension(filePath: string): string {
|
|
77
|
+
return filePath.replace(/\.(?:[cm]?[jt]sx?)$/, '');
|
|
78
|
+
}
|
|
79
|
+
|
|
67
80
|
describe('snapshot containment guardrails', () => {
|
|
68
81
|
test('keeps legacy runtime implementation directories under snapshot backend', () => {
|
|
69
82
|
for (const dir of legacySourceDirs) {
|
|
@@ -89,13 +102,14 @@ describe('snapshot containment guardrails', () => {
|
|
|
89
102
|
});
|
|
90
103
|
|
|
91
104
|
test('does not import old implementation paths outside the snapshot backend', () => {
|
|
92
|
-
const
|
|
93
|
-
String.raw`(?:from\s+|import\s*\(\s*)['"](?:\./|\../)+(?:${legacySourceDirPattern})(?:/|['"])`,
|
|
94
|
-
);
|
|
105
|
+
const legacyRootPrefixes = legacySourceDirs.map((dir) => `${path.join(srcRoot, dir)}${path.sep}`);
|
|
95
106
|
const offenders = walkFiles(srcRoot)
|
|
96
107
|
.filter((file) => !file.includes(`${path.sep}src${path.sep}snapshot${path.sep}`))
|
|
97
|
-
.filter((file) =>
|
|
98
|
-
|
|
108
|
+
.filter((file) =>
|
|
109
|
+
getResolvedRelativeImports(file).some((resolved) =>
|
|
110
|
+
legacyRootPrefixes.some((prefix) => resolved.startsWith(prefix))
|
|
111
|
+
)
|
|
112
|
+
)
|
|
99
113
|
.map((file) => path.relative(runtimeRoot, file));
|
|
100
114
|
|
|
101
115
|
expect(offenders).toEqual([]);
|
|
@@ -103,10 +117,18 @@ describe('snapshot containment guardrails', () => {
|
|
|
103
117
|
|
|
104
118
|
test('prevents element-template from depending on snapshot private paths', () => {
|
|
105
119
|
const elementTemplateRoot = path.join(srcRoot, 'element-template');
|
|
106
|
-
const
|
|
107
|
-
|
|
120
|
+
const snapshotPrefix = `${path.join(srcRoot, 'snapshot')}${path.sep}`;
|
|
121
|
+
const snapshotRootFiles = new Set(
|
|
122
|
+
['document', 'index', 'internal', 'lynx', 'lynx-api', 'root', 'runtime-marker'].map((name) =>
|
|
123
|
+
path.join(srcRoot, name)
|
|
124
|
+
),
|
|
125
|
+
);
|
|
108
126
|
const offenders = walkFiles(elementTemplateRoot)
|
|
109
|
-
.filter((file) =>
|
|
127
|
+
.filter((file) =>
|
|
128
|
+
getResolvedRelativeImports(file).some((resolved) =>
|
|
129
|
+
resolved.startsWith(snapshotPrefix) || snapshotRootFiles.has(stripModuleExtension(resolved))
|
|
130
|
+
)
|
|
131
|
+
)
|
|
110
132
|
.map((file) => path.relative(runtimeRoot, file));
|
|
111
133
|
|
|
112
134
|
expect(offenders).toEqual([]);
|
|
@@ -135,13 +157,25 @@ describe('snapshot containment guardrails', () => {
|
|
|
135
157
|
});
|
|
136
158
|
|
|
137
159
|
test('prevents core and shared modules from depending on runtime backends', () => {
|
|
138
|
-
const
|
|
139
|
-
|
|
160
|
+
const backendPrefixes = [
|
|
161
|
+
`${path.join(srcRoot, 'snapshot')}${path.sep}`,
|
|
162
|
+
`${path.join(srcRoot, 'element-template')}${path.sep}`,
|
|
163
|
+
];
|
|
164
|
+
const snapshotRootFiles = new Set(
|
|
165
|
+
['document', 'index', 'internal', 'lynx', 'lynx-api', 'root', 'runtime-marker'].map((name) =>
|
|
166
|
+
path.join(srcRoot, name)
|
|
167
|
+
),
|
|
168
|
+
);
|
|
140
169
|
const offenders = [
|
|
141
170
|
...walkFiles(coreRoot),
|
|
142
171
|
...walkFiles(sharedRoot),
|
|
143
172
|
]
|
|
144
|
-
.filter((file) =>
|
|
173
|
+
.filter((file) =>
|
|
174
|
+
getResolvedRelativeImports(file).some((resolved) =>
|
|
175
|
+
backendPrefixes.some((prefix) => resolved.startsWith(prefix))
|
|
176
|
+
|| snapshotRootFiles.has(stripModuleExtension(resolved))
|
|
177
|
+
)
|
|
178
|
+
)
|
|
145
179
|
.map((file) => path.relative(runtimeRoot, file));
|
|
146
180
|
|
|
147
181
|
expect(offenders).toEqual([]);
|
|
@@ -0,0 +1,211 @@
|
|
|
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 type { VNode } from 'preact';
|
|
6
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { DIFF, DIFFED, RENDER, ROOT } from '../../src/shared/render-constants.js';
|
|
9
|
+
|
|
10
|
+
describe('shared/component-stack', () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
vi.resetModules();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('is idempotent and clears leaked renderStack entries on next root render or re-setup', async () => {
|
|
16
|
+
const { options } = await import('preact');
|
|
17
|
+
delete options[DIFF];
|
|
18
|
+
delete options[DIFFED];
|
|
19
|
+
delete options[ROOT];
|
|
20
|
+
delete options.vnode;
|
|
21
|
+
delete options[RENDER];
|
|
22
|
+
|
|
23
|
+
const { getCurrentVNode, setupComponentStack } = await import('../../src/shared/component-stack.js');
|
|
24
|
+
setupComponentStack();
|
|
25
|
+
|
|
26
|
+
const installedDiff = options[DIFF];
|
|
27
|
+
const installedDiffed = options[DIFFED];
|
|
28
|
+
const installedRoot = options[ROOT];
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
30
|
+
const installedVNode = options.vnode;
|
|
31
|
+
const installedRender = options[RENDER];
|
|
32
|
+
|
|
33
|
+
function ThrowingChild() {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const throwingVNode = { type: ThrowingChild, props: {} } as unknown as VNode;
|
|
38
|
+
options[ROOT]?.(throwingVNode, {} as never);
|
|
39
|
+
options[DIFF]?.(throwingVNode);
|
|
40
|
+
options[RENDER]?.(throwingVNode);
|
|
41
|
+
// Simulate a component throwing during render before DIFFED runs.
|
|
42
|
+
expect(getCurrentVNode()).toBe(throwingVNode);
|
|
43
|
+
|
|
44
|
+
// Next root render must clear renderStack as well as ownerStack.
|
|
45
|
+
const nextRootVNode = { type: 'view', props: {} } as unknown as VNode;
|
|
46
|
+
options[ROOT]?.(nextRootVNode, {} as never);
|
|
47
|
+
expect(getCurrentVNode()).toBeNull();
|
|
48
|
+
|
|
49
|
+
// Repeated setupComponentStack() must not double-wrap hooks and must reset stacks.
|
|
50
|
+
options[DIFF]?.(throwingVNode);
|
|
51
|
+
expect(getCurrentVNode()).toBe(throwingVNode);
|
|
52
|
+
setupComponentStack();
|
|
53
|
+
expect(getCurrentVNode()).toBeNull();
|
|
54
|
+
expect(options[DIFF]).toBe(installedDiff);
|
|
55
|
+
expect(options[DIFFED]).toBe(installedDiffed);
|
|
56
|
+
expect(options[ROOT]).toBe(installedRoot);
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
58
|
+
expect(options.vnode).toBe(installedVNode);
|
|
59
|
+
expect(options[RENDER]).toBe(installedRender);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('chains existing Preact option hooks and formats owner stacks across vnode types', async () => {
|
|
63
|
+
const { Fragment, options } = await import('preact');
|
|
64
|
+
const oldDiff = vi.fn();
|
|
65
|
+
const oldDiffed = vi.fn();
|
|
66
|
+
const oldRoot = vi.fn();
|
|
67
|
+
const oldVNode = vi.fn();
|
|
68
|
+
const oldRender = vi.fn();
|
|
69
|
+
|
|
70
|
+
options[DIFF] = oldDiff;
|
|
71
|
+
options[DIFFED] = oldDiffed;
|
|
72
|
+
options[ROOT] = oldRoot;
|
|
73
|
+
options.vnode = oldVNode;
|
|
74
|
+
options[RENDER] = oldRender;
|
|
75
|
+
|
|
76
|
+
const { getCurrentVNode, getOwnerStack, setupComponentStack } = await import(
|
|
77
|
+
'../../src/shared/component-stack.js'
|
|
78
|
+
);
|
|
79
|
+
setupComponentStack();
|
|
80
|
+
|
|
81
|
+
function Outer() {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
function NamedInner() {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
NamedInner.displayName = 'CustomInner';
|
|
88
|
+
|
|
89
|
+
const rootVNode = { type: Outer, props: {}, __source: { fileName: 'App.tsx', lineNumber: 10 } } as unknown as VNode;
|
|
90
|
+
options.vnode?.(rootVNode);
|
|
91
|
+
options[ROOT]?.(rootVNode, {} as never);
|
|
92
|
+
options[DIFF]?.(rootVNode);
|
|
93
|
+
options[RENDER]?.(rootVNode);
|
|
94
|
+
expect(getCurrentVNode()).toBe(rootVNode);
|
|
95
|
+
|
|
96
|
+
const innerVNode = { type: NamedInner, props: {} } as unknown as VNode;
|
|
97
|
+
options.vnode?.(innerVNode);
|
|
98
|
+
// Cloning a vnode with an existing _owner must preserve that _owner.
|
|
99
|
+
const preOwnedVNode = { type: 'view', props: {}, _owner: rootVNode } as unknown as VNode;
|
|
100
|
+
options.vnode?.(preOwnedVNode);
|
|
101
|
+
expect((preOwnedVNode as unknown as { _owner: unknown })._owner).toBe(rootVNode);
|
|
102
|
+
|
|
103
|
+
options[DIFF]?.(innerVNode);
|
|
104
|
+
options[RENDER]?.(innerVNode);
|
|
105
|
+
expect(getCurrentVNode()).toBe(innerVNode);
|
|
106
|
+
|
|
107
|
+
const fragmentVNode = { type: Fragment, props: {} } as unknown as VNode;
|
|
108
|
+
options.vnode?.(fragmentVNode);
|
|
109
|
+
options[DIFF]?.(fragmentVNode);
|
|
110
|
+
options[RENDER]?.(fragmentVNode);
|
|
111
|
+
options[DIFFED]?.(fragmentVNode);
|
|
112
|
+
expect(getCurrentVNode()).toBe(innerVNode);
|
|
113
|
+
|
|
114
|
+
// Nested portal root render (parent with parentNode) must preserve outer stacks,
|
|
115
|
+
// including when an inner portal component throws and unwinds to an outer boundary.
|
|
116
|
+
const portalContextVNode = { type: Outer, props: {} } as unknown as VNode;
|
|
117
|
+
const throwingPortalChildVNode = { type: NamedInner, props: {} } as unknown as VNode;
|
|
118
|
+
options.vnode?.(portalContextVNode);
|
|
119
|
+
options[ROOT]?.(portalContextVNode, { parentNode: {} } as never);
|
|
120
|
+
expect(getCurrentVNode()).toBe(innerVNode);
|
|
121
|
+
options[DIFF]?.(portalContextVNode);
|
|
122
|
+
options[RENDER]?.(portalContextVNode);
|
|
123
|
+
options[DIFF]?.(throwingPortalChildVNode);
|
|
124
|
+
options[RENDER]?.(throwingPortalChildVNode);
|
|
125
|
+
expect(getCurrentVNode()).toBe(throwingPortalChildVNode);
|
|
126
|
+
// Simulate throwingPortalChildVNode and portalContextVNode skipping DIFFED
|
|
127
|
+
// when an outer boundary catches the error and finishes DIFFED on innerVNode.
|
|
128
|
+
options[DIFFED]?.(innerVNode);
|
|
129
|
+
expect(getCurrentVNode()).toBe(rootVNode);
|
|
130
|
+
|
|
131
|
+
// Component bailout (DIFF + DIFFED without RENDER) must not pop parent owner.
|
|
132
|
+
const bailoutVNode = { type: NamedInner, props: {} } as unknown as VNode;
|
|
133
|
+
options[DIFF]?.(bailoutVNode);
|
|
134
|
+
expect(getCurrentVNode()).toBe(bailoutVNode);
|
|
135
|
+
options[DIFFED]?.(bailoutVNode);
|
|
136
|
+
expect(getCurrentVNode()).toBe(rootVNode);
|
|
137
|
+
|
|
138
|
+
// Guard against DIFFED on a component vnode that was never pushed to renderStack.
|
|
139
|
+
const unpushedVNode = { type: NamedInner, props: {} } as unknown as VNode;
|
|
140
|
+
options[DIFFED]?.(unpushedVNode);
|
|
141
|
+
expect(getCurrentVNode()).toBe(rootVNode);
|
|
142
|
+
|
|
143
|
+
const postPortalChildVNode = { type: 'view', props: {} } as unknown as VNode;
|
|
144
|
+
options.vnode?.(postPortalChildVNode);
|
|
145
|
+
expect((postPortalChildVNode as unknown as { _owner: unknown })._owner).toBe(rootVNode);
|
|
146
|
+
|
|
147
|
+
const hostVNode = { type: 'view', props: {}, _owner: fragmentVNode } as unknown as VNode;
|
|
148
|
+
const textVNode = { type: null, props: {}, _owner: hostVNode } as unknown as VNode;
|
|
149
|
+
|
|
150
|
+
expect(getOwnerStack(textVNode)).toBe(
|
|
151
|
+
' in #text\n'
|
|
152
|
+
+ ' in view\n'
|
|
153
|
+
+ ' in Fragment\n'
|
|
154
|
+
+ ' in CustomInner\n'
|
|
155
|
+
+ ' in Outer (at App.tsx:10)\n',
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
options[DIFFED]?.(rootVNode);
|
|
159
|
+
expect(getCurrentVNode()).toBeNull();
|
|
160
|
+
|
|
161
|
+
expect(oldRoot).toHaveBeenCalledTimes(2);
|
|
162
|
+
expect(oldDiff).toHaveBeenCalledTimes(6);
|
|
163
|
+
expect(oldRender).toHaveBeenCalledTimes(5);
|
|
164
|
+
expect(oldDiffed).toHaveBeenCalledTimes(5);
|
|
165
|
+
expect(oldVNode).toHaveBeenCalledTimes(6);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('unwinds renderStack and ownerStack when a Portal child throws into an outer ErrorBoundary', async () => {
|
|
169
|
+
const { Component, createElement, render } = await import('preact');
|
|
170
|
+
const { createPortal } = await import('../../src/snapshot/lynx/portals.js');
|
|
171
|
+
const { getCurrentVNode, setupComponentStack } = await import(
|
|
172
|
+
'../../src/shared/component-stack.js'
|
|
173
|
+
);
|
|
174
|
+
setupComponentStack();
|
|
175
|
+
|
|
176
|
+
class Boundary extends Component<{ children?: unknown }, { failed: boolean }> {
|
|
177
|
+
override state = { failed: false };
|
|
178
|
+
static override getDerivedStateFromError() {
|
|
179
|
+
return { failed: true };
|
|
180
|
+
}
|
|
181
|
+
override render() {
|
|
182
|
+
return this.state.failed ? null : this.props.children;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function Boom(): null {
|
|
187
|
+
throw new Error('portal boom');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const fakeTarget = {
|
|
191
|
+
_nodeSelectToken: { type: 0, identifier: '#host', rootUniqueId: 0 },
|
|
192
|
+
} as never;
|
|
193
|
+
|
|
194
|
+
function App() {
|
|
195
|
+
return createElement(Boundary, null, createPortal(createElement(Boom, null), fakeTarget));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const rootContainer = {
|
|
199
|
+
nodeType: 1,
|
|
200
|
+
childNodes: [],
|
|
201
|
+
insertBefore() {},
|
|
202
|
+
removeChild() {},
|
|
203
|
+
} as never;
|
|
204
|
+
|
|
205
|
+
render(createElement(App, null), rootContainer);
|
|
206
|
+
|
|
207
|
+
expect(getCurrentVNode()).toBeNull();
|
|
208
|
+
const afterRenderVNode = createElement('view', null) as unknown as { _owner?: unknown };
|
|
209
|
+
expect(afterRenderVNode._owner).toBeNull();
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -33,9 +33,6 @@ describe('formatPatch', () => {
|
|
|
33
33
|
SnapshotOperation.DEV_ONLY_AddSnapshot,
|
|
34
34
|
'unique-1',
|
|
35
35
|
'snapshotCreator-val',
|
|
36
|
-
SnapshotOperation.DEV_ONLY_RegisterWorklet,
|
|
37
|
-
'hash-1',
|
|
38
|
-
'() => {}',
|
|
39
36
|
];
|
|
40
37
|
const formatted = prettyFormatSnapshotPatch(snapshotPatch);
|
|
41
38
|
expect(formatted).toEqual([
|
|
@@ -60,11 +57,6 @@ describe('formatPatch', () => {
|
|
|
60
57
|
uniqID: 'unique-1',
|
|
61
58
|
snapshotCreator: 'snapshotCreator-val',
|
|
62
59
|
},
|
|
63
|
-
{
|
|
64
|
-
op: 'DEV_ONLY_RegisterWorklet',
|
|
65
|
-
hash: 'hash-1',
|
|
66
|
-
fnStr: '() => {}',
|
|
67
|
-
},
|
|
68
60
|
]);
|
|
69
61
|
});
|
|
70
62
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { prepareGestureForCommit } from '../../../src/snapshot/gesture/
|
|
3
|
+
import { prepareGestureForCommit } from '../../../src/snapshot/gesture/processGestureBackground';
|
|
4
4
|
import { clearConfigCacheForTesting } from '../../../src/snapshot/worklet/functionality';
|
|
5
5
|
|
|
6
6
|
describe('prepareGestureForCommit', () => {
|
|
@@ -15,13 +15,13 @@ beforeAll(() => {
|
|
|
15
15
|
|
|
16
16
|
beforeEach(() => {
|
|
17
17
|
globalEnvManager.resetEnv();
|
|
18
|
-
|
|
18
|
+
lynx.__runtime_configs__ = { globalPropsMode: 'event' };
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
afterEach(() => {
|
|
22
22
|
elementTree.clear();
|
|
23
23
|
vi.restoreAllMocks();
|
|
24
|
-
|
|
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
|
-
|
|
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
|
|
312
|
-
|
|
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 = () => {
|
|
@@ -9,6 +9,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite
|
|
|
9
9
|
import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit';
|
|
10
10
|
import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread';
|
|
11
11
|
import { installComponentCompat } from '../../../src/core/component';
|
|
12
|
+
import { globalPipelineOptions } from '../../../src/core/performance';
|
|
12
13
|
import { initTimingAPI } from '../../../src/snapshot/lynx/performance';
|
|
13
14
|
import { __root } from '../../../src/root';
|
|
14
15
|
import { setupPage } from '../../../src/snapshot';
|
|
@@ -128,6 +129,7 @@ describe('setState timing api', () => {
|
|
|
128
129
|
|
|
129
130
|
globalEnvManager.switchToMainThread();
|
|
130
131
|
rLynxChange(mtCallbacks[0][1]);
|
|
132
|
+
expect(globalPipelineOptions).toBeUndefined();
|
|
131
133
|
expect(__root.__element_root).toMatchInlineSnapshot(`
|
|
132
134
|
<page
|
|
133
135
|
cssId="default-entry-from-native:0"
|
|
@@ -210,6 +212,7 @@ describe('attribute timing api', () => {
|
|
|
210
212
|
|
|
211
213
|
globalEnvManager.switchToMainThread();
|
|
212
214
|
rLynxChange(mtCallbacks[0][1]);
|
|
215
|
+
expect(globalPipelineOptions).toBeUndefined();
|
|
213
216
|
expect(__root.__element_root).toMatchInlineSnapshot(`
|
|
214
217
|
<page
|
|
215
218
|
cssId="default-entry-from-native:0"
|
|
@@ -93,9 +93,6 @@ function collectSnapshotPatchOps(patch) {
|
|
|
93
93
|
case SnapshotOperation.DEV_ONLY_AddSnapshot:
|
|
94
94
|
i += 2;
|
|
95
95
|
break;
|
|
96
|
-
case SnapshotOperation.DEV_ONLY_RegisterWorklet:
|
|
97
|
-
i += 2;
|
|
98
|
-
break;
|
|
99
96
|
case SnapshotOperation.DEV_ONLY_SetSnapshotEntryName:
|
|
100
97
|
i += 2;
|
|
101
98
|
break;
|
|
@@ -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
|
});
|
|
@@ -5,7 +5,6 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite
|
|
|
5
5
|
|
|
6
6
|
import { globalEnvManager } from './utils/envManager';
|
|
7
7
|
import { elementTree } from './utils/nativeMethod';
|
|
8
|
-
import { registerWorkletOnBackground } from '../../src/internal';
|
|
9
8
|
import { addCtxNotFoundEventListener } from '../../src/snapshot/lifecycle/patch/error';
|
|
10
9
|
import {
|
|
11
10
|
SnapshotOperation,
|
|
@@ -1637,38 +1636,6 @@ describe('DEV_ONLY_addSnapshot', () => {
|
|
|
1637
1636
|
});
|
|
1638
1637
|
});
|
|
1639
1638
|
|
|
1640
|
-
describe.skip('DEV_ONLY_RegisterWorklet', () => {
|
|
1641
|
-
beforeEach(() => {
|
|
1642
|
-
initGlobalSnapshotPatch();
|
|
1643
|
-
});
|
|
1644
|
-
|
|
1645
|
-
it('basic', () => {
|
|
1646
|
-
registerWorkletOnBackground('main-thread', 'hash-1', () => 'fn-1');
|
|
1647
|
-
globalThis.registerWorklet = vi.fn();
|
|
1648
|
-
|
|
1649
|
-
const patch = takeGlobalSnapshotPatch();
|
|
1650
|
-
|
|
1651
|
-
expect(patch).toMatchInlineSnapshot(`
|
|
1652
|
-
[
|
|
1653
|
-
101,
|
|
1654
|
-
"hash-1",
|
|
1655
|
-
"() => "fn-1"",
|
|
1656
|
-
]
|
|
1657
|
-
`);
|
|
1658
|
-
|
|
1659
|
-
// Apply patches in main thread
|
|
1660
|
-
snapshotPatchApply(patch, 42, false);
|
|
1661
|
-
|
|
1662
|
-
expect(globalThis.registerWorklet).toBeCalledTimes(1);
|
|
1663
|
-
expect(globalThis.registerWorklet.mock.calls[0][0]).toMatch('main-thread');
|
|
1664
|
-
expect(globalThis.registerWorklet.mock.calls[0][1]).toMatch('hash-1');
|
|
1665
|
-
expect(globalThis.registerWorklet.mock.calls[0][2]()).toMatch('fn-1');
|
|
1666
|
-
|
|
1667
|
-
registerWorkletOnBackground('main-thread', 'hash-1', () => 'fn-1');
|
|
1668
|
-
expect(globalThis.registerWorklet).toBeCalledTimes(1);
|
|
1669
|
-
});
|
|
1670
|
-
});
|
|
1671
|
-
|
|
1672
1639
|
describe('list', () => {
|
|
1673
1640
|
beforeEach(() => {
|
|
1674
1641
|
initGlobalSnapshotPatch();
|
|
@@ -100,4 +100,16 @@ describe('jsFunctionLifecycle', () => {
|
|
|
100
100
|
expect(register).toHaveBeenCalledTimes(2);
|
|
101
101
|
expect(manager.execIdRefCount.get(3)).toBe(1);
|
|
102
102
|
});
|
|
103
|
+
|
|
104
|
+
it('does not release a new runtime execution when retired finalizers run', () => {
|
|
105
|
+
const previous = new JsFunctionLifecycleManager();
|
|
106
|
+
previous.addRef(3, {});
|
|
107
|
+
previous.removeRef(3);
|
|
108
|
+
previous.dispose();
|
|
109
|
+
const current = new JsFunctionLifecycleManager();
|
|
110
|
+
current.addRef(3, {});
|
|
111
|
+
previous.fire();
|
|
112
|
+
expect(events).toEqual([]);
|
|
113
|
+
expect(current.execIdRefCount.get(3)).toBe(1);
|
|
114
|
+
});
|
|
103
115
|
});
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
describe('worklet-runtime legacy fallback', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.resetModules();
|
|
9
|
+
vi.stubGlobal('__LoadLepusChunk', undefined);
|
|
10
|
+
vi.stubGlobal('lynxWorkletImpl', undefined);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.unstubAllGlobals();
|
|
15
|
+
vi.resetModules();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('exports the compatibility helper without initializing the worklet runtime', async () => {
|
|
19
|
+
const reactInternal = await import('@lynx-js/react/internal');
|
|
20
|
+
const bindings = await import('@lynx-js/react/worklet-runtime/bindings');
|
|
21
|
+
|
|
22
|
+
expect(reactInternal.loadWorkletRuntime).toBeTypeOf('function');
|
|
23
|
+
expect(reactInternal.loadWorkletRuntime).toBe(bindings.loadWorkletRuntime);
|
|
24
|
+
expect(globalThis.lynxWorkletImpl).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('returns false when the legacy chunk loader is unavailable', async () => {
|
|
28
|
+
const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
|
|
29
|
+
|
|
30
|
+
expect(loadWorkletRuntime('__Card__')).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('reuses the in-memory runtime without loading the legacy chunk', async () => {
|
|
34
|
+
const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
|
|
35
|
+
const runtime = { _workletMap: {} };
|
|
36
|
+
const loader = vi.fn();
|
|
37
|
+
vi.stubGlobal('lynxWorkletImpl', runtime);
|
|
38
|
+
vi.stubGlobal('__LoadLepusChunk', loader);
|
|
39
|
+
|
|
40
|
+
expect(loadWorkletRuntime('__Card__')).toBe(true);
|
|
41
|
+
expect(globalThis.lynxWorkletImpl).toBe(runtime);
|
|
42
|
+
expect(loader).not.toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it.each([true, false])('returns the legacy chunk loader result (%s)', async (result) => {
|
|
46
|
+
const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
|
|
47
|
+
const loader = vi.fn(() => result);
|
|
48
|
+
vi.stubGlobal('__LoadLepusChunk', loader);
|
|
49
|
+
|
|
50
|
+
expect(loadWorkletRuntime('__Card__')).toBe(result);
|
|
51
|
+
expect(loader).toHaveBeenCalledExactlyOnceWith('worklet-runtime', {
|
|
52
|
+
dynamicComponentEntry: '__Card__',
|
|
53
|
+
chunkType: 0,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('supports callers without a dynamic component entry', async () => {
|
|
58
|
+
const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
|
|
59
|
+
const loader = vi.fn(() => true);
|
|
60
|
+
vi.stubGlobal('__LoadLepusChunk', loader);
|
|
61
|
+
|
|
62
|
+
expect(loadWorkletRuntime()).toBe(true);
|
|
63
|
+
expect(loader).toHaveBeenCalledExactlyOnceWith('worklet-runtime', {
|
|
64
|
+
dynamicComponentEntry: undefined,
|
|
65
|
+
chunkType: 0,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -61,6 +61,36 @@ describe('Worklet', () => {
|
|
|
61
61
|
if (kind === 'metadata') expect(value.nested).toEqual({ _wvid: 999 });
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
+
it('executes the original Native-held context without replacing its captures', () => {
|
|
65
|
+
initWorklet();
|
|
66
|
+
registerWorklet('main-thread', 'background-owner', function() {
|
|
67
|
+
return this._jsFn;
|
|
68
|
+
});
|
|
69
|
+
const handle = { _jsFnId: 7 };
|
|
70
|
+
const ctx = { _wkltId: 'background-owner', _execId: 3, _jsFn: { a: handle, b: handle } };
|
|
71
|
+
lynxWorkletImpl._jsFunctionLifecycleManager.addRef(3, ctx);
|
|
72
|
+
const nativeContext = ctx;
|
|
73
|
+
const first = runWorklet(nativeContext, []);
|
|
74
|
+
expect(first.a).toBe(first.b);
|
|
75
|
+
expect(first.a).toBe(ctx._jsFn.a);
|
|
76
|
+
expect(runWorklet(nativeContext, [])).toBe(first);
|
|
77
|
+
expect(lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(3)).toBe(2);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it.each(['2.15', '2.16'])('prepares captured execution metadata without a lifecycle manager on SDK %s', (version) => {
|
|
81
|
+
SystemInfo.lynxSdkVersion = version;
|
|
82
|
+
initWorklet();
|
|
83
|
+
lynxWorkletImpl._jsFunctionLifecycleManager = undefined;
|
|
84
|
+
registerWorklet('main-thread', 'fallback', function() {
|
|
85
|
+
return this._jsFn.callback;
|
|
86
|
+
});
|
|
87
|
+
const descriptor = { _jsFnId: 7 };
|
|
88
|
+
const ctx = { _wkltId: 'fallback', _execId: 3, _jsFn: { callback: descriptor } };
|
|
89
|
+
expect(runWorklet(ctx, [])).toEqual({ _jsFnId: 7, _execId: 3 });
|
|
90
|
+
expect(ctx._jsFn.callback).toEqual({ _jsFnId: 7, _execId: 3 });
|
|
91
|
+
expect(ctx._jsFn.callback).toBe(descriptor);
|
|
92
|
+
});
|
|
93
|
+
|
|
64
94
|
it('worklet should be called', () => {
|
|
65
95
|
initWorklet();
|
|
66
96
|
|
|
@@ -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,
|
|
@@ -38,7 +39,6 @@ export const {
|
|
|
38
39
|
process,
|
|
39
40
|
registerRuntimeBackend,
|
|
40
41
|
registerRuntimeVersion,
|
|
41
|
-
registerWorkletOnBackground,
|
|
42
42
|
transformToWorklet,
|
|
43
43
|
withInitDataInState,
|
|
44
44
|
wrapWithLynxComponent,
|
package/runtime/lazy/internal.js
CHANGED
|
@@ -46,12 +46,12 @@ export const {
|
|
|
46
46
|
getRuntimeVersion,
|
|
47
47
|
loadDynamicJS,
|
|
48
48
|
loadLazyBundle,
|
|
49
|
+
loadWorkletRuntime,
|
|
49
50
|
options,
|
|
50
51
|
preactCloneElement,
|
|
51
52
|
process,
|
|
52
53
|
registerRuntimeBackend,
|
|
53
54
|
registerRuntimeVersion,
|
|
54
|
-
registerWorkletOnBackground,
|
|
55
55
|
snapshotCreateList,
|
|
56
56
|
snapshotManager,
|
|
57
57
|
snapshotCreatorMap,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
|
|
5
|
-
import { sExportsJSXDevRuntime, target } from './target';
|
|
5
|
+
import { sExportsJSXDevRuntime, target } from './target.js';
|
|
6
6
|
|
|
7
7
|
export const {
|
|
8
8
|
Fragment,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
|
|
5
|
-
import { sExportsJSXRuntime, target } from './target';
|
|
5
|
+
import { sExportsJSXRuntime, target } from './target.js';
|
|
6
6
|
|
|
7
7
|
export const {
|
|
8
8
|
Fragment,
|