diff --git a/.changeset/snapshot-testing-paths.md b/.changeset/snapshot-testing-paths.md new file mode 100644 index 0000000000..397497206c --- /dev/null +++ b/.changeset/snapshot-testing-paths.md @@ -0,0 +1,5 @@ +--- +"@lynx-js/react": patch +--- + +Keep ReactLynx Testing Library imports aligned with the contained snapshot runtime paths. diff --git a/eslint.config.js b/eslint.config.js index 3d97fbdd79..7101d786ee 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -90,10 +90,12 @@ export default tseslint.config( // Generated worklet bundles are published assets, not source files. 'packages/react/runtime/worklet-runtime/**', 'packages/react/runtime/src/renderToOpcodes/**', + 'packages/react/runtime/src/snapshot/renderToOpcodes/**', 'packages/react/runtime/types/**', // TODO: enable eslint for react-runtime 'packages/react/runtime/src/compat/**', + 'packages/react/runtime/src/snapshot/compat/**', 'packages/react/runtime/src/opcodes.ts', // TODO: enable eslint for tools diff --git a/packages/react/package.json b/packages/react/package.json index 5bd27b01f6..4b97eb33dc 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -56,12 +56,12 @@ "default": "./runtime/lepus/jsx-runtime/index.js" }, "./hooks": { - "types": "./runtime/lib/hooks/react.d.ts", - "default": "./runtime/lib/hooks/react.js" + "types": "./runtime/lib/snapshot/hooks/react.d.ts", + "default": "./runtime/lib/snapshot/hooks/react.js" }, "./lepus/hooks": { - "types": "./runtime/lib/hooks/react.d.ts", - "default": "./runtime/lib/hooks/mainThread.js" + "types": "./runtime/lib/snapshot/hooks/react.d.ts", + "default": "./runtime/lib/snapshot/hooks/mainThread.js" }, "./lepus": { "types": "./runtime/lepus/index.d.ts", @@ -96,9 +96,9 @@ "default": "./runtime/lib/worklet-runtime/bindings/index.js" }, "./legacy-react-runtime": { - "types": "./runtime/lib/legacy-react-runtime/index.d.ts", + "types": "./runtime/lib/snapshot/legacy-react-runtime/index.d.ts", "lazy": "./runtime/lazy/legacy-react-runtime.js", - "default": "./runtime/lib/legacy-react-runtime/index.js" + "default": "./runtime/lib/snapshot/legacy-react-runtime/index.js" }, "./testing-library": { "types": "./testing-library/types/index.d.ts", @@ -132,10 +132,10 @@ "./runtime/lazy/import.d.ts" ], "hooks": [ - "./runtime/lib/hooks/react.d.ts" + "./runtime/lib/snapshot/hooks/react.d.ts" ], "lepus/hooks": [ - "./runtime/lib/hooks/react.d.ts" + "./runtime/lib/snapshot/hooks/react.d.ts" ], "internal": [ "./runtime/lib/internal.d.ts" @@ -174,7 +174,7 @@ "./runtime/lib/worklet-runtime/bindings/index.d.ts" ], "legacy-react-runtime": [ - "./runtime/lib/legacy-react-runtime/index.d.ts" + "./runtime/lib/snapshot/legacy-react-runtime/index.d.ts" ] } }, diff --git a/packages/react/runtime/__test__/guardrails/snapshot-containment.test.ts b/packages/react/runtime/__test__/guardrails/snapshot-containment.test.ts new file mode 100644 index 0000000000..da3c13192d --- /dev/null +++ b/packages/react/runtime/__test__/guardrails/snapshot-containment.test.ts @@ -0,0 +1,144 @@ +// Copyright 2026 The Lynx Authors. All rights reserved. +// Licensed under the Apache License Version 2.0 that can be found in the +// LICENSE file in the root directory of this source tree. + +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import { describe, expect, test } from 'vitest'; + +const testDir = path.dirname(fileURLToPath(import.meta.url)); +const runtimeRoot = path.resolve(testDir, '../..'); +const reactRoot = path.resolve(runtimeRoot, '..'); +const srcRoot = path.join(runtimeRoot, 'src'); +const testRoot = path.join(runtimeRoot, '__test__'); +const transformRoot = path.join(reactRoot, 'transform'); + +const legacySourceDirs = [ + 'alog', + 'compat', + 'debug', + 'gesture', + 'hooks', + 'legacy-react-runtime', + 'lifecycle', + 'list', + 'lynx', + 'renderToOpcodes', + 'worklet', +]; +const legacySourceDirPattern = legacySourceDirs.join('|'); +const knownTransformSourcePathExceptions = new Set([ + 'transform/src/swc_plugin_compat_post/mod.rs', + 'transform/tests/__swc_snapshots__/src/swc_plugin_compat_post/mod.rs/should_compat_dark_mode.js', + 'transform/tests/__swc_snapshots__/src/swc_plugin_compat_post/mod.rs/should_compat_dark_mode_custom_theme_expr.js', +]); + +const containedTestDirs = [ + 'alog', + 'compat', + 'css', + 'debug', + 'gesture', + 'hooks', + 'lifecycle', + 'lynx', + 'utils', + 'worklet', +]; + +function toPosixPath(file: string): string { + return file.split(path.sep).join('/'); +} + +function walkFiles(dir: string, pattern = /\.(?:[cm]?[jt]sx?)$/): string[] { + if (!fs.existsSync(dir)) { + return []; + } + return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { + const target = path.join(dir, entry.name); + if (entry.isDirectory()) { + return walkFiles(target, pattern); + } + return pattern.test(entry.name) ? [target] : []; + }); +} + +describe('snapshot containment guardrails', () => { + test('keeps legacy runtime implementation directories under snapshot backend', () => { + for (const dir of legacySourceDirs) { + expect(fs.existsSync(path.join(srcRoot, dir)), dir).toBe(false); + expect(fs.existsSync(path.join(srcRoot, 'snapshot', dir)), dir).toBe(true); + } + }); + + test('keeps legacy runtime tests under snapshot test namespace', () => { + for (const dir of containedTestDirs) { + expect(fs.existsSync(path.join(testRoot, dir)), dir).toBe(false); + expect(fs.existsSync(path.join(testRoot, 'snapshot', dir)), dir).toBe(true); + } + }); + + test('keeps loose legacy runtime tests under snapshot test namespace', () => { + const looseRuntimeTests = fs.readdirSync(testRoot, { withFileTypes: true }) + .filter((entry) => entry.isFile()) + .filter((entry) => /\.(?:[cm]?[jt]sx?)$/.test(entry.name)) + .map((entry) => entry.name); + + expect(looseRuntimeTests).toEqual([]); + }); + + test('does not import old implementation paths outside the snapshot backend', () => { + const oldPathPattern = new RegExp( + String.raw`(?:from\s+|import\s*\(\s*)['"](?:\./|\../)+(?:${legacySourceDirPattern})(?:/|['"])`, + ); + const offenders = walkFiles(srcRoot) + .filter((file) => !file.includes(`${path.sep}src${path.sep}snapshot${path.sep}`)) + .filter((file) => oldPathPattern.test(fs.readFileSync(file, 'utf8'))) + .map((file) => path.relative(runtimeRoot, file)); + + expect(offenders).toEqual([]); + }); + + test('prevents element-template from depending on snapshot private paths', () => { + const elementTemplateRoot = path.join(srcRoot, 'element-template'); + const forbiddenImportPattern = + /(?:from\s+|import\s*\(\s*)['"](?:\.\/|\.\.\/)+(?:snapshot|internal|root|lifecycle|renderToOpcodes)(?:\/|['"])/; + const offenders = walkFiles(elementTemplateRoot) + .filter((file) => forbiddenImportPattern.test(fs.readFileSync(file, 'utf8'))) + .map((file) => path.relative(runtimeRoot, file)); + + expect(offenders).toEqual([]); + }); + + test('prevents transform output from referencing untracked old runtime source paths', () => { + const oldPackageSourcePattern = new RegExp( + String.raw`@lynx-js/react/src/(?:${legacySourceDirPattern})(?:/|['"])`, + ); + const offenders = walkFiles(transformRoot, /\.(?:rs|[cm]?[jt]sx?)$/) + .map((file) => toPosixPath(path.relative(reactRoot, file))) + .filter((file) => !knownTransformSourcePathExceptions.has(file)) + .filter((file) => + oldPackageSourcePattern.test( + fs.readFileSync(path.join(reactRoot, file), 'utf8'), + ) + ); + + expect(offenders).toEqual([]); + }); + + test('keeps package type metadata aligned with contained runtime paths', () => { + const packageJson = JSON.parse( + fs.readFileSync(path.join(reactRoot, 'package.json'), 'utf8'), + ); + const typesVersions = JSON.stringify(packageJson.typesVersions ?? {}); + + expect(typesVersions).not.toContain('./runtime/lib/hooks/'); + expect(typesVersions).not.toContain('./runtime/lib/legacy-react-runtime/'); + expect(typesVersions).toContain('./runtime/lib/snapshot/hooks/react.d.ts'); + expect(typesVersions).toContain( + './runtime/lib/snapshot/legacy-react-runtime/index.d.ts', + ); + }); +}); diff --git a/packages/react/runtime/__test__/alog/elementPAPICall.test.js b/packages/react/runtime/__test__/snapshot/alog/elementPAPICall.test.js similarity index 95% rename from packages/react/runtime/__test__/alog/elementPAPICall.test.js rename to packages/react/runtime/__test__/snapshot/alog/elementPAPICall.test.js index 788d3dd260..d5219dcdfd 100644 --- a/packages/react/runtime/__test__/alog/elementPAPICall.test.js +++ b/packages/react/runtime/__test__/snapshot/alog/elementPAPICall.test.js @@ -1,5 +1,5 @@ import { describe, it, vi } from 'vitest'; -import { initElementPAPICallAlog } from '../../src/alog/elementPAPICall'; +import { initElementPAPICallAlog } from '../../../src/snapshot/alog/elementPAPICall'; import { globalEnvManager } from '../utils/envManager'; import { expect } from 'vitest'; diff --git a/packages/react/runtime/__test__/basic.test.jsx b/packages/react/runtime/__test__/snapshot/basic.test.jsx similarity index 99% rename from packages/react/runtime/__test__/basic.test.jsx rename to packages/react/runtime/__test__/snapshot/basic.test.jsx index f4d7b0fced..375c430523 100644 --- a/packages/react/runtime/__test__/basic.test.jsx +++ b/packages/react/runtime/__test__/snapshot/basic.test.jsx @@ -6,7 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { elementTree } from './utils/nativeMethod'; -import { SnapshotInstance, snapshotInstanceManager } from '../src/snapshot'; +import { SnapshotInstance, snapshotInstanceManager } from '../../src/snapshot'; const HOLE = null; diff --git a/packages/react/runtime/__test__/children.test.jsx b/packages/react/runtime/__test__/snapshot/children.test.jsx similarity index 98% rename from packages/react/runtime/__test__/children.test.jsx rename to packages/react/runtime/__test__/snapshot/children.test.jsx index 023b6a824e..92697f35bc 100644 --- a/packages/react/runtime/__test__/children.test.jsx +++ b/packages/react/runtime/__test__/snapshot/children.test.jsx @@ -6,9 +6,9 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { elementTree } from './utils/nativeMethod'; -import { setupPage } from '../src/snapshot'; -import { cloneElement, Children } from '../src/index'; -import { __root } from '../src/root'; +import { setupPage } from '../../src/snapshot'; +import { cloneElement, Children } from '../../src/index'; +import { __root } from '../../src/root'; import { globalEnvManager } from './utils/envManager'; import { toChildArray } from 'preact'; diff --git a/packages/react/runtime/__test__/clone.test.jsx b/packages/react/runtime/__test__/snapshot/clone.test.jsx similarity index 94% rename from packages/react/runtime/__test__/clone.test.jsx rename to packages/react/runtime/__test__/snapshot/clone.test.jsx index 0fc1a9ed3b..b97c240237 100644 --- a/packages/react/runtime/__test__/clone.test.jsx +++ b/packages/react/runtime/__test__/snapshot/clone.test.jsx @@ -6,13 +6,13 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { elementTree } from './utils/nativeMethod'; -import { setupPage, BackgroundSnapshotInstance } from '../src/snapshot'; -import { cloneElement, createRef } from '../src/index'; -import { __root } from '../src/root'; +import { setupPage, BackgroundSnapshotInstance } from '../../src/snapshot'; +import { cloneElement, createRef } from '../../src/index'; +import { __root } from '../../src/root'; import { globalEnvManager } from './utils/envManager'; -import { injectUpdateMainThread } from '../src/lifecycle/patch/updateMainThread'; +import { injectUpdateMainThread } from '../../src/snapshot/lifecycle/patch/updateMainThread'; import { render } from 'preact'; -import { clearCommitTaskId, replaceCommitHook } from '../src/lifecycle/patch/commit'; +import { clearCommitTaskId, replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit'; beforeAll(() => { setupPage(__CreatePage('0', 0)); diff --git a/packages/react/runtime/__test__/compat.test.jsx b/packages/react/runtime/__test__/snapshot/compat.test.jsx similarity index 97% rename from packages/react/runtime/__test__/compat.test.jsx rename to packages/react/runtime/__test__/snapshot/compat.test.jsx index 559d8c0964..193a2a69a7 100644 --- a/packages/react/runtime/__test__/compat.test.jsx +++ b/packages/react/runtime/__test__/snapshot/compat.test.jsx @@ -1,9 +1,9 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { elementTree } from './utils/nativeMethod'; -import { setupPage, snapshotInstanceManager, backgroundSnapshotInstanceManager } from '../src/snapshot'; -import { ComponentFromReactRuntime, wrapWithLynxComponent } from '../src/compat/lynxComponent'; -import { setupDocument } from '../src/document'; +import { setupPage, snapshotInstanceManager, backgroundSnapshotInstanceManager } from '../../src/snapshot'; +import { ComponentFromReactRuntime, wrapWithLynxComponent } from '../../src/snapshot/compat/lynxComponent'; +import { setupDocument } from '../../src/document'; import { Fragment, render } from 'preact'; import { globalEnvManager } from './utils/envManager'; diff --git a/packages/react/runtime/__test__/compat/export.test.jsx b/packages/react/runtime/__test__/snapshot/compat/export.test.jsx similarity index 96% rename from packages/react/runtime/__test__/compat/export.test.jsx rename to packages/react/runtime/__test__/snapshot/compat/export.test.jsx index 0e7bf07f51..8809d5693e 100644 --- a/packages/react/runtime/__test__/compat/export.test.jsx +++ b/packages/react/runtime/__test__/snapshot/compat/export.test.jsx @@ -2,7 +2,7 @@ import { describe, it, expect, vi } from 'vitest'; import ReactLynx from '@lynx-js/react'; import { startTransition as preactStartTransition, useTransition as preactUseTransition } from 'preact/compat'; -import compat from '../../compat'; +import compat from '../../../compat'; describe('Default export', () => { it('should include all exports from @lynx-js/react', () => { diff --git a/packages/react/runtime/__test__/compat/hooks.test.jsx b/packages/react/runtime/__test__/snapshot/compat/hooks.test.jsx similarity index 94% rename from packages/react/runtime/__test__/compat/hooks.test.jsx rename to packages/react/runtime/__test__/snapshot/compat/hooks.test.jsx index 4bdf8d63ec..2ce8a02ad1 100644 --- a/packages/react/runtime/__test__/compat/hooks.test.jsx +++ b/packages/react/runtime/__test__/snapshot/compat/hooks.test.jsx @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import { useTransition, startTransition } from '../../compat'; +import { useTransition, startTransition } from '../../../compat'; describe('useTransition', () => { it('should return an array with two elements', () => { diff --git a/packages/react/runtime/__test__/compat/initData.test.jsx b/packages/react/runtime/__test__/snapshot/compat/initData.test.jsx similarity index 95% rename from packages/react/runtime/__test__/compat/initData.test.jsx rename to packages/react/runtime/__test__/snapshot/compat/initData.test.jsx index d18f7699c1..eb22fe8cad 100644 --- a/packages/react/runtime/__test__/compat/initData.test.jsx +++ b/packages/react/runtime/__test__/snapshot/compat/initData.test.jsx @@ -1,16 +1,16 @@ import { Component, render } from 'preact'; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { elementTree, waitSchedule } from '../utils/nativeMethod'; -import { setupBackgroundDocument } from '../../src/document'; +import { setupBackgroundDocument } from '../../../src/document'; import { setupPage, SnapshotInstance, BackgroundSnapshotInstance, backgroundSnapshotInstanceManager, -} from '../../src/snapshot'; +} from '../../../src/snapshot'; import { backgroundSnapshotInstanceToJSON } from '../utils/debug'; import { useState } from 'preact/compat'; -import { useInitData, withInitDataInState } from '../../src/lynx-api'; +import { useInitData, withInitDataInState } from '../../../src/lynx-api'; import { globalEnvManager } from '../utils/envManager'; /** @type {SnapshotInstance} */ diff --git a/packages/react/runtime/__test__/createSuspender.jsx b/packages/react/runtime/__test__/snapshot/createSuspender.jsx similarity index 100% rename from packages/react/runtime/__test__/createSuspender.jsx rename to packages/react/runtime/__test__/snapshot/createSuspender.jsx diff --git a/packages/react/runtime/__test__/css/compat.test.jsx b/packages/react/runtime/__test__/snapshot/css/compat.test.jsx similarity index 97% rename from packages/react/runtime/__test__/css/compat.test.jsx rename to packages/react/runtime/__test__/snapshot/css/compat.test.jsx index 0433f7de59..d9ecd42642 100644 --- a/packages/react/runtime/__test__/css/compat.test.jsx +++ b/packages/react/runtime/__test__/snapshot/css/compat.test.jsx @@ -3,7 +3,7 @@ // LICENSE file in the root directory of this source tree. import { expect, it } from 'vitest'; -import { createSnapshot, SnapshotInstance } from '../../src/snapshot'; +import { createSnapshot, SnapshotInstance } from '../../../src/snapshot'; it('legacy createSnapshot', function() { const snapshot = createSnapshot( diff --git a/packages/react/runtime/__test__/css/remove-scoped-lazy-bundle.test.jsx b/packages/react/runtime/__test__/snapshot/css/remove-scoped-lazy-bundle.test.jsx similarity index 94% rename from packages/react/runtime/__test__/css/remove-scoped-lazy-bundle.test.jsx rename to packages/react/runtime/__test__/snapshot/css/remove-scoped-lazy-bundle.test.jsx index 9517e18f30..cf7c5817c7 100644 --- a/packages/react/runtime/__test__/css/remove-scoped-lazy-bundle.test.jsx +++ b/packages/react/runtime/__test__/snapshot/css/remove-scoped-lazy-bundle.test.jsx @@ -3,7 +3,7 @@ // LICENSE file in the root directory of this source tree. import { expect, it, beforeEach, afterEach } from 'vitest'; -import { SnapshotInstance } from '../../src/snapshot'; +import { SnapshotInstance } from '../../../src/snapshot'; let prevEntryName; beforeEach(() => { diff --git a/packages/react/runtime/__test__/css/remove-scoped-main-bundle.test.jsx b/packages/react/runtime/__test__/snapshot/css/remove-scoped-main-bundle.test.jsx similarity index 91% rename from packages/react/runtime/__test__/css/remove-scoped-main-bundle.test.jsx rename to packages/react/runtime/__test__/snapshot/css/remove-scoped-main-bundle.test.jsx index a005106a52..e30f284c1e 100644 --- a/packages/react/runtime/__test__/css/remove-scoped-main-bundle.test.jsx +++ b/packages/react/runtime/__test__/snapshot/css/remove-scoped-main-bundle.test.jsx @@ -3,7 +3,7 @@ // LICENSE file in the root directory of this source tree. import { expect, it } from 'vitest'; -import { SnapshotInstance } from '../../src/snapshot'; +import { SnapshotInstance } from '../../../src/snapshot'; const snapshot1 = __SNAPSHOT__( diff --git a/packages/react/runtime/__test__/css/scoped-lazy-bundle.test.jsx b/packages/react/runtime/__test__/snapshot/css/scoped-lazy-bundle.test.jsx similarity index 94% rename from packages/react/runtime/__test__/css/scoped-lazy-bundle.test.jsx rename to packages/react/runtime/__test__/snapshot/css/scoped-lazy-bundle.test.jsx index cc0dc7dc48..4c0841ceb3 100644 --- a/packages/react/runtime/__test__/css/scoped-lazy-bundle.test.jsx +++ b/packages/react/runtime/__test__/snapshot/css/scoped-lazy-bundle.test.jsx @@ -7,7 +7,7 @@ import { expect, it, beforeEach, afterEach } from 'vitest'; -import { SnapshotInstance } from '../../src/snapshot'; +import { SnapshotInstance } from '../../../src/snapshot'; let prevEntryName; beforeEach(() => { diff --git a/packages/react/runtime/__test__/css/scoped-main-bundle.test.jsx b/packages/react/runtime/__test__/snapshot/css/scoped-main-bundle.test.jsx similarity index 92% rename from packages/react/runtime/__test__/css/scoped-main-bundle.test.jsx rename to packages/react/runtime/__test__/snapshot/css/scoped-main-bundle.test.jsx index 6f74431984..fec2080eb2 100644 --- a/packages/react/runtime/__test__/css/scoped-main-bundle.test.jsx +++ b/packages/react/runtime/__test__/snapshot/css/scoped-main-bundle.test.jsx @@ -7,7 +7,7 @@ import { expect, it } from 'vitest'; -import { SnapshotInstance } from '../../src/snapshot'; +import { SnapshotInstance } from '../../../src/snapshot'; const snapshot1 = __SNAPSHOT__( diff --git a/packages/react/runtime/__test__/debug/backgroundSnapshot-profile.test.jsx b/packages/react/runtime/__test__/snapshot/debug/backgroundSnapshot-profile.test.jsx similarity index 96% rename from packages/react/runtime/__test__/debug/backgroundSnapshot-profile.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/backgroundSnapshot-profile.test.jsx index 78170ee72e..11043bfb2d 100644 --- a/packages/react/runtime/__test__/debug/backgroundSnapshot-profile.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/backgroundSnapshot-profile.test.jsx @@ -6,11 +6,11 @@ import { options, render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest'; -import { setupDocument } from '../../src/document'; -import { setupVNodeSourceHook } from '../../src/debug/vnodeSource'; -import { SnapshotOperation, SnapshotOperationParams } from '../../src/lifecycle/patch/snapshotPatch'; -import { DIFFED, DOM } from '../../src/renderToOpcodes/constants'; -import { __root } from '../../src/root'; +import { setupDocument } from '../../../src/document'; +import { setupVNodeSourceHook } from '../../../src/snapshot/debug/vnodeSource'; +import { SnapshotOperation, SnapshotOperationParams } from '../../../src/snapshot/lifecycle/patch/snapshotPatch'; +import { DIFFED, DOM } from '../../../src/snapshot/renderToOpcodes/constants'; +import { __root } from '../../../src/root'; import { setupPage, SnapshotInstance, @@ -18,7 +18,7 @@ import { BackgroundSnapshotInstance, backgroundSnapshotInstanceManager, hydrate, -} from '../../src/snapshot'; +} from '../../../src/snapshot'; import { elementTree } from '../utils/nativeMethod'; const HOLE = null; diff --git a/packages/react/runtime/__test__/debug/children-with-same-key.test.jsx b/packages/react/runtime/__test__/snapshot/debug/children-with-same-key.test.jsx similarity index 93% rename from packages/react/runtime/__test__/debug/children-with-same-key.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/children-with-same-key.test.jsx index 5d1faeb3df..15e1220216 100644 --- a/packages/react/runtime/__test__/debug/children-with-same-key.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/children-with-same-key.test.jsx @@ -7,7 +7,7 @@ test('preact/debug - children with the same key attribute', async () => { const consoleError = vi.spyOn(console, 'error'); await import('preact/debug'); - const { root } = await import('../../src/index'); + const { root } = await import('../../../src/index'); function Bar() { return ( diff --git a/packages/react/runtime/__test__/debug/describeInvalidValue.test.ts b/packages/react/runtime/__test__/snapshot/debug/describeInvalidValue.test.ts similarity index 92% rename from packages/react/runtime/__test__/debug/describeInvalidValue.test.ts rename to packages/react/runtime/__test__/snapshot/debug/describeInvalidValue.test.ts index a0d832f289..2f5aab409d 100644 --- a/packages/react/runtime/__test__/debug/describeInvalidValue.test.ts +++ b/packages/react/runtime/__test__/snapshot/debug/describeInvalidValue.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { describeInvalidValue } from '../../src/debug/describeInvalidValue.js'; +import { describeInvalidValue } from '../../../src/snapshot/debug/describeInvalidValue.js'; describe('describeInvalidValue', () => { it('describes null and undefined', () => { diff --git a/packages/react/runtime/__test__/debug/formatPatch.test.ts b/packages/react/runtime/__test__/snapshot/debug/formatPatch.test.ts similarity index 91% rename from packages/react/runtime/__test__/debug/formatPatch.test.ts rename to packages/react/runtime/__test__/snapshot/debug/formatPatch.test.ts index 57baa68610..54784e0894 100644 --- a/packages/react/runtime/__test__/debug/formatPatch.test.ts +++ b/packages/react/runtime/__test__/snapshot/debug/formatPatch.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest'; -import { prettyFormatSnapshotPatch } from '../../src/debug/formatPatch.js'; -import { SnapshotOperation } from '../../src/lifecycle/patch/snapshotPatch.js'; +import { prettyFormatSnapshotPatch } from '../../../src/snapshot/debug/formatPatch.js'; +import { SnapshotOperation } from '../../../src/snapshot/lifecycle/patch/snapshotPatch.js'; describe('formatPatch', () => { it('should format all operation types', () => { diff --git a/packages/react/runtime/__test__/debug/hooks-in-render.test.jsx b/packages/react/runtime/__test__/snapshot/debug/hooks-in-render.test.jsx similarity index 86% rename from packages/react/runtime/__test__/debug/hooks-in-render.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/hooks-in-render.test.jsx index fd9ce5ab2a..b8eb103771 100644 --- a/packages/react/runtime/__test__/debug/hooks-in-render.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/hooks-in-render.test.jsx @@ -5,7 +5,7 @@ test('preact/debug - Hook can only be invoked from render methods', async () => .stubGlobal('__LEPUS__', false); await import('preact/debug'); - const { useState } = await import('../../src/index'); + const { useState } = await import('../../../src/index'); expect(() => useState(0)).toThrowErrorMatchingInlineSnapshot( `[Error: Hook can only be invoked from render methods.]`, diff --git a/packages/react/runtime/__test__/debug/hooks-invalid-args.test.jsx b/packages/react/runtime/__test__/snapshot/debug/hooks-invalid-args.test.jsx similarity index 91% rename from packages/react/runtime/__test__/debug/hooks-invalid-args.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/hooks-invalid-args.test.jsx index 5fc75ccf8b..d671ddad6d 100644 --- a/packages/react/runtime/__test__/debug/hooks-invalid-args.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/hooks-invalid-args.test.jsx @@ -9,7 +9,7 @@ test('preact/debug - Invalid argument passed to hook', async () => { }); await import('preact/debug'); - const { root, useEffect, useState } = await import('../../src/index'); + const { root, useEffect, useState } = await import('../../../src/index'); function Bar() { useState(0); diff --git a/packages/react/runtime/__test__/debug/jsx-twice.test.jsx b/packages/react/runtime/__test__/snapshot/debug/jsx-twice.test.jsx similarity index 96% rename from packages/react/runtime/__test__/debug/jsx-twice.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/jsx-twice.test.jsx index 9d988bf1c8..344704368e 100644 --- a/packages/react/runtime/__test__/debug/jsx-twice.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/jsx-twice.test.jsx @@ -5,7 +5,7 @@ test('preact/debug - Invalid type passed to createElement()', async () => { .stubGlobal('__LEPUS__', false); await import('preact/debug'); - const { root } = await import('../../src/index'); + const { root } = await import('../../../src/index'); const a = { b: , arr: [], obj: {}, regexp: /foo/ }; diff --git a/packages/react/runtime/__test__/debug/missing-suspense.test.jsx b/packages/react/runtime/__test__/snapshot/debug/missing-suspense.test.jsx similarity index 92% rename from packages/react/runtime/__test__/debug/missing-suspense.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/missing-suspense.test.jsx index 02cde9a5f4..d7470f2836 100644 --- a/packages/react/runtime/__test__/debug/missing-suspense.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/missing-suspense.test.jsx @@ -5,7 +5,7 @@ test('preact/debug - Missing Suspense', async () => { .stubGlobal('__LEPUS__', false); await import('preact/debug'); - const { lazy, root } = await import('../../src/index'); + const { lazy, root } = await import('../../../src/index'); const Foo = lazy(() => Promise.reject({ default: 'Foo' })); diff --git a/packages/react/runtime/__test__/debug/object-as-child.test.jsx b/packages/react/runtime/__test__/snapshot/debug/object-as-child.test.jsx similarity index 92% rename from packages/react/runtime/__test__/debug/object-as-child.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/object-as-child.test.jsx index 439edc45f2..63421686bf 100644 --- a/packages/react/runtime/__test__/debug/object-as-child.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/object-as-child.test.jsx @@ -5,7 +5,7 @@ test('preact/debug - Objects are not valid as a child', async () => { .stubGlobal('__LEPUS__', false); await import('preact/debug'); - const { root } = await import('../../src/index'); + const { root } = await import('../../../src/index'); function Bar() { return { foo: 'foo', bar: 'bar', baz: 'baz' }; diff --git a/packages/react/runtime/__test__/debug/printSnapshot.test.jsx b/packages/react/runtime/__test__/snapshot/debug/printSnapshot.test.jsx similarity index 98% rename from packages/react/runtime/__test__/debug/printSnapshot.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/printSnapshot.test.jsx index 4ad36314a8..8fbc2a0f51 100644 --- a/packages/react/runtime/__test__/debug/printSnapshot.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/printSnapshot.test.jsx @@ -10,8 +10,8 @@ import { backgroundSnapshotInstanceManager, SnapshotInstance, snapshotInstanceManager, -} from '../../src/snapshot'; -import { printSerializedSnapshotInstance, printSnapshotInstance } from '../../src/debug/printSnapshot'; +} from '../../../src/snapshot'; +import { printSerializedSnapshotInstance, printSnapshotInstance } from '../../../src/snapshot/debug/printSnapshot'; const HOLE = null; diff --git a/packages/react/runtime/__test__/debug/profile-module.test.ts b/packages/react/runtime/__test__/snapshot/debug/profile-module.test.ts similarity index 91% rename from packages/react/runtime/__test__/debug/profile-module.test.ts rename to packages/react/runtime/__test__/snapshot/debug/profile-module.test.ts index fe81b19b90..a0d549d0b5 100644 --- a/packages/react/runtime/__test__/debug/profile-module.test.ts +++ b/packages/react/runtime/__test__/snapshot/debug/profile-module.test.ts @@ -37,7 +37,7 @@ describe('debug/profile module', () => { performance: perf, }; - const profile = await import('../../src/debug/profile'); + const profile = await import('../../../src/snapshot/debug/profile'); expect(profile.isProfiling).toBe(true); }); @@ -53,7 +53,7 @@ describe('debug/profile module', () => { performance: perf, }; - const profile = await import('../../src/debug/profile'); + const profile = await import('../../../src/snapshot/debug/profile'); expect(profile.isProfiling).toBe(false); expect(() => profile.profileStart('trace')).not.toThrow(); @@ -75,7 +75,7 @@ describe('debug/profile module', () => { performance: perf, }; - const profile = await import('../../src/debug/profile'); + const profile = await import('../../../src/snapshot/debug/profile'); profile.profileStart('trace-name', { args: { foo: 'bar' } }); profile.profileEnd(); diff --git a/packages/react/runtime/__test__/debug/profile.test.jsx b/packages/react/runtime/__test__/snapshot/debug/profile.test.jsx similarity index 96% rename from packages/react/runtime/__test__/debug/profile.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/profile.test.jsx index 7dd8647083..50e96f4516 100644 --- a/packages/react/runtime/__test__/debug/profile.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/profile.test.jsx @@ -6,11 +6,20 @@ import { render, options, Component } from 'preact'; import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'; -import { setupDocument } from '../../src/document'; -import { setupPage, snapshotInstanceManager } from '../../src/snapshot'; -import { initProfileHook } from '../../src/debug/profileHooks'; -import { useState } from '../../src/index'; -import { COMPONENT, DIFF, DIFF2, DIFFED, HOOKS, LIST, RENDER, VNODE } from '../../src/renderToOpcodes/constants'; +import { setupDocument } from '../../../src/document'; +import { setupPage, snapshotInstanceManager } from '../../../src/snapshot'; +import { initProfileHook } from '../../../src/snapshot/debug/profileHooks'; +import { useState } from '../../../src/index'; +import { + COMPONENT, + DIFF, + DIFF2, + DIFFED, + HOOKS, + LIST, + RENDER, + VNODE, +} from '../../../src/snapshot/renderToOpcodes/constants'; describe('profile', () => { let scratch; diff --git a/packages/react/runtime/__test__/debug/react-hooks-profile.test.jsx b/packages/react/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx similarity index 97% rename from packages/react/runtime/__test__/debug/react-hooks-profile.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx index 57d260a7eb..14cd6f6a91 100644 --- a/packages/react/runtime/__test__/debug/react-hooks-profile.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx @@ -6,8 +6,8 @@ import { render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { setupDocument } from '../../src/document'; -import { setupPage, snapshotInstanceManager } from '../../src/snapshot'; +import { setupDocument } from '../../../src/document'; +import { setupPage, snapshotInstanceManager } from '../../../src/snapshot'; import { elementTree } from '../utils/nativeMethod'; import { globalEnvManager } from '../utils/envManager'; @@ -16,7 +16,7 @@ async function importHooksWithProfileRecording(isRecording) { lynx.performance.isProfileRecording = vi.fn(() => isRecording); vi.resetModules(); try { - return await import('../../src/hooks/react'); + return await import('../../../src/snapshot/hooks/react'); } finally { lynx.performance.isProfileRecording = original; } diff --git a/packages/react/runtime/__test__/debug/set-state-in-ctor.test.jsx b/packages/react/runtime/__test__/snapshot/debug/set-state-in-ctor.test.jsx similarity index 92% rename from packages/react/runtime/__test__/debug/set-state-in-ctor.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/set-state-in-ctor.test.jsx index f5c1cc2bd8..5d2e62fd4c 100644 --- a/packages/react/runtime/__test__/debug/set-state-in-ctor.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/set-state-in-ctor.test.jsx @@ -6,7 +6,7 @@ test('preact/debug - this.setState in constructor', async () => { const consoleWarn = vi.spyOn(console, 'warn'); await import('preact/debug'); - const { root, Component } = await import('../../src/index'); + const { root, Component } = await import('../../../src/index'); class Bar extends Component { constructor(props) { diff --git a/packages/react/runtime/__test__/debug/too-many-rerenders.test.jsx b/packages/react/runtime/__test__/snapshot/debug/too-many-rerenders.test.jsx similarity index 91% rename from packages/react/runtime/__test__/debug/too-many-rerenders.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/too-many-rerenders.test.jsx index 559924d4d6..24601b4bea 100644 --- a/packages/react/runtime/__test__/debug/too-many-rerenders.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/too-many-rerenders.test.jsx @@ -5,7 +5,7 @@ test('preact/debug - Too many re-renders', async () => { .stubGlobal('__LEPUS__', false); await import('preact/debug'); - const { root, useState } = await import('../../src/index'); + const { root, useState } = await import('../../../src/index'); function Bar() { const [cnt, setCnt] = useState(0); diff --git a/packages/react/runtime/__test__/debug/undefined-component.test.jsx b/packages/react/runtime/__test__/snapshot/debug/undefined-component.test.jsx similarity index 93% rename from packages/react/runtime/__test__/debug/undefined-component.test.jsx rename to packages/react/runtime/__test__/snapshot/debug/undefined-component.test.jsx index 997c5b6139..ddfbb96df6 100644 --- a/packages/react/runtime/__test__/debug/undefined-component.test.jsx +++ b/packages/react/runtime/__test__/snapshot/debug/undefined-component.test.jsx @@ -5,7 +5,7 @@ test('preact/debug - Undefined component passed to createElement()', async () => .stubGlobal('__LEPUS__', false); await import('preact/debug'); - const { root } = await import('../../src/index'); + const { root } = await import('../../../src/index'); const a = { b: undefined }; diff --git a/packages/react/runtime/__test__/debug/vnodeSource.test.ts b/packages/react/runtime/__test__/snapshot/debug/vnodeSource.test.ts similarity index 96% rename from packages/react/runtime/__test__/debug/vnodeSource.test.ts rename to packages/react/runtime/__test__/snapshot/debug/vnodeSource.test.ts index 7d8557786e..b76a663833 100644 --- a/packages/react/runtime/__test__/debug/vnodeSource.test.ts +++ b/packages/react/runtime/__test__/snapshot/debug/vnodeSource.test.ts @@ -11,8 +11,8 @@ import { getSnapshotVNodeSource, moveSnapshotVNodeSource, setupVNodeSourceHook, -} from '../../src/debug/vnodeSource'; -import { DIFFED, DOM } from '../../src/renderToOpcodes/constants'; +} from '../../../src/snapshot/debug/vnodeSource'; +import { DIFFED, DOM } from '../../../src/snapshot/renderToOpcodes/constants'; describe('vnodeSource', () => { let originalDiffed: typeof options[typeof DIFFED]; diff --git a/packages/react/runtime/__test__/delayed-lifecycle-events.test.jsx b/packages/react/runtime/__test__/snapshot/delayed-lifecycle-events.test.jsx similarity index 83% rename from packages/react/runtime/__test__/delayed-lifecycle-events.test.jsx rename to packages/react/runtime/__test__/snapshot/delayed-lifecycle-events.test.jsx index c3684ff0b5..11951a5376 100644 --- a/packages/react/runtime/__test__/delayed-lifecycle-events.test.jsx +++ b/packages/react/runtime/__test__/snapshot/delayed-lifecycle-events.test.jsx @@ -1,11 +1,11 @@ import { describe, it, beforeEach, afterEach, vi } from 'vitest'; -import { delayedLifecycleEvents } from '../src/lifecycle/event/delayLifecycleEvents'; -import { flushDelayedLifecycleEvents } from '../src/lynx/tt'; -import { __root } from '../src/root'; +import { delayedLifecycleEvents } from '../../src/snapshot/lifecycle/event/delayLifecycleEvents'; +import { flushDelayedLifecycleEvents } from '../../src/snapshot/lynx/tt'; +import { __root } from '../../src/root'; import { globalEnvManager } from './utils/envManager'; import { expect } from 'vitest'; import { render } from 'preact'; -import { replaceCommitHook } from '../src/lifecycle/patch/commit'; +import { replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit'; beforeEach(() => { replaceCommitHook(); diff --git a/packages/react/runtime/__test__/snapshot/dynamicPartType.test.jsx b/packages/react/runtime/__test__/snapshot/dynamicPartType.test.jsx index fbf28d4d6b..edd17eb16a 100644 --- a/packages/react/runtime/__test__/snapshot/dynamicPartType.test.jsx +++ b/packages/react/runtime/__test__/snapshot/dynamicPartType.test.jsx @@ -3,15 +3,18 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import * as ReactLynx from '../../src/internal'; import { setupPage, SnapshotInstance, backgroundSnapshotInstanceManager } from '../../src/snapshot'; -import { hydrate } from '../../src/renderToOpcodes/hydrate'; -import { BackgroundSnapshotInstance, hydrate as backgroundHydrate } from '../../src/snapshot/backgroundSnapshot'; -import { __pendingListUpdates } from '../../src/list/pendingListUpdates'; -import { elementTree } from '../utils/nativeMethod'; -import { prettyFormatSnapshotPatch } from '../../src/debug/formatPatch'; -import renderToString from '../../src/renderToOpcodes'; -import { clearListGlobal, gRecycleMap, gSignMap } from '../../src/list/list'; +import { hydrate } from '../../src/snapshot/renderToOpcodes/hydrate'; +import { + BackgroundSnapshotInstance, + hydrate as backgroundHydrate, +} from '../../src/snapshot/snapshot/backgroundSnapshot'; +import { __pendingListUpdates } from '../../src/snapshot/list/pendingListUpdates'; +import { elementTree } from './utils/nativeMethod'; +import { prettyFormatSnapshotPatch } from '../../src/snapshot/debug/formatPatch'; +import renderToString from '../../src/snapshot/renderToOpcodes'; +import { clearListGlobal, gRecycleMap, gSignMap } from '../../src/snapshot/list/list'; import { jsx } from '../../lepus/jsx-runtime'; -import { globalEnvManager } from '../utils/envManager'; +import { globalEnvManager } from './utils/envManager'; const HOLE = null; diff --git a/packages/react/runtime/__test__/element.test.jsx b/packages/react/runtime/__test__/snapshot/element.test.jsx similarity index 95% rename from packages/react/runtime/__test__/element.test.jsx rename to packages/react/runtime/__test__/snapshot/element.test.jsx index d8966f4e01..cdfb2419a2 100644 --- a/packages/react/runtime/__test__/element.test.jsx +++ b/packages/react/runtime/__test__/snapshot/element.test.jsx @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it } from 'vitest'; -import { BackgroundSnapshotInstance } from '../src/snapshot'; +import { BackgroundSnapshotInstance } from '../../src/snapshot'; describe('BackgroundSnapshotInstance', () => { let root, child1, child2, child3; diff --git a/packages/react/runtime/__test__/snapshot/event.test.jsx b/packages/react/runtime/__test__/snapshot/event.test.jsx index d135bdd145..ad89d9089e 100644 --- a/packages/react/runtime/__test__/snapshot/event.test.jsx +++ b/packages/react/runtime/__test__/snapshot/event.test.jsx @@ -6,17 +6,17 @@ import { render } from 'preact'; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { delayedLifecycleEvents } from '../../src/lifecycle/event/delayLifecycleEvents'; -import { takeGlobalSnapshotPatch } from '../../src/lifecycle/patch/snapshotPatch'; -import { snapshotPatchApply } from '../../src/lifecycle/patch/snapshotPatchApply'; -import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; -import { injectTt } from '../../src/lynx/tt'; +import { delayedLifecycleEvents } from '../../src/snapshot/lifecycle/event/delayLifecycleEvents'; +import { takeGlobalSnapshotPatch } from '../../src/snapshot/lifecycle/patch/snapshotPatch'; +import { snapshotPatchApply } from '../../src/snapshot/lifecycle/patch/snapshotPatchApply'; +import { injectUpdateMainThread } from '../../src/snapshot/lifecycle/patch/updateMainThread'; +import { injectTt } from '../../src/snapshot/lynx/tt'; import { root } from '../../src/lynx-api'; -import { CHILDREN } from '../../src/renderToOpcodes/constants'; +import { CHILDREN } from '../../src/snapshot/renderToOpcodes/constants'; import { __root } from '../../src/root'; import { setupPage, backgroundSnapshotInstanceManager } from '../../src/snapshot'; -import { globalEnvManager } from '../utils/envManager'; -import { elementTree } from '../utils/nativeMethod'; +import { globalEnvManager } from './utils/envManager'; +import { elementTree } from './utils/nativeMethod'; beforeAll(() => { setupPage(__CreatePage('0', 0)); diff --git a/packages/react/runtime/__test__/snapshot/gesture.test.jsx b/packages/react/runtime/__test__/snapshot/gesture.test.jsx index 8cb1b0adf5..6dda59d405 100644 --- a/packages/react/runtime/__test__/snapshot/gesture.test.jsx +++ b/packages/react/runtime/__test__/snapshot/gesture.test.jsx @@ -1,12 +1,12 @@ import { render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; +import { replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit'; +import { injectUpdateMainThread } from '../../src/snapshot/lifecycle/patch/updateMainThread'; import { __root } from '../../src/root'; import { setupPage } from '../../src/snapshot'; -import { globalEnvManager } from '../utils/envManager'; -import { elementTree } from '../utils/nativeMethod'; +import { globalEnvManager } from './utils/envManager'; +import { elementTree } from './utils/nativeMethod'; beforeAll(() => { setupPage(__CreatePage('0', 0)); diff --git a/packages/react/runtime/__test__/gesture/processGesture.test.ts b/packages/react/runtime/__test__/snapshot/gesture/processGesture.test.ts similarity index 99% rename from packages/react/runtime/__test__/gesture/processGesture.test.ts rename to packages/react/runtime/__test__/snapshot/gesture/processGesture.test.ts index 8eda850d23..2d29953446 100644 --- a/packages/react/runtime/__test__/gesture/processGesture.test.ts +++ b/packages/react/runtime/__test__/snapshot/gesture/processGesture.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { processGesture } from '../../src/gesture/processGesture.js'; +import { processGesture } from '../../../src/snapshot/gesture/processGesture.js'; function createSerializedGesture(id: number) { return { diff --git a/packages/react/runtime/__test__/hooks/mainThread.test.tsx b/packages/react/runtime/__test__/snapshot/hooks/mainThread.test.tsx similarity index 95% rename from packages/react/runtime/__test__/hooks/mainThread.test.tsx rename to packages/react/runtime/__test__/snapshot/hooks/mainThread.test.tsx index 19f368de43..1bd26b8da4 100644 --- a/packages/react/runtime/__test__/hooks/mainThread.test.tsx +++ b/packages/react/runtime/__test__/snapshot/hooks/mainThread.test.tsx @@ -8,9 +8,9 @@ import { describe } from 'vitest'; import { it } from 'vitest'; import { expect } from 'vitest'; import { beforeAll } from 'vitest'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; +import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit'; import { elementTree } from '../utils/nativeMethod'; -import { __root } from '../../src/root'; +import { __root } from '../../../src/root'; import { useState, useMemo, @@ -23,9 +23,9 @@ import { useId, useErrorBoundary, useContext, -} from '../../src/hooks/mainThread'; +} from '../../../src/snapshot/hooks/mainThread'; import { options, createContext } from 'preact'; -import { HOOK } from '../../src/renderToOpcodes/constants.js'; +import { HOOK } from '../../../src/snapshot/renderToOpcodes/constants.js'; beforeAll(() => { replaceCommitHook(); diff --git a/packages/react/runtime/__test__/hooks/useLynxGlobalEventListener.test.jsx b/packages/react/runtime/__test__/snapshot/hooks/useLynxGlobalEventListener.test.jsx similarity index 96% rename from packages/react/runtime/__test__/hooks/useLynxGlobalEventListener.test.jsx rename to packages/react/runtime/__test__/snapshot/hooks/useLynxGlobalEventListener.test.jsx index f586d35c87..3a1bb319e7 100644 --- a/packages/react/runtime/__test__/hooks/useLynxGlobalEventListener.test.jsx +++ b/packages/react/runtime/__test__/snapshot/hooks/useLynxGlobalEventListener.test.jsx @@ -9,14 +9,14 @@ import { render } from 'preact'; import { useState } from 'preact/compat'; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { setupBackgroundDocument } from '../../src/document'; -import { useLynxGlobalEventListener } from '../../src/lynx-api'; +import { setupBackgroundDocument } from '../../../src/document'; +import { useLynxGlobalEventListener } from '../../../src/lynx-api'; import { BackgroundSnapshotInstance, backgroundSnapshotInstanceManager, SnapshotInstance, setupPage, -} from '../../src/snapshot'; +} from '../../../src/snapshot'; import { backgroundSnapshotInstanceToJSON } from '../utils/debug.js'; import { elementTree } from '../utils/nativeMethod'; diff --git a/packages/react/runtime/__test__/hydrate.test.jsx b/packages/react/runtime/__test__/snapshot/hydrate.test.jsx similarity index 99% rename from packages/react/runtime/__test__/hydrate.test.jsx rename to packages/react/runtime/__test__/snapshot/hydrate.test.jsx index eebfd692cf..ea61c2ec3a 100644 --- a/packages/react/runtime/__test__/hydrate.test.jsx +++ b/packages/react/runtime/__test__/snapshot/hydrate.test.jsx @@ -6,7 +6,7 @@ import { backgroundSnapshotInstanceManager, BackgroundSnapshotInstance, hydrate, -} from '../src/snapshot'; +} from '../../src/snapshot'; const HOLE = null; diff --git a/packages/react/runtime/__test__/lazy.test.js b/packages/react/runtime/__test__/snapshot/lazy.test.js similarity index 79% rename from packages/react/runtime/__test__/lazy.test.js rename to packages/react/runtime/__test__/snapshot/lazy.test.js index c058f63ff9..350cb4013e 100644 --- a/packages/react/runtime/__test__/lazy.test.js +++ b/packages/react/runtime/__test__/snapshot/lazy.test.js @@ -1,13 +1,13 @@ -import '../lazy/import.js'; +import '../../lazy/import.js'; import { describe, expect, test, vi } from 'vitest'; -import * as ReactExports from '../lazy/react.js'; -import * as ReactCompatExports from '../lazy/compat.js'; -import * as ReactLepusExports from '../lazy/react-lepus.js'; -import * as ReactInternalExports from '../lazy/internal.js'; -import * as ReactJSXRuntimeExports from '../lazy/jsx-runtime.js'; -import * as ReactJSXDevRuntimeExports from '../lazy/jsx-dev-runtime.js'; -import * as ReactLegacyReactRuntimeExports from '../lazy/legacy-react-runtime.js'; +import * as ReactExports from '../../lazy/react.js'; +import * as ReactCompatExports from '../../lazy/compat.js'; +import * as ReactLepusExports from '../../lazy/react-lepus.js'; +import * as ReactInternalExports from '../../lazy/internal.js'; +import * as ReactJSXRuntimeExports from '../../lazy/jsx-runtime.js'; +import * as ReactJSXDevRuntimeExports from '../../lazy/jsx-dev-runtime.js'; +import * as ReactLegacyReactRuntimeExports from '../../lazy/legacy-react-runtime.js'; describe('Lazy Exports', () => { test('export APIs from "react"', async () => { @@ -108,7 +108,7 @@ describe('Lazy Exports', () => { vi.stubGlobal('lynx', lynx); vi.stubGlobal('__LEPUS__', false); - const { target } = await import('../lazy/target.js'); + const { target } = await import('../../lazy/target.js'); expect(target).toBe(lynx); }); @@ -117,7 +117,7 @@ describe('Lazy Exports', () => { vi.stubGlobal('__LEPUS__', true); - const { target } = await import('../lazy/target.js'); + const { target } = await import('../../lazy/target.js'); expect(target).toBe(globalThis); }); }); diff --git a/packages/react/runtime/__test__/lifecycle.test.jsx b/packages/react/runtime/__test__/snapshot/lifecycle.test.jsx similarity index 97% rename from packages/react/runtime/__test__/lifecycle.test.jsx rename to packages/react/runtime/__test__/snapshot/lifecycle.test.jsx index ea8b6ed70a..3859abf291 100644 --- a/packages/react/runtime/__test__/lifecycle.test.jsx +++ b/packages/react/runtime/__test__/snapshot/lifecycle.test.jsx @@ -1,15 +1,15 @@ import { Component, options, render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { useEffect, useLayoutEffect, useState } from '../src/index'; +import { useEffect, useLayoutEffect, useState } from '../../src/index'; import { globalEnvManager } from './utils/envManager'; import { waitSchedule } from './utils/nativeMethod'; -import { globalCommitTaskMap, replaceCommitHook } from '../src/lifecycle/patch/commit'; -import { deinitGlobalSnapshotPatch, initGlobalSnapshotPatch } from '../src/lifecycle/patch/snapshotPatch'; -import { LifecycleConstant } from '../src/lifecycle/constant'; -import { CATCH_ERROR } from '../src/renderToOpcodes/constants'; -import { __root } from '../src/root'; -import { setupPage, backgroundSnapshotInstanceManager } from '../src/snapshot'; +import { globalCommitTaskMap, replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit'; +import { deinitGlobalSnapshotPatch, initGlobalSnapshotPatch } from '../../src/snapshot/lifecycle/patch/snapshotPatch'; +import { LifecycleConstant } from '../../src/snapshot/lifecycle/constant'; +import { CATCH_ERROR } from '../../src/snapshot/renderToOpcodes/constants'; +import { __root } from '../../src/root'; +import { setupPage, backgroundSnapshotInstanceManager } from '../../src/snapshot'; beforeAll(() => { setupPage(__CreatePage('0', 0)); diff --git a/packages/react/runtime/__test__/lifecycle/destroy.test.jsx b/packages/react/runtime/__test__/snapshot/lifecycle/destroy.test.jsx similarity index 87% rename from packages/react/runtime/__test__/lifecycle/destroy.test.jsx rename to packages/react/runtime/__test__/snapshot/lifecycle/destroy.test.jsx index 517a1a0c24..7e50173d07 100644 --- a/packages/react/runtime/__test__/lifecycle/destroy.test.jsx +++ b/packages/react/runtime/__test__/snapshot/lifecycle/destroy.test.jsx @@ -16,13 +16,13 @@ describe('Destroy', () => { test('should remove event listener when throw in cleanup', async function() { vi.resetModules(); - await import('../../src/lynx'); + await import('../../../src/lynx'); expect(addEventListener).toHaveBeenCalled(); expect(removeEventListener).toHaveBeenCalledTimes(0); - const { useEffect } = await import('../../src/index'); - const { __root } = await import('../../src/root'); + const { useEffect } = await import('../../../src/index'); + const { __root } = await import('../../../src/root'); const callback = vi.fn().mockImplementation(() => { throw '???'; diff --git a/packages/react/runtime/__test__/lifecycle/isRendering.test.jsx b/packages/react/runtime/__test__/snapshot/lifecycle/isRendering.test.jsx similarity index 87% rename from packages/react/runtime/__test__/lifecycle/isRendering.test.jsx rename to packages/react/runtime/__test__/snapshot/lifecycle/isRendering.test.jsx index e418c83f45..02ea89da97 100644 --- a/packages/react/runtime/__test__/lifecycle/isRendering.test.jsx +++ b/packages/react/runtime/__test__/snapshot/lifecycle/isRendering.test.jsx @@ -5,15 +5,15 @@ import { useState } from 'preact/hooks'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; -import { root } from '../../src/lynx-api'; -import '../../src/lynx/component'; -import { __root } from '../../src/root'; -import { setupPage } from '../../src/snapshot'; +import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit'; +import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread'; +import { root } from '../../../src/lynx-api'; +import '../../../src/snapshot/lynx/component'; +import { __root } from '../../../src/root'; +import { setupPage } from '../../../src/snapshot'; import { globalEnvManager } from '../utils/envManager'; import { elementTree, waitSchedule } from '../utils/nativeMethod'; -import { isRendering } from '../../src/lifecycle/isRendering'; +import { isRendering } from '../../../src/snapshot/lifecycle/isRendering'; beforeAll(() => { setupPage(__CreatePage('0', 0)); diff --git a/packages/react/runtime/__test__/lifecycle/reload.test.jsx b/packages/react/runtime/__test__/snapshot/lifecycle/reload.test.jsx similarity index 99% rename from packages/react/runtime/__test__/lifecycle/reload.test.jsx rename to packages/react/runtime/__test__/snapshot/lifecycle/reload.test.jsx index c5d8ae20e3..7b0710e886 100644 --- a/packages/react/runtime/__test__/lifecycle/reload.test.jsx +++ b/packages/react/runtime/__test__/snapshot/lifecycle/reload.test.jsx @@ -8,13 +8,13 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } import { BasicBG, ListBG, ListConditionalBG, ViewBG, setObj, setStr } from './reloadBG'; import { BasicMT, ListConditionalMT, ListMT, ViewMT } from './reloadMT'; -import { root } from '../../src/index'; -import { delayedEvents, delayedPublishEvent } from '../../src/lifecycle/event/delayEvents'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; -import { reloadBackground } from '../../src/lifecycle/reload'; -import { __root } from '../../src/root'; -import { setupPage } from '../../src/snapshot'; +import { root } from '../../../src/index'; +import { delayedEvents, delayedPublishEvent } from '../../../src/snapshot/lifecycle/event/delayEvents'; +import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit'; +import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread'; +import { reloadBackground } from '../../../src/snapshot/lifecycle/reload'; +import { __root } from '../../../src/root'; +import { setupPage } from '../../../src/snapshot'; import { globalEnvManager } from '../utils/envManager'; import { elementTree, waitSchedule } from '../utils/nativeMethod'; diff --git a/packages/react/runtime/__test__/lifecycle/reloadBG.jsx b/packages/react/runtime/__test__/snapshot/lifecycle/reloadBG.jsx similarity index 97% rename from packages/react/runtime/__test__/lifecycle/reloadBG.jsx rename to packages/react/runtime/__test__/snapshot/lifecycle/reloadBG.jsx index e7f658cfd9..f9a6d73a3c 100644 --- a/packages/react/runtime/__test__/lifecycle/reloadBG.jsx +++ b/packages/react/runtime/__test__/snapshot/lifecycle/reloadBG.jsx @@ -3,7 +3,7 @@ // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. */ -import { useState } from '../../src/index'; +import { useState } from '../../../src/index'; export let setStr; export let setObj; diff --git a/packages/react/runtime/__test__/lifecycle/reloadMT.jsx b/packages/react/runtime/__test__/snapshot/lifecycle/reloadMT.jsx similarity index 94% rename from packages/react/runtime/__test__/lifecycle/reloadMT.jsx rename to packages/react/runtime/__test__/snapshot/lifecycle/reloadMT.jsx index 1bce6d8e37..1af20aa040 100644 --- a/packages/react/runtime/__test__/lifecycle/reloadMT.jsx +++ b/packages/react/runtime/__test__/snapshot/lifecycle/reloadMT.jsx @@ -4,9 +4,9 @@ // LICENSE file in the root directory of this source tree. */ -/** @jsxImportSource ../../lepus */ +/** @jsxImportSource ../../../lepus */ -import { useState } from '../../src/index'; +import { useState } from '../../../src/index'; function SubCompMT(props) { return ; diff --git a/packages/react/runtime/__test__/lifecycle/updateData.test.jsx b/packages/react/runtime/__test__/snapshot/lifecycle/updateData.test.jsx similarity index 98% rename from packages/react/runtime/__test__/lifecycle/updateData.test.jsx rename to packages/react/runtime/__test__/snapshot/lifecycle/updateData.test.jsx index d83897fd43..b20751d3e6 100644 --- a/packages/react/runtime/__test__/lifecycle/updateData.test.jsx +++ b/packages/react/runtime/__test__/snapshot/lifecycle/updateData.test.jsx @@ -5,11 +5,11 @@ import { Component, render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { deinitGlobalSnapshotPatch } from '../../src/lifecycle/patch/snapshotPatch'; -import { InitDataConsumer, InitDataProvider, useInitData, withInitDataInState } from '../../src/lynx-api'; -import { useState } from '../../src/index'; -import { __root } from '../../src/root'; +import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit'; +import { deinitGlobalSnapshotPatch } from '../../../src/snapshot/lifecycle/patch/snapshotPatch'; +import { InitDataConsumer, InitDataProvider, useInitData, withInitDataInState } from '../../../src/lynx-api'; +import { useState } from '../../../src/index'; +import { __root } from '../../../src/root'; import { globalEnvManager } from '../utils/envManager'; import { elementTree, waitSchedule } from '../utils/nativeMethod'; diff --git a/packages/react/runtime/__test__/lifecycle/updateGlobalProps.test.jsx b/packages/react/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx similarity index 98% rename from packages/react/runtime/__test__/lifecycle/updateGlobalProps.test.jsx rename to packages/react/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx index 8f7561b6bb..380596045f 100644 --- a/packages/react/runtime/__test__/lifecycle/updateGlobalProps.test.jsx +++ b/packages/react/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx @@ -10,9 +10,9 @@ import { expect } from 'vitest'; import { render } from 'preact'; import { waitSchedule } from '../utils/nativeMethod'; import { beforeAll } from 'vitest'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; +import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit'; import { elementTree } from '../utils/nativeMethod'; -import { __root } from '../../src/root'; +import { __root } from '../../../src/root'; beforeAll(() => { replaceCommitHook(); @@ -114,7 +114,7 @@ describe('updateGlobalProps', () => { it('should update global props once when use useGlobalProps and get warning', async () => { vi.spyOn(console, 'warn').mockImplementation(() => {}); - const { useGlobalProps } = await import('../../src/lynx-api'); + const { useGlobalProps } = await import('../../../src/lynx-api'); const Comp = () => { const globalProps = useGlobalProps(); return {globalProps.theme}; @@ -199,7 +199,7 @@ describe('updateGlobalProps', () => { it('should update global props once when use GlobalPropsConsumer / GlobalPropsProvider and get warning', async () => { vi.spyOn(console, 'warn').mockImplementation(() => {}); - const { GlobalPropsProvider, GlobalPropsConsumer, useGlobalPropsChanged } = await import('../../src/lynx-api'); + const { GlobalPropsProvider, GlobalPropsConsumer, useGlobalPropsChanged } = await import('../../../src/lynx-api'); let count = 0; let dataTheme, globalPropsTheme; const Comp = () => { @@ -375,7 +375,7 @@ describe('updateGlobalProps', () => { it('should trigger re-render when useGlobalProps is called', async () => { globalThis.__GLOBAL_PROPS_MODE__ = 'event'; const { useGlobalProps, useGlobalPropsChanged, GlobalPropsProvider, GlobalPropsConsumer } = await import( - '../../src/lynx-api' + '../../../src/lynx-api' ); lynx.__globalProps = { theme: 'dark' }; @@ -465,7 +465,7 @@ describe('updateGlobalProps', () => { it('should trigger update when GlobalPropsProvider and useGlobalProps are used', async () => { globalThis.__GLOBAL_PROPS_MODE__ = 'event'; const { useGlobalProps, useGlobalPropsChanged, GlobalPropsProvider, GlobalPropsConsumer } = await import( - '../../src/lynx-api' + '../../../src/lynx-api' ); lynx.__globalProps = { theme: 'dark' }; diff --git a/packages/react/runtime/__test__/list.test.jsx b/packages/react/runtime/__test__/snapshot/list.test.jsx similarity index 99% rename from packages/react/runtime/__test__/list.test.jsx rename to packages/react/runtime/__test__/snapshot/list.test.jsx index 600daae508..a6373e78c0 100644 --- a/packages/react/runtime/__test__/list.test.jsx +++ b/packages/react/runtime/__test__/snapshot/list.test.jsx @@ -1,13 +1,13 @@ -/** @jsxImportSource ../lepus */ +/** @jsxImportSource ../../lepus */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { elementTree, nativeMethodQueue } from './utils/nativeMethod'; -import { hydrate } from '../src/renderToOpcodes/hydrate'; -import { __pendingListUpdates } from '../src/list/pendingListUpdates'; -import { SnapshotInstance, snapshotInstanceManager } from '../src/snapshot'; -import { __root } from '../src/root'; +import { hydrate } from '../../src/snapshot/renderToOpcodes/hydrate'; +import { __pendingListUpdates } from '../../src/snapshot/list/pendingListUpdates'; +import { SnapshotInstance, snapshotInstanceManager } from '../../src/snapshot'; +import { __root } from '../../src/root'; import { globalEnvManager } from './utils/envManager'; -import { gRecycleMap, gSignMap } from '../src/list/list'; +import { gRecycleMap, gSignMap } from '../../src/snapshot/list/list'; const HOLE = null; diff --git a/packages/react/runtime/__test__/lynx/injectLepusMethods.test.jsx b/packages/react/runtime/__test__/snapshot/lynx/injectLepusMethods.test.jsx similarity index 90% rename from packages/react/runtime/__test__/lynx/injectLepusMethods.test.jsx rename to packages/react/runtime/__test__/snapshot/lynx/injectLepusMethods.test.jsx index c1f3ed4ec4..09612f9a06 100644 --- a/packages/react/runtime/__test__/lynx/injectLepusMethods.test.jsx +++ b/packages/react/runtime/__test__/snapshot/lynx/injectLepusMethods.test.jsx @@ -1,10 +1,10 @@ import { Component, h, options, render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { setupPage } from '../../src/snapshot'; +import { setupPage } from '../../../src/snapshot'; import { globalEnvManager } from '../utils/envManager'; import { elementTree, waitSchedule } from '../utils/nativeMethod'; -import { __root } from '../../src/root'; -import { injectLepusMethods } from '../../src/lynx/injectLepusMethods'; +import { __root } from '../../../src/root'; +import { injectLepusMethods } from '../../../src/snapshot/lynx/injectLepusMethods'; beforeAll(() => { setupPage(__CreatePage('0', 0)); diff --git a/packages/react/runtime/__test__/lynx/lazy-bundle.test.js b/packages/react/runtime/__test__/snapshot/lynx/lazy-bundle.test.js similarity index 90% rename from packages/react/runtime/__test__/lynx/lazy-bundle.test.js rename to packages/react/runtime/__test__/snapshot/lynx/lazy-bundle.test.js index 5764ba6c35..740462f72c 100644 --- a/packages/react/runtime/__test__/lynx/lazy-bundle.test.js +++ b/packages/react/runtime/__test__/snapshot/lynx/lazy-bundle.test.js @@ -20,7 +20,7 @@ describe('loadLazyBundle', () => { }); test('should have lynx.loadLazyBundle', async () => { - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); expect(lynx.loadLazyBundle).toBe(loadLazyBundle); }); @@ -30,7 +30,7 @@ describe('loadLazyBundle', () => { __QueryComponent.mockReturnValueOnce({ evalResult: { data: 'foo' } }); vi.stubGlobal('__QueryComponent', __QueryComponent); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -59,7 +59,7 @@ describe('loadLazyBundle', () => { __QueryComponent.mockReturnValueOnce({ evalResult: { data: 'foo' } }); vi.stubGlobal('__QueryComponent', __QueryComponent); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -87,7 +87,7 @@ describe('loadLazyBundle', () => { __QueryComponent.mockReturnValueOnce({ evalResult: { data: 'foo' } }); vi.stubGlobal('__QueryComponent', __QueryComponent); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -108,7 +108,7 @@ describe('loadLazyBundle', () => { __QueryComponent.mockReturnValueOnce({ evalResult: { data: 'foo' } }); vi.stubGlobal('__QueryComponent', __QueryComponent); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -151,7 +151,7 @@ describe('loadLazyBundle', () => { __QueryComponent.mockReturnValueOnce({ evalResult: { data: 'foo' } }); vi.stubGlobal('__QueryComponent', __QueryComponent); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -177,7 +177,7 @@ describe('loadLazyBundle', () => { __QueryComponent.mockReturnValueOnce(undefined); vi.stubGlobal('__QueryComponent', __QueryComponent); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -222,7 +222,7 @@ describe('loadLazyBundle', () => { callback({ code: 0, detail: { schema: source } }); }); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -243,7 +243,7 @@ describe('loadLazyBundle', () => { callback({ code: 1, detail: { errMsg: 'error', schema: source } }); }); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -276,7 +276,7 @@ describe('loadLazyBundle', () => { callback({ code: 0, detail: { schema: source } }); }); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -311,7 +311,7 @@ describe('loadLazyBundle', () => { callback({ code: 0, detail: { schema: source } }); }); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -346,7 +346,7 @@ describe('loadLazyBundle', () => { callback({ code: 0, detail: { schema: source } }); }); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -387,7 +387,7 @@ describe('loadLazyBundle', () => { callback({ code: 0, detail: { schema: source } }); }); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -415,7 +415,7 @@ describe('loadLazyBundle', () => { }); }); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -451,7 +451,7 @@ describe('loadLazyBundle', () => { }); }); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -492,7 +492,7 @@ describe('loadLazyBundle', () => { }); }); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -536,7 +536,7 @@ describe('loadLazyBundle', () => { callback({ code: 0, detail: { schema: source } }); }); vi.stubGlobal('lynx', { getNativeLynx: () => ({ QueryComponent }) }); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); const promise = loadLazyBundle('foo'); @@ -560,7 +560,7 @@ describe('loadLazyBundle', () => { .stubGlobal('__MAIN_THREAD__', false) .stubGlobal('__LEPUS__', false); - const { loadLazyBundle } = await import('../../src/lynx/lazy-bundle'); + const { loadLazyBundle } = await import('../../../src/snapshot/lynx/lazy-bundle'); expect(() => loadLazyBundle()).toThrowErrorMatchingInlineSnapshot(`[Error: unreachable]`); }); diff --git a/packages/react/runtime/__test__/lynx/processEvalResult.test.js b/packages/react/runtime/__test__/snapshot/lynx/processEvalResult.test.js similarity index 93% rename from packages/react/runtime/__test__/lynx/processEvalResult.test.js rename to packages/react/runtime/__test__/snapshot/lynx/processEvalResult.test.js index 530d546676..c9eb64d110 100644 --- a/packages/react/runtime/__test__/lynx/processEvalResult.test.js +++ b/packages/react/runtime/__test__/snapshot/lynx/processEvalResult.test.js @@ -5,7 +5,7 @@ describe('processEvalResult', () => { test('main-thread', async () => { globalEnvManager.switchToMainThread(); - await import('../../src/index.ts'); + await import('../../../src/index.ts'); expect(processEvalResult).toStrictEqual(expect.any(Function)); diff --git a/packages/react/runtime/__test__/lynx/suspense.test.jsx b/packages/react/runtime/__test__/snapshot/lynx/suspense.test.jsx similarity index 99% rename from packages/react/runtime/__test__/lynx/suspense.test.jsx rename to packages/react/runtime/__test__/snapshot/lynx/suspense.test.jsx index 2f777ceef5..6722cf8ee9 100644 --- a/packages/react/runtime/__test__/lynx/suspense.test.jsx +++ b/packages/react/runtime/__test__/snapshot/lynx/suspense.test.jsx @@ -4,23 +4,23 @@ import { render, Component } from 'preact'; import { createElement } from 'preact/compat'; -import { Suspense, lazy, useState } from '../../src/index'; +import { Suspense, lazy, useState } from '../../../src/index'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; -import '../../src/lynx/component'; -import { __root } from '../../src/root'; +import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit'; +import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread'; +import '../../../src/snapshot/lynx/component'; +import { __root } from '../../../src/root'; import { setupPage, SnapshotInstance, snapshotInstanceManager, BackgroundSnapshotInstance, backgroundSnapshotInstanceManager, -} from '../../src/snapshot'; +} from '../../../src/snapshot'; import { globalEnvManager } from '../utils/envManager'; import { elementTree } from '../utils/nativeMethod'; -import { prettyFormatSnapshotPatch } from '../../src/debug/formatPatch'; +import { prettyFormatSnapshotPatch } from '../../../src/snapshot/debug/formatPatch'; import { createSuspender } from '../createSuspender'; beforeAll(() => { diff --git a/packages/react/runtime/__test__/lynx/timing.test.jsx b/packages/react/runtime/__test__/snapshot/lynx/timing.test.jsx similarity index 98% rename from packages/react/runtime/__test__/lynx/timing.test.jsx rename to packages/react/runtime/__test__/snapshot/lynx/timing.test.jsx index 599a23b817..911595a503 100644 --- a/packages/react/runtime/__test__/lynx/timing.test.jsx +++ b/packages/react/runtime/__test__/snapshot/lynx/timing.test.jsx @@ -6,12 +6,12 @@ import { Component, options, render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; -import '../../src/lynx/component'; -import { initTimingAPI } from '../../src/lynx/performance'; -import { __root } from '../../src/root'; -import { setupPage } from '../../src/snapshot'; +import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit'; +import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread'; +import '../../../src/snapshot/lynx/component'; +import { initTimingAPI } from '../../../src/snapshot/lynx/performance'; +import { __root } from '../../../src/root'; +import { setupPage } from '../../../src/snapshot'; import { globalEnvManager } from '../utils/envManager'; import { elementTree, waitSchedule } from '../utils/nativeMethod'; diff --git a/packages/react/runtime/__test__/lynxQueueMicrotask.test.jsx b/packages/react/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx similarity index 88% rename from packages/react/runtime/__test__/lynxQueueMicrotask.test.jsx rename to packages/react/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx index a37084cefe..260fc02352 100644 --- a/packages/react/runtime/__test__/lynxQueueMicrotask.test.jsx +++ b/packages/react/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx @@ -13,7 +13,7 @@ describe('lynxQueueMicrotask', () => { const mockFn = vi.fn(); vi.stubGlobal('lynx', { queueMicrotask: vi.fn(fn => Promise.resolve().then(fn)) }); - const { lynxQueueMicrotask } = await import('../src/utils'); + const { lynxQueueMicrotask } = await import('../../src/utils'); lynxQueueMicrotask(mockFn); expect(lynx.queueMicrotask).toHaveBeenCalled(); @@ -27,7 +27,7 @@ describe('lynxQueueMicrotask', () => { const mockFn = vi.fn(); vi.stubGlobal('lynx', {}); - const { lynxQueueMicrotask } = await import('../src/utils'); + const { lynxQueueMicrotask } = await import('../../src/utils'); lynxQueueMicrotask(mockFn); expect(mockFn).not.toHaveBeenCalled(); diff --git a/packages/react/runtime/__test__/page.test.jsx b/packages/react/runtime/__test__/snapshot/page.test.jsx similarity index 96% rename from packages/react/runtime/__test__/page.test.jsx rename to packages/react/runtime/__test__/snapshot/page.test.jsx index 1e93e75982..ac0c11a456 100644 --- a/packages/react/runtime/__test__/page.test.jsx +++ b/packages/react/runtime/__test__/snapshot/page.test.jsx @@ -1,13 +1,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { __page } from '../src/snapshot'; +import { __page } from '../../src/snapshot'; import { globalEnvManager } from './utils/envManager'; import { elementTree, waitSchedule } from './utils/nativeMethod'; -import { useRef, useState } from '../src/index'; -import { __root } from '../src/root'; +import { useRef, useState } from '../../src/index'; +import { __root } from '../../src/root'; import { render } from 'preact'; -import { replaceCommitHook } from '../src/lifecycle/patch/commit'; -import { deinitGlobalSnapshotPatch } from '../src/lifecycle/patch/snapshotPatch'; +import { replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit'; +import { deinitGlobalSnapshotPatch } from '../../src/snapshot/lifecycle/patch/snapshotPatch'; beforeEach(() => { replaceCommitHook(); diff --git a/packages/react/runtime/__test__/preact.test.jsx b/packages/react/runtime/__test__/snapshot/preact.test.jsx similarity index 98% rename from packages/react/runtime/__test__/preact.test.jsx rename to packages/react/runtime/__test__/snapshot/preact.test.jsx index 2676da8ffe..804afa6083 100644 --- a/packages/react/runtime/__test__/preact.test.jsx +++ b/packages/react/runtime/__test__/snapshot/preact.test.jsx @@ -2,14 +2,14 @@ import { cloneElement, Component, render } from 'preact'; import { Suspense, lazy } from 'preact/compat'; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { setupBackgroundDocument, setupDocument } from '../src/document'; -import { globalBackgroundSnapshotInstancesToRemove } from '../src/lifecycle/patch/commit'; +import { setupBackgroundDocument, setupDocument } from '../../src/document'; +import { globalBackgroundSnapshotInstancesToRemove } from '../../src/snapshot/lifecycle/patch/commit'; import { deinitGlobalSnapshotPatch, initGlobalSnapshotPatch, takeGlobalSnapshotPatch, -} from '../src/lifecycle/patch/snapshotPatch'; -import { runWithForce } from '../src/lynx/tt'; +} from '../../src/snapshot/lifecycle/patch/snapshotPatch'; +import { runWithForce } from '../../src/snapshot/lynx/tt'; import { SnapshotInstance, setupPage, @@ -18,7 +18,7 @@ import { backgroundSnapshotInstanceManager, BackgroundSnapshotInstance, hydrate, -} from '../src/snapshot'; +} from '../../src/snapshot'; import { backgroundSnapshotInstanceToJSON, snapshotInstanceToJSON } from './utils/debug.js'; import { globalEnvManager } from './utils/envManager'; import { elementTree } from './utils/nativeMethod'; diff --git a/packages/react/runtime/__test__/snapshot/ref.test.jsx b/packages/react/runtime/__test__/snapshot/ref.test.jsx index 65df4044ef..3046fee74a 100644 --- a/packages/react/runtime/__test__/snapshot/ref.test.jsx +++ b/packages/react/runtime/__test__/snapshot/ref.test.jsx @@ -6,16 +6,16 @@ import { render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { RefProxy, runDelayedUiOps, shouldDelayUiOps } from '../../src/lifecycle/ref/delay'; +import { RefProxy, runDelayedUiOps, shouldDelayUiOps } from '../../src/snapshot/lifecycle/ref/delay'; import { Component, createRef, useState } from '../../src/index'; -import { clearCommitTaskId, replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; -import { __pendingListUpdates } from '../../src/list/pendingListUpdates'; +import { clearCommitTaskId, replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit'; +import { injectUpdateMainThread } from '../../src/snapshot/lifecycle/patch/updateMainThread'; +import { __pendingListUpdates } from '../../src/snapshot/list/pendingListUpdates'; import { __root } from '../../src/root'; import { setupPage } from '../../src/snapshot'; -import { globalEnvManager } from '../utils/envManager'; -import { elementTree, waitSchedule } from '../utils/nativeMethod'; +import { globalEnvManager } from './utils/envManager'; +import { elementTree, waitSchedule } from './utils/nativeMethod'; beforeAll(() => { setupPage(__CreatePage('0', 0)); diff --git a/packages/react/runtime/__test__/render.test.jsx b/packages/react/runtime/__test__/snapshot/render.test.jsx similarity index 87% rename from packages/react/runtime/__test__/render.test.jsx rename to packages/react/runtime/__test__/snapshot/render.test.jsx index e8608d2508..b5efa2a075 100644 --- a/packages/react/runtime/__test__/render.test.jsx +++ b/packages/react/runtime/__test__/snapshot/render.test.jsx @@ -5,16 +5,16 @@ import { render, Component, process } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { replaceCommitHook } from '../src/lifecycle/patch/commit'; -import { injectUpdateMainThread } from '../src/lifecycle/patch/updateMainThread'; -import '../src/lynx/component'; -import { __root } from '../src/root'; -import { setupPage, SnapshotInstance, snapshotInstanceManager } from '../src/snapshot'; +import { replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit'; +import { injectUpdateMainThread } from '../../src/snapshot/lifecycle/patch/updateMainThread'; +import '../../src/snapshot/lynx/component'; +import { __root } from '../../src/root'; +import { setupPage, SnapshotInstance, snapshotInstanceManager } from '../../src/snapshot'; import { globalEnvManager } from './utils/envManager'; import { elementTree } from './utils/nativeMethod'; -import { backgroundSnapshotInstanceManager } from '../src/backgroundSnapshot'; -import { prettyFormatSnapshotPatch } from '../src/debug/formatPatch'; -import { root } from '../src/lynx-api'; +import { backgroundSnapshotInstanceManager } from '../../src/snapshot/snapshot/backgroundSnapshot'; +import { prettyFormatSnapshotPatch } from '../../src/snapshot/debug/formatPatch'; +import { root } from '../../src/lynx-api'; import { waitSchedule } from './utils/nativeMethod'; beforeAll(() => { diff --git a/packages/react/runtime/__test__/renderToOpcodes.test.jsx b/packages/react/runtime/__test__/snapshot/renderToOpcodes.test.jsx similarity index 99% rename from packages/react/runtime/__test__/renderToOpcodes.test.jsx rename to packages/react/runtime/__test__/snapshot/renderToOpcodes.test.jsx index d63768db5c..2942649006 100644 --- a/packages/react/runtime/__test__/renderToOpcodes.test.jsx +++ b/packages/react/runtime/__test__/snapshot/renderToOpcodes.test.jsx @@ -1,4 +1,4 @@ -/** @jsxImportSource ../lepus */ +/** @jsxImportSource ../../lepus */ import { Component, createContext, Fragment } from 'preact'; import { useMemo, useState } from 'preact/hooks'; @@ -6,14 +6,14 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite import { elementTree, waitSchedule } from './utils/nativeMethod'; import { globalEnvManager } from './utils/envManager'; -import { setupDocument } from '../src/document'; -// import { renderOpcodesInto } from '../src/opcodes'; -import renderToStringBase from '../src/renderToOpcodes'; -import { setupPage, SnapshotInstance, snapshotInstanceManager } from '../src/snapshot'; -import { createElement, cloneElement } from '../lepus'; +import { setupDocument } from '../../src/document'; +// import { renderOpcodesInto } from '../../src/opcodes'; +import renderToStringBase from '../../src/snapshot/renderToOpcodes'; +import { setupPage, SnapshotInstance, snapshotInstanceManager } from '../../src/snapshot'; +import { createElement, cloneElement } from '../../lepus'; import { Suspense } from 'preact/compat'; import { createSuspender } from './createSuspender'; -import { __root } from '../src/root'; +import { __root } from '../../src/root'; const renderToString = (element, root = __root) => { return renderToStringBase(element, null, root); diff --git a/packages/react/runtime/__test__/snapshotPatch.test.jsx b/packages/react/runtime/__test__/snapshot/snapshotPatch.test.jsx similarity index 99% rename from packages/react/runtime/__test__/snapshotPatch.test.jsx rename to packages/react/runtime/__test__/snapshot/snapshotPatch.test.jsx index bfa04486c8..1c614ded36 100644 --- a/packages/react/runtime/__test__/snapshotPatch.test.jsx +++ b/packages/react/runtime/__test__/snapshot/snapshotPatch.test.jsx @@ -5,16 +5,16 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite import { globalEnvManager } from './utils/envManager'; import { elementTree } from './utils/nativeMethod'; -import { registerWorkletOnBackground } from '../src/internal'; -import { addCtxNotFoundEventListener } from '../src/lifecycle/patch/error'; +import { registerWorkletOnBackground } from '../../src/internal'; +import { addCtxNotFoundEventListener } from '../../src/snapshot/lifecycle/patch/error'; import { SnapshotOperation, __globalSnapshotPatch, deinitGlobalSnapshotPatch, initGlobalSnapshotPatch, takeGlobalSnapshotPatch, -} from '../src/lifecycle/patch/snapshotPatch'; -import { snapshotPatchApply } from '../src/lifecycle/patch/snapshotPatchApply'; +} from '../../src/snapshot/lifecycle/patch/snapshotPatch'; +import { snapshotPatchApply } from '../../src/snapshot/lifecycle/patch/snapshotPatchApply'; import { BackgroundSnapshotInstance, SnapshotInstance, @@ -22,8 +22,8 @@ import { snapshotCreatorMap, snapshotInstanceManager, snapshotManager, -} from '../src/snapshot'; -import { DynamicPartType } from '../src/snapshot/dynamicPartType'; +} from '../../src/snapshot'; +import { DynamicPartType } from '../../src/snapshot/snapshot/dynamicPartType'; const HOLE = null; diff --git a/packages/react/runtime/__test__/snapshot/spread.test.jsx b/packages/react/runtime/__test__/snapshot/spread.test.jsx index c344e36dcc..74d2825b2e 100644 --- a/packages/react/runtime/__test__/snapshot/spread.test.jsx +++ b/packages/react/runtime/__test__/snapshot/spread.test.jsx @@ -7,11 +7,11 @@ import { render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { useState } from '../../src/index'; -import { initGlobalSnapshotPatch, takeGlobalSnapshotPatch } from '../../src/lifecycle/patch/snapshotPatch'; -import { snapshotPatchApply } from '../../src/lifecycle/patch/snapshotPatchApply'; +import { initGlobalSnapshotPatch, takeGlobalSnapshotPatch } from '../../src/snapshot/lifecycle/patch/snapshotPatch'; +import { snapshotPatchApply } from '../../src/snapshot/lifecycle/patch/snapshotPatchApply'; import { setupPage, snapshotInstanceManager, hydrate, backgroundSnapshotInstanceManager } from '../../src/snapshot'; -import { globalEnvManager } from '../utils/envManager'; -import { elementTree } from '../utils/nativeMethod'; +import { globalEnvManager } from './utils/envManager'; +import { elementTree } from './utils/nativeMethod'; let scratch; let scratchBackground; diff --git a/packages/react/runtime/__test__/ssr.test.jsx b/packages/react/runtime/__test__/snapshot/ssr.test.jsx similarity index 97% rename from packages/react/runtime/__test__/ssr.test.jsx rename to packages/react/runtime/__test__/snapshot/ssr.test.jsx index 07bbffcb2f..fafebcb438 100644 --- a/packages/react/runtime/__test__/ssr.test.jsx +++ b/packages/react/runtime/__test__/snapshot/ssr.test.jsx @@ -1,13 +1,13 @@ -/** @jsxImportSource ../lepus */ +/** @jsxImportSource ../../lepus */ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { globalEnvManager } from './utils/envManager'; import { elementTree, options } from './utils/nativeMethod'; -import { __page as __internalPage } from '../src/internal'; -import { jsReadyEventIdSwap } from '../src/lifecycle/event/jsReady'; -import { __root } from '../src/root'; -import { clearPage } from '../src/snapshot'; +import { __page as __internalPage } from '../../src/internal'; +import { jsReadyEventIdSwap } from '../../src/snapshot/lifecycle/event/jsReady'; +import { __root } from '../../src/root'; +import { clearPage } from '../../src/snapshot'; const ssrIDMap = new Map(); diff --git a/packages/react/runtime/__test__/utils/debug.js b/packages/react/runtime/__test__/snapshot/utils/debug.js similarity index 100% rename from packages/react/runtime/__test__/utils/debug.js rename to packages/react/runtime/__test__/snapshot/utils/debug.js diff --git a/packages/react/runtime/__test__/utils/envManager.ts b/packages/react/runtime/__test__/snapshot/utils/envManager.ts similarity index 75% rename from packages/react/runtime/__test__/utils/envManager.ts rename to packages/react/runtime/__test__/snapshot/utils/envManager.ts index 9b6e2b84da..d96fa19e2d 100644 --- a/packages/react/runtime/__test__/utils/envManager.ts +++ b/packages/react/runtime/__test__/snapshot/utils/envManager.ts @@ -5,16 +5,16 @@ import { getJSModule } from './jsModule.js'; import { BackgroundSnapshotInstance, backgroundSnapshotInstanceManager, -} from '../../src/snapshot/backgroundSnapshot.js'; -import { setupBackgroundDocument, setupDocument } from '../../src/document.js'; -import { deinitGlobalSnapshotPatch } from '../../src/lifecycle/patch/snapshotPatch.js'; -import { shouldDelayUiOps } from '../../src/lifecycle/ref/delay.js'; -import { clearListGlobal } from '../../src/list/list.js'; -import { globalPipelineOptions, setPipeline } from '../../src/lynx/performance.js'; -import { __root, setRoot } from '../../src/root.js'; -import { SnapshotInstance, snapshotInstanceManager } from '../../src/snapshot/snapshot.js'; -import { hydrationMap } from '../../src/snapshot/snapshotInstanceHydrationMap.js'; -import { clearWorkletRefLastIdForTesting } from '../../src/worklet/ref/workletRef.js'; +} from '../../../src/snapshot/snapshot/backgroundSnapshot.js'; +import { setupBackgroundDocument, setupDocument } from '../../../src/document.js'; +import { deinitGlobalSnapshotPatch } from '../../../src/snapshot/lifecycle/patch/snapshotPatch.js'; +import { shouldDelayUiOps } from '../../../src/snapshot/lifecycle/ref/delay.js'; +import { clearListGlobal } from '../../../src/snapshot/list/list.js'; +import { globalPipelineOptions, setPipeline } from '../../../src/snapshot/lynx/performance.js'; +import { __root, setRoot } from '../../../src/root.js'; +import { SnapshotInstance, snapshotInstanceManager } from '../../../src/snapshot/snapshot/snapshot.js'; +import { hydrationMap } from '../../../src/snapshot/snapshot/snapshotInstanceHydrationMap.js'; +import { clearWorkletRefLastIdForTesting } from '../../../src/snapshot/worklet/ref/workletRef.js'; export class EnvManager { root: typeof __root | undefined; diff --git a/packages/react/runtime/__test__/utils/globals.js b/packages/react/runtime/__test__/snapshot/utils/globals.js similarity index 100% rename from packages/react/runtime/__test__/utils/globals.js rename to packages/react/runtime/__test__/snapshot/utils/globals.js diff --git a/packages/react/runtime/__test__/utils/inject.ts b/packages/react/runtime/__test__/snapshot/utils/inject.ts similarity index 100% rename from packages/react/runtime/__test__/utils/inject.ts rename to packages/react/runtime/__test__/snapshot/utils/inject.ts diff --git a/packages/react/runtime/__test__/utils/jsModule.ts b/packages/react/runtime/__test__/snapshot/utils/jsModule.ts similarity index 100% rename from packages/react/runtime/__test__/utils/jsModule.ts rename to packages/react/runtime/__test__/snapshot/utils/jsModule.ts diff --git a/packages/react/runtime/__test__/utils/nativeMethod.ts b/packages/react/runtime/__test__/snapshot/utils/nativeMethod.ts similarity index 100% rename from packages/react/runtime/__test__/utils/nativeMethod.ts rename to packages/react/runtime/__test__/snapshot/utils/nativeMethod.ts diff --git a/packages/react/runtime/__test__/utils/runtimeProxy.test.js b/packages/react/runtime/__test__/snapshot/utils/runtimeProxy.test.js similarity index 100% rename from packages/react/runtime/__test__/utils/runtimeProxy.test.js rename to packages/react/runtime/__test__/snapshot/utils/runtimeProxy.test.js diff --git a/packages/react/runtime/__test__/utils/runtimeProxy.ts b/packages/react/runtime/__test__/snapshot/utils/runtimeProxy.ts similarity index 100% rename from packages/react/runtime/__test__/utils/runtimeProxy.ts rename to packages/react/runtime/__test__/snapshot/utils/runtimeProxy.ts diff --git a/packages/react/runtime/__test__/utils/setup.js b/packages/react/runtime/__test__/snapshot/utils/setup.js similarity index 94% rename from packages/react/runtime/__test__/utils/setup.js rename to packages/react/runtime/__test__/snapshot/utils/setup.js index d896dd1306..df780129d2 100644 --- a/packages/react/runtime/__test__/utils/setup.js +++ b/packages/react/runtime/__test__/snapshot/utils/setup.js @@ -2,8 +2,8 @@ // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. import { __injectElementApi } from './inject.ts'; -import '../../src/lynx.ts'; -import { document } from '../../src/document.ts'; +import '../../../src/lynx.ts'; +import { document } from '../../../src/document.ts'; import { afterEach, expect } from 'vitest'; diff --git a/packages/react/runtime/__test__/worklet/execIdMap.test.js b/packages/react/runtime/__test__/snapshot/worklet/execIdMap.test.js similarity index 91% rename from packages/react/runtime/__test__/worklet/execIdMap.test.js rename to packages/react/runtime/__test__/snapshot/worklet/execIdMap.test.js index ce7b217a54..daaf43a57b 100644 --- a/packages/react/runtime/__test__/worklet/execIdMap.test.js +++ b/packages/react/runtime/__test__/snapshot/worklet/execIdMap.test.js @@ -3,7 +3,7 @@ // LICENSE file in the root directory of this source tree. import { beforeEach, describe, expect, it } from 'vitest'; -import { WorkletExecIdMap } from '../../src/worklet/call/execMap'; +import { WorkletExecIdMap } from '../../../src/snapshot/worklet/call/execMap'; beforeEach(() => { SystemInfo.lynxSdkVersion = '999.999'; diff --git a/packages/react/runtime/__test__/worklet/onPost.test.js b/packages/react/runtime/__test__/snapshot/worklet/onPost.test.js similarity index 85% rename from packages/react/runtime/__test__/worklet/onPost.test.js rename to packages/react/runtime/__test__/snapshot/worklet/onPost.test.js index 7affaea35f..4f82f8e453 100644 --- a/packages/react/runtime/__test__/worklet/onPost.test.js +++ b/packages/react/runtime/__test__/snapshot/worklet/onPost.test.js @@ -3,8 +3,8 @@ // LICENSE file in the root directory of this source tree. import { afterEach, describe, expect, it, vi } from 'vitest'; -import { onPostWorkletCtx } from '../../src/worklet/ctx'; -import { destroyWorklet } from '../../src/worklet/destroy'; +import { onPostWorkletCtx } from '../../../src/snapshot/worklet/ctx'; +import { destroyWorklet } from '../../../src/snapshot/worklet/destroy'; afterEach(() => { destroyWorklet(); diff --git a/packages/react/runtime/__test__/worklet/runOnBackground.test.js b/packages/react/runtime/__test__/snapshot/worklet/runOnBackground.test.js similarity index 94% rename from packages/react/runtime/__test__/worklet/runOnBackground.test.js rename to packages/react/runtime/__test__/snapshot/worklet/runOnBackground.test.js index 8bf9da0a0a..632bb18215 100644 --- a/packages/react/runtime/__test__/worklet/runOnBackground.test.js +++ b/packages/react/runtime/__test__/snapshot/worklet/runOnBackground.test.js @@ -3,10 +3,10 @@ // LICENSE file in the root directory of this source tree. import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { onPostWorkletCtx } from '../../src/worklet/ctx'; -import { destroyWorklet } from '../../src/worklet/destroy'; -import { clearConfigCacheForTesting } from '../../src/worklet/functionality'; -import { runOnBackground } from '../../src/worklet/call/runOnBackground'; +import { onPostWorkletCtx } from '../../../src/snapshot/worklet/ctx'; +import { destroyWorklet } from '../../../src/snapshot/worklet/destroy'; +import { clearConfigCacheForTesting } from '../../../src/snapshot/worklet/functionality'; +import { runOnBackground } from '../../../src/snapshot/worklet/call/runOnBackground'; import { globalEnvManager } from '../utils/envManager'; beforeEach(() => { diff --git a/packages/react/runtime/__test__/worklet/runOnMainThread.test.jsx b/packages/react/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx similarity index 94% rename from packages/react/runtime/__test__/worklet/runOnMainThread.test.jsx rename to packages/react/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx index bcc997894b..cd9ba777e9 100644 --- a/packages/react/runtime/__test__/worklet/runOnMainThread.test.jsx +++ b/packages/react/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx @@ -7,14 +7,14 @@ import { afterEach, beforeEach, describe, expect, it, vi, beforeAll } from 'vite import { WorkletEvents } from '@lynx-js/react/worklet-runtime/bindings'; -import { destroyWorklet } from '../../src/worklet/destroy'; -import { clearConfigCacheForTesting } from '../../src/worklet/functionality'; -import { runOnMainThread } from '../../src/worklet/call/runOnMainThread'; +import { destroyWorklet } from '../../../src/snapshot/worklet/destroy'; +import { clearConfigCacheForTesting } from '../../../src/snapshot/worklet/functionality'; +import { runOnMainThread } from '../../../src/snapshot/worklet/call/runOnMainThread'; import { globalEnvManager } from '../utils/envManager'; -import { initGlobalSnapshotPatch } from '../../src/lifecycle/patch/snapshotPatch'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { __root } from '../../src/root'; -import { root } from '../../src/lynx-api'; +import { initGlobalSnapshotPatch } from '../../../src/snapshot/lifecycle/patch/snapshotPatch'; +import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit'; +import { __root } from '../../../src/root'; +import { root } from '../../../src/lynx-api'; import { waitSchedule } from '../utils/nativeMethod'; const App = ({ fn, attr }) => { diff --git a/packages/react/runtime/__test__/worklet/transform.test.js b/packages/react/runtime/__test__/snapshot/worklet/transform.test.js similarity index 85% rename from packages/react/runtime/__test__/worklet/transform.test.js rename to packages/react/runtime/__test__/snapshot/worklet/transform.test.js index a1b8869a0e..d59670928f 100644 --- a/packages/react/runtime/__test__/worklet/transform.test.js +++ b/packages/react/runtime/__test__/snapshot/worklet/transform.test.js @@ -3,8 +3,8 @@ // LICENSE file in the root directory of this source tree. import { afterEach, describe, expect, it, vi } from 'vitest'; -import { destroyWorklet } from '../../src/worklet/destroy'; -import { transformToWorklet } from '../../src/worklet/call/transformToWorklet'; +import { destroyWorklet } from '../../../src/snapshot/worklet/destroy'; +import { transformToWorklet } from '../../../src/snapshot/worklet/call/transformToWorklet'; afterEach(() => { destroyWorklet(); diff --git a/packages/react/runtime/__test__/worklet/workletRef.test.jsx b/packages/react/runtime/__test__/snapshot/worklet/workletRef.test.jsx similarity index 92% rename from packages/react/runtime/__test__/worklet/workletRef.test.jsx rename to packages/react/runtime/__test__/snapshot/worklet/workletRef.test.jsx index 6a370f6c34..c4a81c2416 100644 --- a/packages/react/runtime/__test__/worklet/workletRef.test.jsx +++ b/packages/react/runtime/__test__/snapshot/worklet/workletRef.test.jsx @@ -6,15 +6,15 @@ import { render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; -import { __root } from '../../src/root'; -import { setupPage } from '../../src/snapshot'; -import { destroyWorklet } from '../../src/worklet/destroy'; -import { clearConfigCacheForTesting } from '../../src/worklet/functionality'; -import { MainThreadRef, useMainThreadRef } from '../../src/worklet/ref/workletRef'; +import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit'; +import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread'; +import { __root } from '../../../src/root'; +import { setupPage } from '../../../src/snapshot'; +import { destroyWorklet } from '../../../src/snapshot/worklet/destroy'; +import { clearConfigCacheForTesting } from '../../../src/snapshot/worklet/functionality'; +import { MainThreadRef, useMainThreadRef } from '../../../src/snapshot/worklet/ref/workletRef'; import { globalEnvManager } from '../utils/envManager'; -import { injectUpdateMTRefInitValue } from '../../src/worklet/ref/updateInitValue'; +import { injectUpdateMTRefInitValue } from '../../../src/snapshot/worklet/ref/updateInitValue'; const Comp = () => { const ref = useMainThreadRef(233); diff --git a/packages/react/runtime/__test__/snapshot/workletEvent.test.jsx b/packages/react/runtime/__test__/snapshot/workletEvent.test.jsx index faaf0a7a57..3f64f872d3 100644 --- a/packages/react/runtime/__test__/snapshot/workletEvent.test.jsx +++ b/packages/react/runtime/__test__/snapshot/workletEvent.test.jsx @@ -7,13 +7,13 @@ import { render } from 'preact'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { Component, useState } from '../../src/index'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; +import { replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit'; +import { injectUpdateMainThread } from '../../src/snapshot/lifecycle/patch/updateMainThread'; import { __root } from '../../src/root'; import { setupPage } from '../../src/snapshot'; -import { updateWorkletEvent } from '../../src/snapshot/workletEvent'; -import { globalEnvManager } from '../utils/envManager'; -import { elementTree, waitSchedule } from '../utils/nativeMethod'; +import { updateWorkletEvent } from '../../src/snapshot/snapshot/workletEvent'; +import { globalEnvManager } from './utils/envManager'; +import { elementTree, waitSchedule } from './utils/nativeMethod'; beforeAll(() => { setupPage(__CreatePage('0', 0)); diff --git a/packages/react/runtime/__test__/snapshot/workletRef.test.jsx b/packages/react/runtime/__test__/snapshot/workletRef.test.jsx index 8fe5e3b0e6..508f15843d 100644 --- a/packages/react/runtime/__test__/snapshot/workletRef.test.jsx +++ b/packages/react/runtime/__test__/snapshot/workletRef.test.jsx @@ -8,13 +8,13 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite import { createCompBG1, createCompBGList, createCompBGSpread } from './workletRefBG'; import { createCompMT1, createCompMTList, createCompMTSpread } from './workletRefMT'; -import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; -import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; +import { replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit'; +import { injectUpdateMainThread } from '../../src/snapshot/lifecycle/patch/updateMainThread'; import { __root } from '../../src/root'; import { setupPage } from '../../src/snapshot'; -import { globalEnvManager } from '../utils/envManager'; -import { elementTree } from '../utils/nativeMethod'; -import { injectUpdateMTRefInitValue } from '../../src/worklet/ref/updateInitValue'; +import { globalEnvManager } from './utils/envManager'; +import { elementTree } from './utils/nativeMethod'; +import { injectUpdateMTRefInitValue } from '../../src/snapshot/worklet/ref/updateInitValue'; beforeAll(() => { setupPage(__CreatePage('0', 0)); diff --git a/packages/react/runtime/__test__/snapshot/workletRefBG.jsx b/packages/react/runtime/__test__/snapshot/workletRefBG.jsx index 40fce0081c..f4deb74c7e 100644 --- a/packages/react/runtime/__test__/snapshot/workletRefBG.jsx +++ b/packages/react/runtime/__test__/snapshot/workletRefBG.jsx @@ -3,7 +3,7 @@ // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. */ -import { useMainThreadRef } from '../../src/worklet/ref/workletRef'; +import { useMainThreadRef } from '../../src/snapshot/worklet/ref/workletRef'; /* v8 ignore start */ let ref1; diff --git a/packages/react/runtime/__test__/snapshot/workletRefMT.jsx b/packages/react/runtime/__test__/snapshot/workletRefMT.jsx index 1da5246822..b5cfc74250 100644 --- a/packages/react/runtime/__test__/snapshot/workletRefMT.jsx +++ b/packages/react/runtime/__test__/snapshot/workletRefMT.jsx @@ -6,7 +6,7 @@ /** @jsxImportSource ../../lepus */ -import { useMainThreadRef } from '../../src/worklet/ref/workletRef'; +import { useMainThreadRef } from '../../src/snapshot/worklet/ref/workletRef'; /* v8 ignore start */ let ref1; diff --git a/packages/react/runtime/src/document.ts b/packages/react/runtime/src/document.ts index c0ed053b4c..17b6f69e53 100644 --- a/packages/react/runtime/src/document.ts +++ b/packages/react/runtime/src/document.ts @@ -1,8 +1,8 @@ // Copyright 2024 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. -import { BackgroundSnapshotInstance } from './snapshot/backgroundSnapshot.js'; -import { SnapshotInstance } from './snapshot/snapshot.js'; +import { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js'; +import { SnapshotInstance } from './snapshot/snapshot/snapshot.js'; /** * This module implements an Interface Adapter Pattern to integrate Preact's diff --git a/packages/react/runtime/src/index.ts b/packages/react/runtime/src/index.ts index cf11301fc2..a2be13406f 100644 --- a/packages/react/runtime/src/index.ts +++ b/packages/react/runtime/src/index.ts @@ -3,7 +3,7 @@ // LICENSE file in the root directory of this source tree. import './lynx.js'; -import './lynx/component.js'; +import './snapshot/lynx/component.js'; import { Children, Component, @@ -31,12 +31,12 @@ import { useReducer, useRef, useState, -} from './hooks/react.js'; -import { Suspense } from './lynx/suspense.js'; +} from './snapshot/hooks/react.js'; +import { Suspense } from './snapshot/lynx/suspense.js'; export { Component, createContext } from 'preact'; export { PureComponent } from 'preact/compat'; -export * from './hooks/react.js'; +export * from './snapshot/hooks/react.js'; /** * @internal diff --git a/packages/react/runtime/src/internal.ts b/packages/react/runtime/src/internal.ts index 7c4decbad4..c5dfca947c 100644 --- a/packages/react/runtime/src/internal.ts +++ b/packages/react/runtime/src/internal.ts @@ -7,17 +7,17 @@ import type { FC } from 'react'; import './lynx.js'; -import { factory as factory2 } from './compat/componentIs.js'; -import { useMemo } from './hooks/react.js'; -import { loadLazyBundle } from './lynx/lazy-bundle.js'; import { __root } from './root.js'; -import { BackgroundSnapshotInstance } from './snapshot/backgroundSnapshot.js'; -import { __page, __pageId, createSnapshot, snapshotManager } from './snapshot/definition.js'; -import { DynamicPartType } from './snapshot/dynamicPartType.js'; -import { snapshotCreateList } from './snapshot/list.js'; -import { SnapshotInstance, snapshotCreatorMap } from './snapshot/snapshot.js'; +import { factory as factory2 } from './snapshot/compat/componentIs.js'; +import { useMemo } from './snapshot/hooks/react.js'; +import { loadLazyBundle } from './snapshot/lynx/lazy-bundle.js'; +import { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js'; +import { __page, __pageId, createSnapshot, snapshotManager } from './snapshot/snapshot/definition.js'; +import { DynamicPartType } from './snapshot/snapshot/dynamicPartType.js'; +import { snapshotCreateList } from './snapshot/snapshot/list.js'; +import { SnapshotInstance, snapshotCreatorMap } from './snapshot/snapshot/snapshot.js'; -export { CHILDREN, COMPONENT, DIFF, DIRTY, DOM, FLAGS, INDEX, PARENT } from './renderToOpcodes/constants.js'; +export { CHILDREN, COMPONENT, DIFF, DIRTY, DOM, FLAGS, INDEX, PARENT } from './snapshot/renderToOpcodes/constants.js'; export { __page, __pageId, __root }; @@ -34,20 +34,20 @@ export const __DynamicPartSlot: DynamicPartType = DynamicPartType.Slot; export const __DynamicPartMultiChildren: DynamicPartType = DynamicPartType.MultiChildren; export const __DynamicPartChildren: DynamicPartType = DynamicPartType.Children; export const __DynamicPartListChildren: DynamicPartType = DynamicPartType.ListChildren; -export { __DynamicPartChildren_0 } from './snapshot/dynamicPartType.js'; +export { __DynamicPartChildren_0 } from './snapshot/snapshot/dynamicPartType.js'; // v2 slot export const __DynamicPartSlotV2: DynamicPartType = DynamicPartType.SlotV2; export const __DynamicPartListSlotV2: DynamicPartType = DynamicPartType.ListSlotV2; export const __DynamicPartSlotV2_0: [DynamicPartType, number][] = [[DynamicPartType.SlotV2, 0]]; -export { updateSpread } from './snapshot/spread.js'; -export { updateEvent } from './snapshot/event.js'; -export { updateRef, transformRef } from './snapshot/ref.js'; -export { updateWorkletEvent } from './snapshot/workletEvent.js'; -export { updateWorkletRef } from './snapshot/workletRef.js'; -export { updateGesture } from './snapshot/gesture.js'; -export { updateListItemPlatformInfo } from './snapshot/platformInfo.js'; +export { updateSpread } from './snapshot/snapshot/spread.js'; +export { updateEvent } from './snapshot/snapshot/event.js'; +export { updateRef, transformRef } from './snapshot/snapshot/ref.js'; +export { updateWorkletEvent } from './snapshot/snapshot/workletEvent.js'; +export { updateWorkletRef } from './snapshot/snapshot/workletRef.js'; +export { updateGesture } from './snapshot/snapshot/gesture.js'; +export { updateListItemPlatformInfo } from './snapshot/snapshot/platformInfo.js'; export { options, @@ -57,11 +57,11 @@ export { } from 'preact'; export type { Options } from 'preact'; -export { loadDynamicJS, __dynamicImport } from './lynx/dynamic-js.js'; +export { loadDynamicJS, __dynamicImport } from './snapshot/lynx/dynamic-js.js'; -export { withInitDataInState } from './compat/initData.js'; +export { withInitDataInState } from './snapshot/compat/initData.js'; -export { wrapWithLynxComponent } from './compat/lynxComponent.js'; +export { wrapWithLynxComponent } from './snapshot/compat/lynxComponent.js'; /** * @internal a polyfill for @@ -72,9 +72,9 @@ export const __ComponentIsPolyfill: FC<{ is: string }> = /* @__PURE__ */ factory loadLazyBundle, ); -export { loadLazyBundle } from './lynx/lazy-bundle.js'; +export { loadLazyBundle } from './snapshot/lynx/lazy-bundle.js'; -export { transformToWorklet } from './worklet/call/transformToWorklet.js'; -export { registerWorkletOnBackground } from './worklet/hmr.js'; +export { transformToWorklet } from './snapshot/worklet/call/transformToWorklet.js'; +export { registerWorkletOnBackground } from './snapshot/worklet/hmr.js'; export { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings'; diff --git a/packages/react/runtime/src/lynx-api.ts b/packages/react/runtime/src/lynx-api.ts index 410c168171..180da40023 100644 --- a/packages/react/runtime/src/lynx-api.ts +++ b/packages/react/runtime/src/lynx-api.ts @@ -6,12 +6,12 @@ import { createContext, createElement } from 'preact/compat'; import { useState } from 'preact/hooks'; import type { Consumer, FC, ReactNode } from 'react'; -import { factory, withInitDataInState } from './compat/initData.js'; -import { profileEnd, profileStart } from './debug/profile.js'; -import { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js'; -import { LifecycleConstant } from './lifecycle/constant.js'; -import { flushDelayedLifecycleEvents } from './lynx/tt.js'; import { __root } from './root.js'; +import { factory, withInitDataInState } from './snapshot/compat/initData.js'; +import { profileEnd, profileStart } from './snapshot/debug/profile.js'; +import { useLynxGlobalEventListener } from './snapshot/hooks/useLynxGlobalEventListener.js'; +import { LifecycleConstant } from './snapshot/lifecycle/constant.js'; +import { flushDelayedLifecycleEvents } from './snapshot/lynx/tt.js'; /** * The default root exported by `@lynx-js/react` for you to render a JSX @@ -572,7 +572,7 @@ export interface Lynx { registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void; } -export { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js'; -export { runOnBackground } from './worklet/call/runOnBackground.js'; -export { runOnMainThread } from './worklet/call/runOnMainThread.js'; -export { MainThreadRef, useMainThreadRef } from './worklet/ref/workletRef.js'; +export { useLynxGlobalEventListener } from './snapshot/hooks/useLynxGlobalEventListener.js'; +export { runOnBackground } from './snapshot/worklet/call/runOnBackground.js'; +export { runOnMainThread } from './snapshot/worklet/call/runOnMainThread.js'; +export { MainThreadRef, useMainThreadRef } from './snapshot/worklet/ref/workletRef.js'; diff --git a/packages/react/runtime/src/lynx.ts b/packages/react/runtime/src/lynx.ts index da3a1d0bf2..2864d9c1be 100644 --- a/packages/react/runtime/src/lynx.ts +++ b/packages/react/runtime/src/lynx.ts @@ -3,27 +3,27 @@ // LICENSE file in the root directory of this source tree. import { options } from 'preact'; // to make sure preact's hooks to register earlier than ours -import './hooks/react.js'; +import './snapshot/hooks/react.js'; -import { initElementPAPICallAlog } from './alog/elementPAPICall.js'; -import { initAlog } from './alog/index.js'; -import { setupComponentStack } from './debug/component-stack.js'; -import { isProfiling } from './debug/profile.js'; -import { initProfileHook } from './debug/profileHooks.js'; -import { setupVNodeSourceHook } from './debug/vnodeSource.js'; import { document, setupBackgroundDocument } from './document.js'; -import { replaceCommitHook } from './lifecycle/patch/commit.js'; -import { addCtxNotFoundEventListener } from './lifecycle/patch/error.js'; -import { injectUpdateMainThread } from './lifecycle/patch/updateMainThread.js'; -import { injectCalledByNative } from './lynx/calledByNative.js'; -import { setupLynxEnv } from './lynx/env.js'; -import { injectLepusMethods } from './lynx/injectLepusMethods.js'; -import { initTimingAPI } from './lynx/performance.js'; -import { injectTt } from './lynx/tt.js'; +import { initElementPAPICallAlog } from './snapshot/alog/elementPAPICall.js'; +import { initAlog } from './snapshot/alog/index.js'; +import { setupComponentStack } from './snapshot/debug/component-stack.js'; +import { isProfiling } from './snapshot/debug/profile.js'; +import { initProfileHook } from './snapshot/debug/profileHooks.js'; +import { setupVNodeSourceHook } from './snapshot/debug/vnodeSource.js'; +import { replaceCommitHook } from './snapshot/lifecycle/patch/commit.js'; +import { addCtxNotFoundEventListener } from './snapshot/lifecycle/patch/error.js'; +import { injectUpdateMainThread } from './snapshot/lifecycle/patch/updateMainThread.js'; +import { injectCalledByNative } from './snapshot/lynx/calledByNative.js'; +import { setupLynxEnv } from './snapshot/lynx/env.js'; +import { injectLepusMethods } from './snapshot/lynx/injectLepusMethods.js'; +import { initTimingAPI } from './snapshot/lynx/performance.js'; +import { injectTt } from './snapshot/lynx/tt.js'; +import { injectUpdateMTRefInitValue } from './snapshot/worklet/ref/updateInitValue.js'; import { lynxQueueMicrotask } from './utils.js'; -import { injectUpdateMTRefInitValue } from './worklet/ref/updateInitValue.js'; -export { runWithForce } from './lynx/runWithForce.js'; +export { runWithForce } from './snapshot/lynx/runWithForce.js'; // @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof globalThis.processEvalResult === 'undefined') { diff --git a/packages/react/runtime/src/root.ts b/packages/react/runtime/src/root.ts index 18c5f8cb74..000b4ab2d9 100644 --- a/packages/react/runtime/src/root.ts +++ b/packages/react/runtime/src/root.ts @@ -1,8 +1,8 @@ // Copyright 2024 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. -import { BackgroundSnapshotInstance } from './snapshot/backgroundSnapshot.js'; -import { SnapshotInstance } from './snapshot/snapshot.js'; +import { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js'; +import { SnapshotInstance } from './snapshot/snapshot/snapshot.js'; /** * The internal ReactLynx's root. diff --git a/packages/react/runtime/src/alog/elementPAPICall.ts b/packages/react/runtime/src/snapshot/alog/elementPAPICall.ts similarity index 100% rename from packages/react/runtime/src/alog/elementPAPICall.ts rename to packages/react/runtime/src/snapshot/alog/elementPAPICall.ts diff --git a/packages/react/runtime/src/alog/index.ts b/packages/react/runtime/src/snapshot/alog/index.ts similarity index 100% rename from packages/react/runtime/src/alog/index.ts rename to packages/react/runtime/src/snapshot/alog/index.ts diff --git a/packages/react/runtime/src/alog/render.ts b/packages/react/runtime/src/snapshot/alog/render.ts similarity index 96% rename from packages/react/runtime/src/alog/render.ts rename to packages/react/runtime/src/snapshot/alog/render.ts index 07ee3d78ba..a820261bd5 100644 --- a/packages/react/runtime/src/alog/render.ts +++ b/packages/react/runtime/src/snapshot/alog/render.ts @@ -4,9 +4,9 @@ import { options } from 'preact'; import type { ComponentClass, VNode } from 'preact'; +import { getDisplayName } from '../../utils.js'; import { DIFFED, DOM } from '../renderToOpcodes/constants.js'; import type { SnapshotInstance } from '../snapshot/snapshot.js'; -import { getDisplayName } from '../utils.js'; export function initRenderAlog(): void { const oldAfterDiff = options[DIFFED]; diff --git a/packages/react/runtime/src/compat/componentIs.ts b/packages/react/runtime/src/snapshot/compat/componentIs.ts similarity index 100% rename from packages/react/runtime/src/compat/componentIs.ts rename to packages/react/runtime/src/snapshot/compat/componentIs.ts diff --git a/packages/react/runtime/src/compat/initData.ts b/packages/react/runtime/src/snapshot/compat/initData.ts similarity index 100% rename from packages/react/runtime/src/compat/initData.ts rename to packages/react/runtime/src/snapshot/compat/initData.ts diff --git a/packages/react/runtime/src/compat/lynxComponent.ts b/packages/react/runtime/src/snapshot/compat/lynxComponent.ts similarity index 100% rename from packages/react/runtime/src/compat/lynxComponent.ts rename to packages/react/runtime/src/snapshot/compat/lynxComponent.ts diff --git a/packages/react/runtime/src/debug/component-stack.ts b/packages/react/runtime/src/snapshot/debug/component-stack.ts similarity index 100% rename from packages/react/runtime/src/debug/component-stack.ts rename to packages/react/runtime/src/snapshot/debug/component-stack.ts diff --git a/packages/react/runtime/src/debug/debug.ts b/packages/react/runtime/src/snapshot/debug/debug.ts similarity index 100% rename from packages/react/runtime/src/debug/debug.ts rename to packages/react/runtime/src/snapshot/debug/debug.ts diff --git a/packages/react/runtime/src/debug/describeInvalidValue.ts b/packages/react/runtime/src/snapshot/debug/describeInvalidValue.ts similarity index 100% rename from packages/react/runtime/src/debug/describeInvalidValue.ts rename to packages/react/runtime/src/snapshot/debug/describeInvalidValue.ts diff --git a/packages/react/runtime/src/debug/formatPatch.ts b/packages/react/runtime/src/snapshot/debug/formatPatch.ts similarity index 100% rename from packages/react/runtime/src/debug/formatPatch.ts rename to packages/react/runtime/src/snapshot/debug/formatPatch.ts diff --git a/packages/react/runtime/src/debug/printSnapshot.ts b/packages/react/runtime/src/snapshot/debug/printSnapshot.ts similarity index 100% rename from packages/react/runtime/src/debug/printSnapshot.ts rename to packages/react/runtime/src/snapshot/debug/printSnapshot.ts diff --git a/packages/react/runtime/src/debug/profile.ts b/packages/react/runtime/src/snapshot/debug/profile.ts similarity index 96% rename from packages/react/runtime/src/debug/profile.ts rename to packages/react/runtime/src/snapshot/debug/profile.ts index 232c78913d..1ae2fe6707 100644 --- a/packages/react/runtime/src/debug/profile.ts +++ b/packages/react/runtime/src/snapshot/debug/profile.ts @@ -2,7 +2,7 @@ // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. -import { noop } from '../utils.js'; +import { noop } from '../../utils.js'; export const isProfiling: boolean = /* @__PURE__ */ Boolean( lynx.performance?.isProfileRecording?.(), diff --git a/packages/react/runtime/src/debug/profileHooks.ts b/packages/react/runtime/src/snapshot/debug/profileHooks.ts similarity index 99% rename from packages/react/runtime/src/debug/profileHooks.ts rename to packages/react/runtime/src/snapshot/debug/profileHooks.ts index 6814da0ed2..d09c8c703b 100644 --- a/packages/react/runtime/src/debug/profileHooks.ts +++ b/packages/react/runtime/src/snapshot/debug/profileHooks.ts @@ -6,6 +6,7 @@ import type { ComponentClass, ComponentType, VNode } from 'preact'; import type { TraceOption } from '@lynx-js/types'; +import { getDisplayName, hook } from '../../utils.js'; import { globalPatchOptions } from '../lifecycle/patch/commit.js'; import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js'; import { @@ -23,7 +24,6 @@ import { VALUE, VNODE, } from '../renderToOpcodes/constants.js'; -import { getDisplayName, hook } from '../utils.js'; const format = (val: unknown) => { if (typeof val === 'function') { diff --git a/packages/react/runtime/src/debug/vnodeSource.ts b/packages/react/runtime/src/snapshot/debug/vnodeSource.ts similarity index 100% rename from packages/react/runtime/src/debug/vnodeSource.ts rename to packages/react/runtime/src/snapshot/debug/vnodeSource.ts diff --git a/packages/react/runtime/src/gesture/processGesture.ts b/packages/react/runtime/src/snapshot/gesture/processGesture.ts similarity index 100% rename from packages/react/runtime/src/gesture/processGesture.ts rename to packages/react/runtime/src/snapshot/gesture/processGesture.ts diff --git a/packages/react/runtime/src/gesture/processGestureBagkround.ts b/packages/react/runtime/src/snapshot/gesture/processGestureBagkround.ts similarity index 100% rename from packages/react/runtime/src/gesture/processGestureBagkround.ts rename to packages/react/runtime/src/snapshot/gesture/processGestureBagkround.ts diff --git a/packages/react/runtime/src/gesture/types.ts b/packages/react/runtime/src/snapshot/gesture/types.ts similarity index 100% rename from packages/react/runtime/src/gesture/types.ts rename to packages/react/runtime/src/snapshot/gesture/types.ts diff --git a/packages/react/runtime/src/hooks/mainThread.ts b/packages/react/runtime/src/snapshot/hooks/mainThread.ts similarity index 99% rename from packages/react/runtime/src/hooks/mainThread.ts rename to packages/react/runtime/src/snapshot/hooks/mainThread.ts index 633f4c5fc0..1ed23bccbd 100644 --- a/packages/react/runtime/src/hooks/mainThread.ts +++ b/packages/react/runtime/src/snapshot/hooks/mainThread.ts @@ -19,6 +19,7 @@ import type { useLayoutEffect as useLayoutEffectType, } from 'preact/hooks'; +import { noop } from '../../utils.js'; import { CHILDREN, COMPONENT, @@ -35,7 +36,6 @@ import { VALUE, VNODE, } from '../renderToOpcodes/constants.js'; -import { noop } from '../utils.js'; let currentIndex: number; let currentComponent: Component | null | undefined; diff --git a/packages/react/runtime/src/hooks/react.ts b/packages/react/runtime/src/snapshot/hooks/react.ts similarity index 100% rename from packages/react/runtime/src/hooks/react.ts rename to packages/react/runtime/src/snapshot/hooks/react.ts diff --git a/packages/react/runtime/src/hooks/useLynxGlobalEventListener.ts b/packages/react/runtime/src/snapshot/hooks/useLynxGlobalEventListener.ts similarity index 100% rename from packages/react/runtime/src/hooks/useLynxGlobalEventListener.ts rename to packages/react/runtime/src/snapshot/hooks/useLynxGlobalEventListener.ts diff --git a/packages/react/runtime/src/snapshot/index.ts b/packages/react/runtime/src/snapshot/index.ts index 4f40a0fa0d..4c5d89cc8e 100644 --- a/packages/react/runtime/src/snapshot/index.ts +++ b/packages/react/runtime/src/snapshot/index.ts @@ -1,8 +1,5 @@ -// Copyright 2026 The Lynx Authors. All rights reserved. +// Copyright 2024 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. -export { BackgroundSnapshotInstance, backgroundSnapshotInstanceManager, hydrate } from './backgroundSnapshot.js'; -export { SnapshotInstance, snapshotInstanceManager, snapshotCreatorMap } from './snapshot.js'; -export { snapshotManager, createSnapshot, setupPage, __page, __pageId, clearPage } from './definition.js'; -export { traverseSnapshotInstance } from './utils.js'; +export * from './snapshot/index.js'; diff --git a/packages/react/runtime/src/legacy-react-runtime/index.ts b/packages/react/runtime/src/snapshot/legacy-react-runtime/index.ts similarity index 100% rename from packages/react/runtime/src/legacy-react-runtime/index.ts rename to packages/react/runtime/src/snapshot/legacy-react-runtime/index.ts diff --git a/packages/react/runtime/src/lifecycle/constant.ts b/packages/react/runtime/src/snapshot/lifecycle/constant.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/constant.ts rename to packages/react/runtime/src/snapshot/lifecycle/constant.ts diff --git a/packages/react/runtime/src/lifecycle/destroy.ts b/packages/react/runtime/src/snapshot/lifecycle/destroy.ts similarity index 96% rename from packages/react/runtime/src/lifecycle/destroy.ts rename to packages/react/runtime/src/snapshot/lifecycle/destroy.ts index ee5835cedf..ce65c38d8a 100644 --- a/packages/react/runtime/src/lifecycle/destroy.ts +++ b/packages/react/runtime/src/snapshot/lifecycle/destroy.ts @@ -3,7 +3,7 @@ // LICENSE file in the root directory of this source tree. import { render } from 'preact'; -import { __root } from '../root.js'; +import { __root } from '../../root.js'; import { delayedEvents } from './event/delayEvents.js'; import { delayedLifecycleEvents } from './event/delayLifecycleEvents.js'; import { globalCommitTaskMap } from './patch/commit.js'; diff --git a/packages/react/runtime/src/lifecycle/event/delayEvents.ts b/packages/react/runtime/src/snapshot/lifecycle/event/delayEvents.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/event/delayEvents.ts rename to packages/react/runtime/src/snapshot/lifecycle/event/delayEvents.ts diff --git a/packages/react/runtime/src/lifecycle/event/delayLifecycleEvents.ts b/packages/react/runtime/src/snapshot/lifecycle/event/delayLifecycleEvents.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/event/delayLifecycleEvents.ts rename to packages/react/runtime/src/snapshot/lifecycle/event/delayLifecycleEvents.ts diff --git a/packages/react/runtime/src/lifecycle/event/jsReady.ts b/packages/react/runtime/src/snapshot/lifecycle/event/jsReady.ts similarity index 96% rename from packages/react/runtime/src/lifecycle/event/jsReady.ts rename to packages/react/runtime/src/snapshot/lifecycle/event/jsReady.ts index 169bc8f05f..4fcda32269 100644 --- a/packages/react/runtime/src/lifecycle/event/jsReady.ts +++ b/packages/react/runtime/src/snapshot/lifecycle/event/jsReady.ts @@ -1,9 +1,9 @@ // Copyright 2025 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. +import { __root } from '../../../root.js'; import { profileEnd, profileStart } from '../../debug/profile.js'; import { LifecycleConstant } from '../../lifecycle/constant.js'; -import { __root } from '../../root.js'; let isJSReady: boolean; let jsReadyEventIdSwap: Record; diff --git a/packages/react/runtime/src/lifecycle/isRendering.ts b/packages/react/runtime/src/snapshot/lifecycle/isRendering.ts similarity index 93% rename from packages/react/runtime/src/lifecycle/isRendering.ts rename to packages/react/runtime/src/snapshot/lifecycle/isRendering.ts index 4ca86b4b32..ac0d933c9f 100644 --- a/packages/react/runtime/src/lifecycle/isRendering.ts +++ b/packages/react/runtime/src/snapshot/lifecycle/isRendering.ts @@ -4,8 +4,8 @@ import { options } from 'preact'; +import { hook, lynxQueueMicrotask } from '../../utils.js'; import { RENDER_COMPONENT, ROOT } from '../renderToOpcodes/constants.js'; -import { hook, lynxQueueMicrotask } from '../utils.js'; export const isRendering = /* @__PURE__ */ { value: false }; diff --git a/packages/react/runtime/src/lifecycle/pass.ts b/packages/react/runtime/src/snapshot/lifecycle/pass.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/pass.ts rename to packages/react/runtime/src/snapshot/lifecycle/pass.ts diff --git a/packages/react/runtime/src/lifecycle/patch/commit.ts b/packages/react/runtime/src/snapshot/lifecycle/patch/commit.ts similarity index 99% rename from packages/react/runtime/src/lifecycle/patch/commit.ts rename to packages/react/runtime/src/snapshot/lifecycle/patch/commit.ts index ffb4349e67..531f108dfb 100644 --- a/packages/react/runtime/src/lifecycle/patch/commit.ts +++ b/packages/react/runtime/src/snapshot/lifecycle/patch/commit.ts @@ -29,13 +29,13 @@ import { } from './globalState.js'; import { takeGlobalSnapshotPatch } from './snapshotPatch.js'; import type { SnapshotPatch } from './snapshotPatch.js'; +import { hook, isEmptyObject } from '../../../utils.js'; import { profileEnd, profileStart } from '../../debug/profile.js'; import { LifecycleConstant } from '../../lifecycle/constant.js'; import { globalPipelineOptions, markTiming, markTimingLegacy, setPipeline } from '../../lynx/performance.js'; import { COMMIT } from '../../renderToOpcodes/constants.js'; import { backgroundSnapshotInstanceManager } from '../../snapshot/backgroundSnapshot.js'; import { applyQueuedRefs } from '../../snapshot/ref.js'; -import { hook, isEmptyObject } from '../../utils.js'; import { delayedRunOnMainThreadData, takeDelayedRunOnMainThreadData, diff --git a/packages/react/runtime/src/lifecycle/patch/error.ts b/packages/react/runtime/src/snapshot/lifecycle/patch/error.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/patch/error.ts rename to packages/react/runtime/src/snapshot/lifecycle/patch/error.ts diff --git a/packages/react/runtime/src/lifecycle/patch/globalState.ts b/packages/react/runtime/src/snapshot/lifecycle/patch/globalState.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/patch/globalState.ts rename to packages/react/runtime/src/snapshot/lifecycle/patch/globalState.ts diff --git a/packages/react/runtime/src/lifecycle/patch/isMainThreadHydrating.ts b/packages/react/runtime/src/snapshot/lifecycle/patch/isMainThreadHydrating.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/patch/isMainThreadHydrating.ts rename to packages/react/runtime/src/snapshot/lifecycle/patch/isMainThreadHydrating.ts diff --git a/packages/react/runtime/src/lifecycle/patch/snapshotPatch.ts b/packages/react/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/patch/snapshotPatch.ts rename to packages/react/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts diff --git a/packages/react/runtime/src/lifecycle/patch/snapshotPatchApply.ts b/packages/react/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/patch/snapshotPatchApply.ts rename to packages/react/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts diff --git a/packages/react/runtime/src/lifecycle/patch/updateMainThread.ts b/packages/react/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/patch/updateMainThread.ts rename to packages/react/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts diff --git a/packages/react/runtime/src/lifecycle/ref/delay.ts b/packages/react/runtime/src/snapshot/lifecycle/ref/delay.ts similarity index 100% rename from packages/react/runtime/src/lifecycle/ref/delay.ts rename to packages/react/runtime/src/snapshot/lifecycle/ref/delay.ts diff --git a/packages/react/runtime/src/lifecycle/reload.ts b/packages/react/runtime/src/snapshot/lifecycle/reload.ts similarity index 96% rename from packages/react/runtime/src/lifecycle/reload.ts rename to packages/react/runtime/src/snapshot/lifecycle/reload.ts index 79f4b013b7..88ec0692d9 100644 --- a/packages/react/runtime/src/lifecycle/reload.ts +++ b/packages/react/runtime/src/snapshot/lifecycle/reload.ts @@ -12,15 +12,15 @@ import { render } from 'preact'; import { destroyBackground } from './destroy.js'; import { increaseReloadVersion } from './pass.js'; import { renderMainThread } from './render.js'; +import { __root, setRoot } from '../../root.js'; +import { isEmptyObject } from '../../utils.js'; import { profileEnd, profileStart } from '../debug/profile.js'; import { LifecycleConstant } from '../lifecycle/constant.js'; import { __pendingListUpdates } from '../list/pendingListUpdates.js'; import { hydrate } from '../renderToOpcodes/hydrate.js'; -import { __root, setRoot } from '../root.js'; import { __page } from '../snapshot/definition.js'; import { SnapshotInstance, snapshotInstanceManager } from '../snapshot/snapshot.js'; import { applyRefQueue } from '../snapshot/workletRef.js'; -import { isEmptyObject } from '../utils.js'; import { clearJSReadyEventIdSwap, isJSReady } from './event/jsReady.js'; import { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js'; import { shouldDelayUiOps } from './ref/delay.js'; diff --git a/packages/react/runtime/src/lifecycle/render.ts b/packages/react/runtime/src/snapshot/lifecycle/render.ts similarity index 96% rename from packages/react/runtime/src/lifecycle/render.ts rename to packages/react/runtime/src/snapshot/lifecycle/render.ts index 898a081d35..04d7b541c4 100644 --- a/packages/react/runtime/src/lifecycle/render.ts +++ b/packages/react/runtime/src/snapshot/lifecycle/render.ts @@ -6,9 +6,9 @@ * Implements the IFR (Instant First-Frame Rendering) on main thread. */ +import { __root } from '../../root.js'; import { profileEnd, profileStart } from '../debug/profile.js'; import { render as renderToString } from '../renderToOpcodes/index.js'; -import { __root } from '../root.js'; import { SnapshotInstance } from '../snapshot/snapshot.js'; function renderMainThread(): void { diff --git a/packages/react/runtime/src/list/list.ts b/packages/react/runtime/src/snapshot/list/list.ts similarity index 99% rename from packages/react/runtime/src/list/list.ts rename to packages/react/runtime/src/snapshot/list/list.ts index 7569ae4270..9dbf2734ec 100644 --- a/packages/react/runtime/src/list/list.ts +++ b/packages/react/runtime/src/snapshot/list/list.ts @@ -1,10 +1,10 @@ // Copyright 2024 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. +import { maybePromise } from '../../utils.js'; import { LifecycleConstant } from '../lifecycle/constant.js'; import type { SnapshotInstance } from '../snapshot/snapshot.js'; import { applyRefQueue } from '../snapshot/workletRef.js'; -import { maybePromise } from '../utils.js'; export const gSignMap: Record> = {}; export const gRecycleMap: Record>> = {}; diff --git a/packages/react/runtime/src/list/listUpdateInfo.ts b/packages/react/runtime/src/snapshot/list/listUpdateInfo.ts similarity index 100% rename from packages/react/runtime/src/list/listUpdateInfo.ts rename to packages/react/runtime/src/snapshot/list/listUpdateInfo.ts diff --git a/packages/react/runtime/src/list/pendingListUpdates.ts b/packages/react/runtime/src/snapshot/list/pendingListUpdates.ts similarity index 100% rename from packages/react/runtime/src/list/pendingListUpdates.ts rename to packages/react/runtime/src/snapshot/list/pendingListUpdates.ts diff --git a/packages/react/runtime/src/lynx/calledByNative.ts b/packages/react/runtime/src/snapshot/lynx/calledByNative.ts similarity index 98% rename from packages/react/runtime/src/lynx/calledByNative.ts rename to packages/react/runtime/src/snapshot/lynx/calledByNative.ts index 7b397412ff..a1dc37780d 100644 --- a/packages/react/runtime/src/lynx/calledByNative.ts +++ b/packages/react/runtime/src/snapshot/lynx/calledByNative.ts @@ -2,6 +2,8 @@ // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. import { markTiming, setPipeline } from './performance.js'; +import { __root, setRoot } from '../../root.js'; +import { isEmptyObject } from '../../utils.js'; import { LifecycleConstant } from '../lifecycle/constant.js'; import { isJSReady, jsReady, jsReadyEventIdSwap, resetJSReady } from '../lifecycle/event/jsReady.js'; import { reloadMainThread } from '../lifecycle/reload.js'; @@ -9,11 +11,9 @@ import { renderMainThread } from '../lifecycle/render.js'; import { __pendingListUpdates } from '../list/pendingListUpdates.js'; import { hydrate } from '../renderToOpcodes/hydrate.js'; import { ssrHydrateByOpcodes } from '../renderToOpcodes/opcodes.js'; -import { __root, setRoot } from '../root.js'; import { __page, setupPage } from '../snapshot/definition.js'; import { SnapshotInstance } from '../snapshot/snapshot.js'; import { applyRefQueue } from '../snapshot/workletRef.js'; -import { isEmptyObject } from '../utils.js'; function ssrEncode() { const { __opcodes } = __root; diff --git a/packages/react/runtime/src/lynx/component.ts b/packages/react/runtime/src/snapshot/lynx/component.ts similarity index 100% rename from packages/react/runtime/src/lynx/component.ts rename to packages/react/runtime/src/snapshot/lynx/component.ts diff --git a/packages/react/runtime/src/lynx/dynamic-js.ts b/packages/react/runtime/src/snapshot/lynx/dynamic-js.ts similarity index 100% rename from packages/react/runtime/src/lynx/dynamic-js.ts rename to packages/react/runtime/src/snapshot/lynx/dynamic-js.ts diff --git a/packages/react/runtime/src/lynx/env.ts b/packages/react/runtime/src/snapshot/lynx/env.ts similarity index 99% rename from packages/react/runtime/src/lynx/env.ts rename to packages/react/runtime/src/snapshot/lynx/env.ts index 73a670cc7f..5fa934977d 100644 --- a/packages/react/runtime/src/lynx/env.ts +++ b/packages/react/runtime/src/snapshot/lynx/env.ts @@ -1,8 +1,8 @@ // Copyright 2024 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. +import type { DataProcessorDefinition, InitData, InitDataRaw } from '../../lynx-api.js'; import { profileEnd, profileStart } from '../debug/profile.js'; -import type { DataProcessorDefinition, InitData, InitDataRaw } from '../lynx-api.js'; export function setupLynxEnv(): void { if (!__LEPUS__) { diff --git a/packages/react/runtime/src/lynx/injectLepusMethods.ts b/packages/react/runtime/src/snapshot/lynx/injectLepusMethods.ts similarity index 100% rename from packages/react/runtime/src/lynx/injectLepusMethods.ts rename to packages/react/runtime/src/snapshot/lynx/injectLepusMethods.ts diff --git a/packages/react/runtime/src/lynx/lazy-bundle.ts b/packages/react/runtime/src/snapshot/lynx/lazy-bundle.ts similarity index 100% rename from packages/react/runtime/src/lynx/lazy-bundle.ts rename to packages/react/runtime/src/snapshot/lynx/lazy-bundle.ts diff --git a/packages/react/runtime/src/lynx/performance.ts b/packages/react/runtime/src/snapshot/lynx/performance.ts similarity index 98% rename from packages/react/runtime/src/lynx/performance.ts rename to packages/react/runtime/src/snapshot/lynx/performance.ts index 0c12e259c1..f12d6bf8a3 100644 --- a/packages/react/runtime/src/lynx/performance.ts +++ b/packages/react/runtime/src/snapshot/lynx/performance.ts @@ -3,9 +3,9 @@ // LICENSE file in the root directory of this source tree. import { options } from 'preact'; +import { hook, isSdkVersionGt } from '../../utils.js'; import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js'; import { RENDER_COMPONENT, ROOT } from '../renderToOpcodes/constants.js'; -import { hook, isSdkVersionGt } from '../utils.js'; const PerformanceTimingKeys = [ 'updateSetStateTrigger', diff --git a/packages/react/runtime/src/lynx/runWithForce.ts b/packages/react/runtime/src/snapshot/lynx/runWithForce.ts similarity index 97% rename from packages/react/runtime/src/lynx/runWithForce.ts rename to packages/react/runtime/src/snapshot/lynx/runWithForce.ts index efa79dc970..236ed3361c 100644 --- a/packages/react/runtime/src/lynx/runWithForce.ts +++ b/packages/react/runtime/src/snapshot/lynx/runWithForce.ts @@ -4,8 +4,8 @@ import { options } from 'preact'; import type { VNode } from 'preact'; +import { __root } from '../../root.js'; import { COMPONENT, DIFF2, FORCE, ORIGINAL } from '../renderToOpcodes/constants.js'; -import { __root } from '../root.js'; export function runWithForce(cb: () => void): void { // In https://github.com/preactjs/preact/pull/4724, preact will diff --git a/packages/react/runtime/src/lynx/suspense.ts b/packages/react/runtime/src/snapshot/lynx/suspense.ts similarity index 100% rename from packages/react/runtime/src/lynx/suspense.ts rename to packages/react/runtime/src/snapshot/lynx/suspense.ts diff --git a/packages/react/runtime/src/lynx/tt.ts b/packages/react/runtime/src/snapshot/lynx/tt.ts similarity index 99% rename from packages/react/runtime/src/lynx/tt.ts rename to packages/react/runtime/src/snapshot/lynx/tt.ts index 55552c182e..5e31140e65 100644 --- a/packages/react/runtime/src/lynx/tt.ts +++ b/packages/react/runtime/src/snapshot/lynx/tt.ts @@ -5,6 +5,7 @@ import { process, render } from 'preact'; import { PerformanceTimingFlags, PipelineOrigins, beginPipeline, markTiming } from './performance.js'; import { runWithForce } from './runWithForce.js'; +import { __root } from '../../root.js'; import { printSnapshotInstanceToString } from '../debug/printSnapshot.js'; import { profileEnd, profileStart } from '../debug/profile.js'; import { getSnapshotVNodeSource } from '../debug/vnodeSource.js'; @@ -19,7 +20,6 @@ import { removeCtxNotFoundEventListener } from '../lifecycle/patch/error.js'; import { runDelayedUiOps } from '../lifecycle/ref/delay.js'; import { reloadBackground } from '../lifecycle/reload.js'; import { CHILDREN } from '../renderToOpcodes/constants.js'; -import { __root } from '../root.js'; import { BackgroundSnapshotInstance, backgroundSnapshotInstanceManager, diff --git a/packages/react/runtime/src/renderToOpcodes/constants.ts b/packages/react/runtime/src/snapshot/renderToOpcodes/constants.ts similarity index 100% rename from packages/react/runtime/src/renderToOpcodes/constants.ts rename to packages/react/runtime/src/snapshot/renderToOpcodes/constants.ts diff --git a/packages/react/runtime/src/renderToOpcodes/hydrate.ts b/packages/react/runtime/src/snapshot/renderToOpcodes/hydrate.ts similarity index 99% rename from packages/react/runtime/src/renderToOpcodes/hydrate.ts rename to packages/react/runtime/src/snapshot/renderToOpcodes/hydrate.ts index 64a5e3403d..40987fd216 100644 --- a/packages/react/runtime/src/renderToOpcodes/hydrate.ts +++ b/packages/react/runtime/src/snapshot/renderToOpcodes/hydrate.ts @@ -9,7 +9,7 @@ import { DynamicPartType } from '../snapshot/dynamicPartType.js'; import type { PlatformInfo } from '../snapshot/platformInfo.js'; import { unref } from '../snapshot/ref.js'; import type { SnapshotInstance } from '../snapshot/snapshot.js'; -import { isEmptyObject } from '../utils.js'; +import { isEmptyObject } from '../../utils.js'; const UNREACHABLE_ITEM_KEY_NOT_FOUND = 'UNREACHABLE_ITEM_KEY_NOT_FOUND'; diff --git a/packages/react/runtime/src/renderToOpcodes/index.ts b/packages/react/runtime/src/snapshot/renderToOpcodes/index.ts similarity index 100% rename from packages/react/runtime/src/renderToOpcodes/index.ts rename to packages/react/runtime/src/snapshot/renderToOpcodes/index.ts diff --git a/packages/react/runtime/src/renderToOpcodes/opcodes.ts b/packages/react/runtime/src/snapshot/renderToOpcodes/opcodes.ts similarity index 100% rename from packages/react/runtime/src/renderToOpcodes/opcodes.ts rename to packages/react/runtime/src/snapshot/renderToOpcodes/opcodes.ts diff --git a/packages/react/runtime/src/snapshot/backgroundSnapshot.ts b/packages/react/runtime/src/snapshot/snapshot/backgroundSnapshot.ts similarity index 99% rename from packages/react/runtime/src/snapshot/backgroundSnapshot.ts rename to packages/react/runtime/src/snapshot/snapshot/backgroundSnapshot.ts index f1b1e7e5b6..4d777daf4f 100644 --- a/packages/react/runtime/src/snapshot/backgroundSnapshot.ts +++ b/packages/react/runtime/src/snapshot/snapshot/backgroundSnapshot.ts @@ -20,6 +20,7 @@ import { hydrationMap } from './snapshotInstanceHydrationMap.js'; import { transformSpread } from './spread.js'; import type { SerializedSnapshotInstance } from './types.js'; import { traverseSnapshotInstance } from './utils.js'; +import { isDirectOrDeepEqual } from '../../utils.js'; import { profileEnd, profileStart } from '../debug/profile.js'; import { clearSnapshotVNodeSource, getSnapshotVNodeSource, moveSnapshotVNodeSource } from '../debug/vnodeSource.js'; import { processGestureBackground } from '../gesture/processGestureBagkround.js'; @@ -34,7 +35,6 @@ import { import type { SnapshotPatch } from '../lifecycle/patch/snapshotPatch.js'; import { globalPipelineOptions } from '../lynx/performance.js'; import { diffArrayAction, diffArrayLepus } from '../renderToOpcodes/hydrate.js'; -import { isDirectOrDeepEqual } from '../utils.js'; import { onPostWorkletCtx } from '../worklet/ctx.js'; /** diff --git a/packages/react/runtime/src/snapshot/constants.ts b/packages/react/runtime/src/snapshot/snapshot/constants.ts similarity index 100% rename from packages/react/runtime/src/snapshot/constants.ts rename to packages/react/runtime/src/snapshot/snapshot/constants.ts diff --git a/packages/react/runtime/src/snapshot/definition.ts b/packages/react/runtime/src/snapshot/snapshot/definition.ts similarity index 100% rename from packages/react/runtime/src/snapshot/definition.ts rename to packages/react/runtime/src/snapshot/snapshot/definition.ts diff --git a/packages/react/runtime/src/snapshot/dynamicPartType.ts b/packages/react/runtime/src/snapshot/snapshot/dynamicPartType.ts similarity index 100% rename from packages/react/runtime/src/snapshot/dynamicPartType.ts rename to packages/react/runtime/src/snapshot/snapshot/dynamicPartType.ts diff --git a/packages/react/runtime/src/snapshot/event.ts b/packages/react/runtime/src/snapshot/snapshot/event.ts similarity index 100% rename from packages/react/runtime/src/snapshot/event.ts rename to packages/react/runtime/src/snapshot/snapshot/event.ts diff --git a/packages/react/runtime/src/snapshot/gesture.ts b/packages/react/runtime/src/snapshot/snapshot/gesture.ts similarity index 100% rename from packages/react/runtime/src/snapshot/gesture.ts rename to packages/react/runtime/src/snapshot/snapshot/gesture.ts diff --git a/packages/react/runtime/src/snapshot/snapshot/index.ts b/packages/react/runtime/src/snapshot/snapshot/index.ts new file mode 100644 index 0000000000..4f40a0fa0d --- /dev/null +++ b/packages/react/runtime/src/snapshot/snapshot/index.ts @@ -0,0 +1,8 @@ +// Copyright 2026 The Lynx Authors. All rights reserved. +// Licensed under the Apache License Version 2.0 that can be found in the +// LICENSE file in the root directory of this source tree. + +export { BackgroundSnapshotInstance, backgroundSnapshotInstanceManager, hydrate } from './backgroundSnapshot.js'; +export { SnapshotInstance, snapshotInstanceManager, snapshotCreatorMap } from './snapshot.js'; +export { snapshotManager, createSnapshot, setupPage, __page, __pageId, clearPage } from './definition.js'; +export { traverseSnapshotInstance } from './utils.js'; diff --git a/packages/react/runtime/src/snapshot/list.ts b/packages/react/runtime/src/snapshot/snapshot/list.ts similarity index 100% rename from packages/react/runtime/src/snapshot/list.ts rename to packages/react/runtime/src/snapshot/snapshot/list.ts diff --git a/packages/react/runtime/src/snapshot/platformInfo.ts b/packages/react/runtime/src/snapshot/snapshot/platformInfo.ts similarity index 100% rename from packages/react/runtime/src/snapshot/platformInfo.ts rename to packages/react/runtime/src/snapshot/snapshot/platformInfo.ts diff --git a/packages/react/runtime/src/snapshot/ref.ts b/packages/react/runtime/src/snapshot/snapshot/ref.ts similarity index 100% rename from packages/react/runtime/src/snapshot/ref.ts rename to packages/react/runtime/src/snapshot/snapshot/ref.ts diff --git a/packages/react/runtime/src/snapshot/snapshot.ts b/packages/react/runtime/src/snapshot/snapshot/snapshot.ts similarity index 99% rename from packages/react/runtime/src/snapshot/snapshot.ts rename to packages/react/runtime/src/snapshot/snapshot/snapshot.ts index 3f0b5e0693..a73c7a9c73 100644 --- a/packages/react/runtime/src/snapshot/snapshot.ts +++ b/packages/react/runtime/src/snapshot/snapshot/snapshot.ts @@ -19,11 +19,11 @@ import type { PlatformInfo } from './platformInfo.js'; import { unref } from './ref.js'; import type { SerializedSnapshotInstance } from './types.js'; import { traverseSnapshotInstance } from './utils.js'; +import { isDirectOrDeepEqual } from '../../utils.js'; import { clearSnapshotVNodeSource } from '../debug/vnodeSource.js'; import { SnapshotOperation, __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js'; import { ListUpdateInfoRecording } from '../list/listUpdateInfo.js'; import { __pendingListUpdates } from '../list/pendingListUpdates.js'; -import { isDirectOrDeepEqual } from '../utils.js'; export const snapshotInstanceManager: { nextId: number; diff --git a/packages/react/runtime/src/snapshot/snapshotInstanceHydrationMap.ts b/packages/react/runtime/src/snapshot/snapshot/snapshotInstanceHydrationMap.ts similarity index 100% rename from packages/react/runtime/src/snapshot/snapshotInstanceHydrationMap.ts rename to packages/react/runtime/src/snapshot/snapshot/snapshotInstanceHydrationMap.ts diff --git a/packages/react/runtime/src/snapshot/spread.ts b/packages/react/runtime/src/snapshot/snapshot/spread.ts similarity index 99% rename from packages/react/runtime/src/snapshot/spread.ts rename to packages/react/runtime/src/snapshot/snapshot/spread.ts index a68ffc45b9..a0ef1d439b 100644 --- a/packages/react/runtime/src/snapshot/spread.ts +++ b/packages/react/runtime/src/snapshot/snapshot/spread.ts @@ -12,16 +12,16 @@ import type { Element, Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings'; import type { BackgroundSnapshotInstance } from './backgroundSnapshot.js'; -import { ListUpdateInfoRecording } from '../list/listUpdateInfo.js'; -import { __pendingListUpdates } from '../list/pendingListUpdates.js'; -import { SnapshotInstance } from '../snapshot/snapshot.js'; -import { isDirectOrDeepEqual, isEmptyObject, pick } from '../utils.js'; import { updateEvent } from './event.js'; import { updateGesture } from './gesture.js'; import { platformInfoAttributes, updateListItemPlatformInfo } from './platformInfo.js'; import { transformRef, updateRef } from './ref.js'; import { updateWorkletEvent } from './workletEvent.js'; import { updateWorkletRef } from './workletRef.js'; +import { isDirectOrDeepEqual, isEmptyObject, pick } from '../../utils.js'; +import { ListUpdateInfoRecording } from '../list/listUpdateInfo.js'; +import { __pendingListUpdates } from '../list/pendingListUpdates.js'; +import { SnapshotInstance } from '../snapshot/snapshot.js'; // eslint-disable-next-line regexp/no-unused-capturing-group const eventRegExp = /^(([A-Za-z-]*):)?(bind|catch|capture-bind|capture-catch|global-bind)([A-Za-z]+)$/; diff --git a/packages/react/runtime/src/snapshot/types.ts b/packages/react/runtime/src/snapshot/snapshot/types.ts similarity index 100% rename from packages/react/runtime/src/snapshot/types.ts rename to packages/react/runtime/src/snapshot/snapshot/types.ts diff --git a/packages/react/runtime/src/snapshot/utils.ts b/packages/react/runtime/src/snapshot/snapshot/utils.ts similarity index 100% rename from packages/react/runtime/src/snapshot/utils.ts rename to packages/react/runtime/src/snapshot/snapshot/utils.ts diff --git a/packages/react/runtime/src/snapshot/workletEvent.ts b/packages/react/runtime/src/snapshot/snapshot/workletEvent.ts similarity index 100% rename from packages/react/runtime/src/snapshot/workletEvent.ts rename to packages/react/runtime/src/snapshot/snapshot/workletEvent.ts diff --git a/packages/react/runtime/src/snapshot/workletRef.ts b/packages/react/runtime/src/snapshot/snapshot/workletRef.ts similarity index 100% rename from packages/react/runtime/src/snapshot/workletRef.ts rename to packages/react/runtime/src/snapshot/snapshot/workletRef.ts diff --git a/packages/react/runtime/src/worklet/call/delayedRunOnMainThreadData.ts b/packages/react/runtime/src/snapshot/worklet/call/delayedRunOnMainThreadData.ts similarity index 100% rename from packages/react/runtime/src/worklet/call/delayedRunOnMainThreadData.ts rename to packages/react/runtime/src/snapshot/worklet/call/delayedRunOnMainThreadData.ts diff --git a/packages/react/runtime/src/worklet/call/execMap.ts b/packages/react/runtime/src/snapshot/worklet/call/execMap.ts similarity index 100% rename from packages/react/runtime/src/worklet/call/execMap.ts rename to packages/react/runtime/src/snapshot/worklet/call/execMap.ts diff --git a/packages/react/runtime/src/worklet/call/functionCall.ts b/packages/react/runtime/src/snapshot/worklet/call/functionCall.ts similarity index 100% rename from packages/react/runtime/src/worklet/call/functionCall.ts rename to packages/react/runtime/src/snapshot/worklet/call/functionCall.ts diff --git a/packages/react/runtime/src/worklet/call/runOnBackground.ts b/packages/react/runtime/src/snapshot/worklet/call/runOnBackground.ts similarity index 100% rename from packages/react/runtime/src/worklet/call/runOnBackground.ts rename to packages/react/runtime/src/snapshot/worklet/call/runOnBackground.ts diff --git a/packages/react/runtime/src/worklet/call/runOnMainThread.ts b/packages/react/runtime/src/snapshot/worklet/call/runOnMainThread.ts similarity index 100% rename from packages/react/runtime/src/worklet/call/runOnMainThread.ts rename to packages/react/runtime/src/snapshot/worklet/call/runOnMainThread.ts diff --git a/packages/react/runtime/src/worklet/call/transformToWorklet.ts b/packages/react/runtime/src/snapshot/worklet/call/transformToWorklet.ts similarity index 100% rename from packages/react/runtime/src/worklet/call/transformToWorklet.ts rename to packages/react/runtime/src/snapshot/worklet/call/transformToWorklet.ts diff --git a/packages/react/runtime/src/worklet/ctx.ts b/packages/react/runtime/src/snapshot/worklet/ctx.ts similarity index 100% rename from packages/react/runtime/src/worklet/ctx.ts rename to packages/react/runtime/src/snapshot/worklet/ctx.ts diff --git a/packages/react/runtime/src/worklet/destroy.ts b/packages/react/runtime/src/snapshot/worklet/destroy.ts similarity index 100% rename from packages/react/runtime/src/worklet/destroy.ts rename to packages/react/runtime/src/snapshot/worklet/destroy.ts diff --git a/packages/react/runtime/src/worklet/functionality.ts b/packages/react/runtime/src/snapshot/worklet/functionality.ts similarity index 93% rename from packages/react/runtime/src/worklet/functionality.ts rename to packages/react/runtime/src/snapshot/worklet/functionality.ts index c716877f8d..0f52dfc771 100644 --- a/packages/react/runtime/src/worklet/functionality.ts +++ b/packages/react/runtime/src/snapshot/worklet/functionality.ts @@ -2,7 +2,7 @@ // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. -import { isSdkVersionGt } from '../utils.js'; +import { isSdkVersionGt } from '../../utils.js'; let mtsEnabled: boolean | undefined; let runOnBackgroundEnabled: boolean | undefined; diff --git a/packages/react/runtime/src/worklet/hmr.ts b/packages/react/runtime/src/snapshot/worklet/hmr.ts similarity index 100% rename from packages/react/runtime/src/worklet/hmr.ts rename to packages/react/runtime/src/snapshot/worklet/hmr.ts diff --git a/packages/react/runtime/src/worklet/indexMap.ts b/packages/react/runtime/src/snapshot/worklet/indexMap.ts similarity index 100% rename from packages/react/runtime/src/worklet/indexMap.ts rename to packages/react/runtime/src/snapshot/worklet/indexMap.ts diff --git a/packages/react/runtime/src/worklet/ref/updateInitValue.ts b/packages/react/runtime/src/snapshot/worklet/ref/updateInitValue.ts similarity index 100% rename from packages/react/runtime/src/worklet/ref/updateInitValue.ts rename to packages/react/runtime/src/snapshot/worklet/ref/updateInitValue.ts diff --git a/packages/react/runtime/src/worklet/ref/workletRef.ts b/packages/react/runtime/src/snapshot/worklet/ref/workletRef.ts similarity index 100% rename from packages/react/runtime/src/worklet/ref/workletRef.ts rename to packages/react/runtime/src/snapshot/worklet/ref/workletRef.ts diff --git a/packages/react/runtime/src/worklet/ref/workletRefPool.ts b/packages/react/runtime/src/snapshot/worklet/ref/workletRefPool.ts similarity index 100% rename from packages/react/runtime/src/worklet/ref/workletRefPool.ts rename to packages/react/runtime/src/snapshot/worklet/ref/workletRefPool.ts diff --git a/packages/react/runtime/src/utils.ts b/packages/react/runtime/src/utils.ts index da29803abd..c5c4d562cd 100644 --- a/packages/react/runtime/src/utils.ts +++ b/packages/react/runtime/src/utils.ts @@ -4,7 +4,7 @@ import type { ComponentClass } from 'preact'; -import { getCurrentVNode, getOwnerStack } from './debug/component-stack.js'; +import { getCurrentVNode, getOwnerStack } from './snapshot/debug/component-stack.js'; /* v8 ignore start */ export const noop: (...args: unknown[]) => unknown = () => {}; diff --git a/packages/react/runtime/types/types.d.ts b/packages/react/runtime/types/types.d.ts index 14b7072d57..c2e7b2fec6 100644 --- a/packages/react/runtime/types/types.d.ts +++ b/packages/react/runtime/types/types.d.ts @@ -4,7 +4,7 @@ import { EventEmitter } from '@lynx-js/types'; -import { LifecycleConstant } from '../src/lifecycle/constant.js'; +import { LifecycleConstant } from '../src/snapshot/lifecycle/constant.js'; import { Lynx as LynxApi } from '../src/lynx-api.js'; import type { InitData, InitDataRaw } from '../src/lynx-api.js'; diff --git a/packages/react/runtime/vitest.config.ts b/packages/react/runtime/vitest.config.ts index 38178d3d1d..69747ac0e3 100644 --- a/packages/react/runtime/vitest.config.ts +++ b/packages/react/runtime/vitest.config.ts @@ -68,7 +68,7 @@ export default defineConfig({ '@lynx-js/react/jsx-dev-runtime': path.resolve(__dirname, './jsx-dev-runtime/index.js'), '@lynx-js/react/jsx-runtime': path.resolve(__dirname, './jsx-runtime/index.js'), '@lynx-js/react/lepus': path.resolve(__dirname, './lepus/index.js'), - '@lynx-js/react/legacy-react-runtime': path.resolve(__dirname, './src/legacy-react-runtime/index.ts'), + '@lynx-js/react/legacy-react-runtime': path.resolve(__dirname, './src/snapshot/legacy-react-runtime/index.ts'), '@lynx-js/react': path.resolve(__dirname, './src/index.ts'), }, }, @@ -82,7 +82,7 @@ export default defineConfig({ 'lepus/jsx-dev-runtime', 'lepus/index.d.ts', 'vitest.config.ts', - '__test__/utils/**', + '__test__/snapshot/utils/**', 'lib/**', 'worklet-runtime/**', 'src/index.ts', @@ -95,17 +95,17 @@ export default defineConfig({ 'src/worklet-runtime/index.ts', 'src/worklet-runtime/listeners.ts', 'src/worklet-runtime/types/**', - 'src/debug/component-stack.ts', - 'src/debug/debug.ts', - 'src/debug/utils.ts', - 'src/lynx/calledByNative.ts', - 'src/lynx/component.ts', - 'src/lynx/dynamic-js.ts', - 'src/lynx/env.ts', - 'src/lynx/tt.ts', - 'src/compat/componentIs.ts', + 'src/snapshot/debug/component-stack.ts', + 'src/snapshot/debug/debug.ts', + 'src/snapshot/debug/utils.ts', + 'src/snapshot/lynx/calledByNative.ts', + 'src/snapshot/lynx/component.ts', + 'src/snapshot/lynx/dynamic-js.ts', + 'src/snapshot/lynx/env.ts', + 'src/snapshot/lynx/tt.ts', + 'src/snapshot/compat/componentIs.ts', - '__test__/page.test.jsx', + '__test__/snapshot/page.test.jsx', '**/*.d.ts', '**/*.test-d.*', ], @@ -117,9 +117,9 @@ export default defineConfig({ }, }, setupFiles: [ - path.join(__dirname, './__test__/utils/globals.js'), - path.join(__dirname, './__test__/utils/setup.js'), - path.join(__dirname, './__test__/utils/runtimeProxy.ts'), + path.join(__dirname, './__test__/snapshot/utils/globals.js'), + path.join(__dirname, './__test__/snapshot/utils/setup.js'), + path.join(__dirname, './__test__/snapshot/utils/runtimeProxy.ts'), ], }, }); diff --git a/packages/react/testing-library/src/__tests__/act.test.jsx b/packages/react/testing-library/src/__tests__/act.test.jsx index c82c36794d..ef9d22ae9f 100644 --- a/packages/react/testing-library/src/__tests__/act.test.jsx +++ b/packages/react/testing-library/src/__tests__/act.test.jsx @@ -6,7 +6,7 @@ import { useEffect, useState } from 'preact/hooks'; import { createRef } from 'preact'; import { Component } from 'preact'; import { expect } from 'vitest'; -import { __globalSnapshotPatch } from '../../../runtime/lib/lifecycle/patch/snapshotPatch.js'; +import { __globalSnapshotPatch } from '../../../runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js'; import { snapshotInstanceManager } from '../../../runtime/lib/snapshot/index.js'; test('render calls useEffect immediately', async () => { diff --git a/packages/react/testing-library/src/__tests__/lazy-bundle/index.test.jsx b/packages/react/testing-library/src/__tests__/lazy-bundle/index.test.jsx index 26f0323215..68c5df45f3 100644 --- a/packages/react/testing-library/src/__tests__/lazy-bundle/index.test.jsx +++ b/packages/react/testing-library/src/__tests__/lazy-bundle/index.test.jsx @@ -6,7 +6,7 @@ import { BackgroundSnapshotInstance } from '@lynx-js/react/internal'; import { Suspense as PreactSuspense } from 'preact/compat'; import { createRequire } from 'node:module'; import { describe } from 'node:test'; -import { prettyFormatSnapshotPatch } from '../../../../runtime/lib/debug/formatPatch'; +import { prettyFormatSnapshotPatch } from '../../../../runtime/lib/snapshot/debug/formatPatch'; const SuspenseMap = { LynxSuspense: Suspense, diff --git a/packages/react/testing-library/src/__tests__/list.test.jsx b/packages/react/testing-library/src/__tests__/list.test.jsx index 0bca0351b4..263dc63952 100644 --- a/packages/react/testing-library/src/__tests__/list.test.jsx +++ b/packages/react/testing-library/src/__tests__/list.test.jsx @@ -8,7 +8,7 @@ import { describe, expect, vi } from 'vitest'; import { Component, useState } from '@lynx-js/react'; import { render } from '..'; -import { __pendingListUpdates } from '../../../runtime/lib/list/pendingListUpdates.js'; +import { __pendingListUpdates } from '../../../runtime/lib/snapshot/list/pendingListUpdates.js'; describe('list', () => { it('basic', async () => { diff --git a/packages/react/testing-library/src/__tests__/lynx.test.jsx b/packages/react/testing-library/src/__tests__/lynx.test.jsx index 1495362095..43089ef696 100644 --- a/packages/react/testing-library/src/__tests__/lynx.test.jsx +++ b/packages/react/testing-library/src/__tests__/lynx.test.jsx @@ -1,11 +1,11 @@ import { describe, expect, it, vi } from 'vitest'; import { render } from '..'; +import { prettyFormatSnapshotPatch } from '../../../runtime/lib/snapshot/debug/formatPatch'; import { __globalSnapshotPatch, initGlobalSnapshotPatch, SnapshotOperation, -} from '../../../runtime/lib/lifecycle/patch/snapshotPatch'; -import { prettyFormatSnapshotPatch } from '../../../runtime/lib/debug/formatPatch'; +} from '../../../runtime/lib/snapshot/lifecycle/patch/snapshotPatch'; describe('lynx global API', () => { it('getJSModule should work', () => { diff --git a/packages/react/testing-library/src/__tests__/renderComponent.test.jsx b/packages/react/testing-library/src/__tests__/renderComponent.test.jsx index 87eeda9755..a1315537f7 100644 --- a/packages/react/testing-library/src/__tests__/renderComponent.test.jsx +++ b/packages/react/testing-library/src/__tests__/renderComponent.test.jsx @@ -2,7 +2,7 @@ import { expect } from 'vitest'; import { Component, useState } from '@lynx-js/react'; import { render, act } from '..'; -import { prettyFormatSnapshotPatch } from '../../../runtime/lib/debug/formatPatch'; +import { prettyFormatSnapshotPatch } from '../../../runtime/lib/snapshot/debug/formatPatch'; test('setState generates insertBefore operation', async () => { vi.spyOn(lynxTestingEnv.backgroundThread.lynxCoreInject.tt, 'OnLifecycleEvent'); diff --git a/packages/react/testing-library/src/__tests__/setState-jsx.test.jsx b/packages/react/testing-library/src/__tests__/setState-jsx.test.jsx index e0701d1427..d4d902d889 100644 --- a/packages/react/testing-library/src/__tests__/setState-jsx.test.jsx +++ b/packages/react/testing-library/src/__tests__/setState-jsx.test.jsx @@ -2,7 +2,7 @@ import { expect } from 'vitest'; import { Component, useState } from '@lynx-js/react'; import { fireEvent, render, act } from '..'; -import { prettyFormatSnapshotPatch } from '../../../runtime/lib/debug/formatPatch'; +import { prettyFormatSnapshotPatch } from '../../../runtime/lib/snapshot/debug/formatPatch'; test('setState changes jsx', async () => { vi.spyOn(lynxTestingEnv.backgroundThread.lynxCoreInject.tt, 'OnLifecycleEvent'); diff --git a/packages/react/testing-library/src/__tests__/spread.test.jsx b/packages/react/testing-library/src/__tests__/spread.test.jsx index ca72d36e06..dcaf8fec2b 100644 --- a/packages/react/testing-library/src/__tests__/spread.test.jsx +++ b/packages/react/testing-library/src/__tests__/spread.test.jsx @@ -3,7 +3,7 @@ import { vi } from 'vitest'; import { act, render } from '..'; import { expect } from 'vitest'; import { useState } from 'preact/hooks'; -import { prettyFormatSnapshotPatch } from '../../../runtime/lib/debug/formatPatch'; +import { prettyFormatSnapshotPatch } from '../../../runtime/lib/snapshot/debug/formatPatch'; import { BackgroundSnapshotInstance } from '@lynx-js/react/internal'; test('re-render with same style should not generate patch without spread', () => { diff --git a/packages/react/testing-library/src/__tests__/text.test.jsx b/packages/react/testing-library/src/__tests__/text.test.jsx index 70ac048fae..71415936fb 100644 --- a/packages/react/testing-library/src/__tests__/text.test.jsx +++ b/packages/react/testing-library/src/__tests__/text.test.jsx @@ -3,7 +3,7 @@ import { vi } from 'vitest'; import { render, fireEvent } from '..'; import { expect } from 'vitest'; import { useState } from 'preact/hooks'; -import { prettyFormatSnapshotPatch } from '../../../runtime/lib/debug/formatPatch'; +import { prettyFormatSnapshotPatch } from '../../../runtime/lib/snapshot/debug/formatPatch'; describe('should only render text when it is not empty', () => { it('empty text should not be rendered', () => { diff --git a/packages/react/testing-library/src/pure.jsx b/packages/react/testing-library/src/pure.jsx index 5eef77f076..a8c5aa96bc 100644 --- a/packages/react/testing-library/src/pure.jsx +++ b/packages/react/testing-library/src/pure.jsx @@ -8,7 +8,7 @@ import { act } from 'preact/test-utils'; import { __root } from '@lynx-js/react/internal'; -import { flushDelayedLifecycleEvents } from '../../runtime/lib/lynx/tt.js'; +import { flushDelayedLifecycleEvents } from '../../runtime/lib/snapshot/lynx/tt.js'; import { clearPage } from '../../runtime/lib/snapshot/index.js'; export function waitSchedule() { diff --git a/packages/react/testing-library/src/setupFiles/common/runtime-setup.js b/packages/react/testing-library/src/setupFiles/common/runtime-setup.js index 42ac2c8450..d688e6058a 100644 --- a/packages/react/testing-library/src/setupFiles/common/runtime-setup.js +++ b/packages/react/testing-library/src/setupFiles/common/runtime-setup.js @@ -1,13 +1,13 @@ import { options } from 'preact'; -import { clearCommitTaskId, replaceCommitHook } from '../../../../runtime/lib/lifecycle/patch/commit.js'; -import { deinitGlobalSnapshotPatch } from '../../../../runtime/lib/lifecycle/patch/snapshotPatch.js'; -import { injectUpdateMainThread } from '../../../../runtime/lib/lifecycle/patch/updateMainThread.js'; -import { injectUpdateMTRefInitValue } from '../../../../runtime/lib/worklet/ref/updateInitValue.js'; -import { injectCalledByNative } from '../../../../runtime/lib/lynx/calledByNative.js'; -import { flushDelayedLifecycleEvents, injectTt } from '../../../../runtime/lib/lynx/tt.js'; -import { initElementPAPICallAlog } from '../../../../runtime/lib/alog/elementPAPICall.js'; -import { addCtxNotFoundEventListener } from '../../../../runtime/lib/lifecycle/patch/error.js'; +import { clearCommitTaskId, replaceCommitHook } from '../../../../runtime/lib/snapshot/lifecycle/patch/commit.js'; +import { deinitGlobalSnapshotPatch } from '../../../../runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js'; +import { injectUpdateMainThread } from '../../../../runtime/lib/snapshot/lifecycle/patch/updateMainThread.js'; +import { injectUpdateMTRefInitValue } from '../../../../runtime/lib/snapshot/worklet/ref/updateInitValue.js'; +import { injectCalledByNative } from '../../../../runtime/lib/snapshot/lynx/calledByNative.js'; +import { flushDelayedLifecycleEvents, injectTt } from '../../../../runtime/lib/snapshot/lynx/tt.js'; +import { initElementPAPICallAlog } from '../../../../runtime/lib/snapshot/alog/elementPAPICall.js'; +import { addCtxNotFoundEventListener } from '../../../../runtime/lib/snapshot/lifecycle/patch/error.js'; import { setRoot } from '../../../../runtime/lib/root.js'; import { SnapshotInstance, @@ -15,7 +15,7 @@ import { backgroundSnapshotInstanceManager, snapshotInstanceManager, } from '../../../../runtime/lib/snapshot/index.js'; -import { destroyWorklet } from '../../../../runtime/lib/worklet/destroy.js'; +import { destroyWorklet } from '../../../../runtime/lib/snapshot/worklet/destroy.js'; import { initApiEnv } from '../../../../runtime/lib/worklet-runtime/api/lynxApi.js'; import { initEventListeners } from '../../../../runtime/lib/worklet-runtime/listeners.js'; import { initWorklet } from '../../../../runtime/lib/worklet-runtime/workletRuntime.js'; diff --git a/packages/react/types/react.docs.d.ts b/packages/react/types/react.docs.d.ts index a1ffd2fd53..cae483da0c 100644 --- a/packages/react/types/react.docs.d.ts +++ b/packages/react/types/react.docs.d.ts @@ -48,7 +48,7 @@ export { useSyncExternalStore, } from 'react'; -export { useEffect, useLayoutEffect, useErrorBoundary } from '../runtime/lib/hooks/react.js'; +export { useEffect, useLayoutEffect, useErrorBoundary } from '../runtime/lib/snapshot/hooks/react.js'; /** * Built-in React APIs diff --git a/packages/rspeedy/lynx-bundle-rslib-config/test/external-bundle.test.ts b/packages/rspeedy/lynx-bundle-rslib-config/test/external-bundle.test.ts index b5515aa8f8..3ea7a6e654 100644 --- a/packages/rspeedy/lynx-bundle-rslib-config/test/external-bundle.test.ts +++ b/packages/rspeedy/lynx-bundle-rslib-config/test/external-bundle.test.ts @@ -706,7 +706,7 @@ describe('pluginReactLynx', () => { "@lynx-js/react/internal$": "/packages/react/runtime/lib/internal.js", "@lynx-js/react/jsx-dev-runtime": "/packages/react/runtime/jsx-dev-runtime/index.js", "@lynx-js/react/jsx-runtime": "/packages/react/runtime/jsx-runtime/index.js", - "@lynx-js/react/legacy-react-runtime$": "/packages/react/runtime/lib/legacy-react-runtime/index.js", + "@lynx-js/react/legacy-react-runtime$": "/packages/react/runtime/lib/snapshot/legacy-react-runtime/index.js", "@lynx-js/react/runtime-components$": "/packages/react/components/lib/index.js", "@lynx-js/react/worklet-runtime/bindings$": "/packages/react/runtime/lib/worklet-runtime/bindings/index.js", "@swc/helpers": "/node_modules//@swc/helpers", diff --git a/packages/rspeedy/plugin-react-alias/test/index.test.ts b/packages/rspeedy/plugin-react-alias/test/index.test.ts index 8e565e124c..d0dd151d45 100644 --- a/packages/rspeedy/plugin-react-alias/test/index.test.ts +++ b/packages/rspeedy/plugin-react-alias/test/index.test.ts @@ -212,7 +212,7 @@ describe('React - alias', () => { expect(mainThreadRule.resolve.alias).toHaveProperty( 'preact/hooks', expect.stringContaining( - '/packages/react/runtime/lib/hooks/mainThread.js'.replaceAll( + '/packages/react/runtime/lib/snapshot/hooks/mainThread.js'.replaceAll( '/', path.sep, ), @@ -221,7 +221,7 @@ describe('React - alias', () => { expect(mainThreadRule.resolve.alias).toHaveProperty( '@lynx-js/react/hooks', expect.stringContaining( - '/packages/react/runtime/lib/hooks/mainThread.js'.replaceAll( + '/packages/react/runtime/lib/snapshot/hooks/mainThread.js'.replaceAll( '/', path.sep, ), @@ -230,7 +230,7 @@ describe('React - alias', () => { expect(mainThreadRule.resolve.alias).toHaveProperty( '@lynx-js/react/lepus/hooks', expect.stringContaining( - '/packages/react/runtime/lib/hooks/mainThread.js'.replaceAll( + '/packages/react/runtime/lib/snapshot/hooks/mainThread.js'.replaceAll( '/', path.sep, ), @@ -272,7 +272,7 @@ describe('React - alias', () => { expect(backgroundRule.resolve.alias).toHaveProperty( '@lynx-js/react/hooks', expect.stringContaining( - '/packages/react/runtime/lib/hooks/react.js'.replaceAll( + '/packages/react/runtime/lib/snapshot/hooks/react.js'.replaceAll( '/', path.sep, ),