@lynx-js/react 0.127.0 → 0.129.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -14
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/entry-re-eval.test.ts +161 -0
- package/runtime/__test__/core/reload-scoped-dual-thread-communication.test.ts +129 -0
- package/runtime/__test__/core/thread-function-call.test.ts +1 -0
- package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +2 -0
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -1
- package/runtime/__test__/element-template/native/index.test.ts +8 -0
- package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +101 -0
- package/runtime/__test__/element-template/native/reload.test.ts +50 -1
- package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
- package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +39 -48
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +14 -10
- package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -0
- package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +31 -5
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +17 -3
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +8 -3
- package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +89 -2
- package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +5 -0
- package/runtime/__test__/element-template/test-utils/mock/globals.js +6 -0
- package/runtime/__test__/element-template/vitest.config.ts +4 -0
- package/runtime/__test__/snapshot/lifecycle/re-eval-reload.test.jsx +114 -0
- package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +169 -0
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +63 -0
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-main-thread.test.jsx +103 -0
- package/runtime/__test__/snapshot/lifecycle.test.jsx +61 -1
- package/runtime/__test__/snapshot/lynx/lazy-effect-scheduling.test.jsx +105 -0
- package/runtime/__test__/snapshot/ssr.test.jsx +2 -2
- package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +6 -11
- package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +1 -1
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +24 -1
- package/runtime/__test__/worklet-runtime/initEntry.test.js +109 -0
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +15 -1
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
- package/runtime/__test__/worklet-runtime/object-methods.test.js +2 -3
- package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
- package/runtime/lazy/element-template-internal.js +0 -1
- package/runtime/lazy/internal.js +0 -1
- package/runtime/lib/core/background-function/exec-map.d.ts +2 -0
- package/runtime/lib/core/background-function/exec-map.js +7 -0
- package/runtime/lib/core/background-function/exec-map.js.map +1 -1
- package/runtime/lib/core/background-function/handle.js.map +1 -1
- package/runtime/lib/core/background-function/run-on-background.js +15 -16
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
- package/runtime/lib/core/card-lifetime.d.ts +5 -0
- package/runtime/lib/core/card-lifetime.js +17 -0
- package/runtime/lib/core/card-lifetime.js.map +1 -0
- package/runtime/lib/core/commit-context.js.map +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/compat/lynxComponent.js.map +1 -1
- package/runtime/lib/core/component.js.map +1 -1
- package/runtime/lib/core/entry-reload.d.ts +7 -0
- package/runtime/lib/core/entry-reload.js +49 -0
- package/runtime/lib/core/entry-reload.js.map +1 -0
- package/runtime/lib/core/forceRootRender.js.map +1 -1
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/hooks/mainThread.js.map +1 -1
- package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
- package/runtime/lib/core/hooks/react.js.map +1 -1
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
- package/runtime/lib/core/initData.js.map +1 -1
- package/runtime/lib/core/lynx/dynamic-import.js.map +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js +4 -1
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-backend.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-version.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/lynx-page-data.js.map +1 -1
- package/runtime/lib/core/lynx-update-data.js.map +1 -1
- package/runtime/lib/core/main-thread-function.js.map +1 -1
- package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -1
- package/runtime/lib/core/main-thread-object.js +1 -4
- package/runtime/lib/core/main-thread-object.js.map +1 -1
- package/runtime/lib/core/main-thread-ref-id.js +4 -4
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
- package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
- package/runtime/lib/core/main-thread-ref.js.map +1 -1
- package/runtime/lib/core/mts-capability.js.map +1 -1
- package/runtime/lib/core/performance.js.map +1 -1
- package/runtime/lib/core/ref.js.map +1 -1
- package/runtime/lib/core/reload-scoped-event.d.ts +5 -0
- package/runtime/lib/core/reload-scoped-event.js +26 -0
- package/runtime/lib/core/reload-scoped-event.js.map +1 -0
- package/runtime/lib/core/reload-version.js +4 -3
- package/runtime/lib/core/reload-version.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.d.ts +2 -0
- package/runtime/lib/core/runtime-destroy.js +9 -0
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/core/thread-function-call/main-thread.js +5 -4
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/core/thread-function-call/return-value.js +6 -5
- package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
- package/runtime/lib/document.js.map +1 -1
- package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
- package/runtime/lib/element-template/background/commit-context.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js +19 -16
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/document.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js +2 -6
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/background/instance.js.map +1 -1
- package/runtime/lib/element-template/background/manager.js.map +1 -1
- package/runtime/lib/element-template/background/page-root-hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/render-scope.js.map +1 -1
- package/runtime/lib/element-template/client/root.js.map +1 -1
- package/runtime/lib/element-template/debug/alog.js.map +1 -1
- package/runtime/lib/element-template/debug/elementPAPICall.js.map +1 -1
- package/runtime/lib/element-template/debug/profile.js.map +1 -1
- package/runtime/lib/element-template/hydration-map.js.map +1 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +0 -1
- package/runtime/lib/element-template/internal.js +0 -1
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/jsx-dev-runtime/index.js.map +1 -1
- package/runtime/lib/element-template/jsx-runtime/index.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/lynx/performance.js.map +1 -1
- package/runtime/lib/element-template/main-thread-ref-init-value.d.ts +3 -0
- package/runtime/lib/element-template/main-thread-ref-init-value.js +38 -0
- package/runtime/lib/element-template/main-thread-ref-init-value.js.map +1 -0
- package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
- package/runtime/lib/element-template/native/index.js +2 -0
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js +2 -0
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +1 -4
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.d.ts +1 -1
- package/runtime/lib/element-template/native/reload-background.js +12 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.d.ts +6 -0
- package/runtime/lib/element-template/native/reload-main-thread.js +18 -2
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/event-value.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/event.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.d.ts +2 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.js +1 -0
- package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
- package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
- package/runtime/lib/element-template/protocol/page.js.map +1 -1
- package/runtime/lib/element-template/protocol/template-type.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +0 -2
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/protocol/update-event.js.map +1 -1
- package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/authored-page.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/host.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
- package/runtime/lib/element-template/runtime-marker.js.map +1 -1
- package/runtime/lib/index.js.map +1 -1
- package/runtime/lib/internal.d.ts +0 -1
- package/runtime/lib/internal.js +0 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/root.js.map +1 -1
- package/runtime/lib/runtime-marker.js.map +1 -1
- package/runtime/lib/shared/attribute-name.js.map +1 -1
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/shared/index-map.d.ts +4 -1
- package/runtime/lib/shared/index-map.js +5 -2
- package/runtime/lib/shared/index-map.js.map +1 -1
- package/runtime/lib/shared/profile.js.map +1 -1
- package/runtime/lib/shared/render-constants.js.map +1 -1
- package/runtime/lib/snapshot/alog/elementPAPICall.js.map +1 -1
- package/runtime/lib/snapshot/alog/index.js.map +1 -1
- package/runtime/lib/snapshot/alog/render.js.map +1 -1
- package/runtime/lib/snapshot/compat/componentIs.js.map +1 -1
- package/runtime/lib/snapshot/debug/debug.js.map +1 -1
- package/runtime/lib/snapshot/debug/describeInvalidValue.js.map +1 -1
- package/runtime/lib/snapshot/debug/formatPatch.js.map +1 -1
- package/runtime/lib/snapshot/debug/printSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/debug/vnodeSource.js.map +1 -1
- package/runtime/lib/snapshot/gesture/processGesture.js.map +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +1 -1
- package/runtime/lib/snapshot/gesture/types.js.map +1 -1
- package/runtime/lib/snapshot/index.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/constant.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/destroy.js +6 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/delayEvents.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/delayLifecycleEvents.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +6 -2
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +21 -18
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/globalState.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/isMainThreadHydrating.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/nodesRefApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.d.ts +9 -2
- package/runtime/lib/snapshot/lifecycle/reload.js +29 -8
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/render.js.map +1 -1
- package/runtime/lib/snapshot/list/list.js +3 -2
- package/runtime/lib/snapshot/list/list.js.map +1 -1
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/list/pendingListUpdates.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +3 -3
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/lynx/children.js.map +1 -1
- package/runtime/lib/snapshot/lynx/element.js.map +1 -1
- package/runtime/lib/snapshot/lynx/env.js.map +1 -1
- package/runtime/lib/snapshot/lynx/injectLepusMethods.js.map +1 -1
- package/runtime/lib/snapshot/lynx/lazyBundleConstants.js.map +1 -1
- package/runtime/lib/snapshot/lynx/nodesRef.js.map +1 -1
- package/runtime/lib/snapshot/lynx/performance.js.map +1 -1
- package/runtime/lib/snapshot/lynx/portals.js.map +1 -1
- package/runtime/lib/snapshot/lynx/portalsPending.js.map +1 -1
- package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.js.map +1 -1
- package/runtime/lib/snapshot/lynx/runWithForce.js.map +1 -1
- package/runtime/lib/snapshot/lynx/suspense.js.map +1 -1
- package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/constants.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/definition.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/dynamicPartType.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/event.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/gesture.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/index.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/list.js +2 -1
- package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/reconstructInstanceTree.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceHydrationMap.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +4 -2
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +11 -11
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/types.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/utils.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/workletEvent.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/workletRef.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +1 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +6 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ctx.d.ts +1 -1
- package/runtime/lib/snapshot/worklet/ctx.js +6 -1
- package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
- package/runtime/lib/snapshot/worklet/destroy.js.map +1 -1
- package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
- package/runtime/lib/snapshot/worklet/hmr.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js +6 -0
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/utils.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/animation/animation.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/animation/effect.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/lepusQuerySelector.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/events.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +0 -1
- package/runtime/lib/worklet-runtime/bindings/index.js +0 -1
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js +3 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
- package/runtime/lib/worklet-runtime/eomImpl.js.map +1 -1
- package/runtime/lib/worklet-runtime/eventPropagation.js.map +1 -1
- package/runtime/lib/worklet-runtime/global.js.map +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/index.js +6 -0
- package/runtime/lib/worklet-runtime/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +2 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/listeners.js +2 -2
- package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.js +3 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
- package/runtime/lib/worklet-runtime/runOnMainThread.js +4 -3
- package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/mainThreadFlushLoopGuard.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/version.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/src/core/background-function/exec-map.ts +9 -0
- package/runtime/src/core/background-function/run-on-background.ts +14 -16
- package/runtime/src/core/card-lifetime.ts +18 -0
- package/runtime/src/core/entry-reload.ts +63 -0
- package/runtime/src/core/lynx/lazy-bundle.ts +4 -1
- package/runtime/src/core/main-thread-object.ts +1 -8
- package/runtime/src/core/main-thread-ref-id.ts +5 -4
- package/runtime/src/core/reload-scoped-event.ts +35 -0
- package/runtime/src/core/reload-version.ts +5 -3
- package/runtime/src/core/runtime-destroy.ts +11 -0
- package/runtime/src/core/thread-function-call/main-thread.ts +4 -4
- package/runtime/src/core/thread-function-call/return-value.ts +6 -5
- package/runtime/src/element-template/background/commit-hook.ts +20 -17
- package/runtime/src/element-template/background/hydration-listener.ts +2 -6
- package/runtime/src/element-template/internal.ts +0 -1
- package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
- package/runtime/src/element-template/native/index.ts +2 -0
- package/runtime/src/element-template/native/mts-destroy.ts +3 -0
- package/runtime/src/element-template/native/patch-listener.ts +0 -5
- package/runtime/src/element-template/native/reload-background.ts +13 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +30 -2
- package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
- package/runtime/src/element-template/protocol/types.ts +0 -2
- package/runtime/src/internal.ts +0 -1
- package/runtime/src/shared/index-map.ts +3 -2
- package/runtime/src/snapshot/lifecycle/destroy.ts +7 -0
- package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +26 -19
- package/runtime/src/snapshot/lifecycle/reload.ts +47 -11
- package/runtime/src/snapshot/list/list.ts +9 -2
- package/runtime/src/snapshot/lynx/calledByNative.ts +3 -4
- package/runtime/src/snapshot/snapshot/list.ts +5 -1
- package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +19 -12
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +10 -1
- package/runtime/src/snapshot/worklet/ctx.ts +10 -1
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +6 -0
- package/runtime/src/worklet-runtime/README.md +13 -0
- package/runtime/src/worklet-runtime/bindings/index.ts +0 -1
- package/runtime/src/worklet-runtime/delayRunOnBackground.ts +3 -1
- package/runtime/src/worklet-runtime/index.ts +7 -0
- package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +2 -1
- package/runtime/src/worklet-runtime/listeners.ts +4 -7
- package/runtime/src/worklet-runtime/mainThreadObject.ts +2 -1
- package/runtime/src/worklet-runtime/runOnMainThread.ts +4 -3
- package/runtime/tsconfig.json +2 -0
- package/runtime/types/types.d.ts +3 -1
- package/runtime/vitest.config.ts +4 -0
- package/testing-library/.turbo/turbo-build.log +12 -12
- package/testing-library/dist/env/index.js +3 -15
- package/testing-library/dist/plugins/index.js +10 -0
- package/testing-library/dist/rstest-config.js +15 -0
- package/testing-library/dist/setupFiles/common/worklet-runtime-init.js +11 -0
- package/testing-library/rstest.config.ts +3 -0
- package/testing-library/src/__tests__/rstest-config.test.js +34 -1
- package/testing-library/src/__tests__/worklet.test.jsx +51 -37
- package/testing-library/src/plugins/vitest.ts +5 -1
- package/testing-library/src/rstest-config.ts +17 -1
- package/testing-library/src/setupFiles/common/worklet-runtime-init.js +22 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +345 -150
- package/transform/__test__/defines.spec.js +187 -12
- package/transform/__test__/fixture.spec.js +166 -48
- package/transform/__test__/object-methods.spec.js +1 -3
- package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +26 -10
- package/transform/crates/swc_plugin_worklet/lib.rs +138 -153
- package/transform/crates/swc_plugin_worklet/napi.rs +10 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +4 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +4 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_lepus.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +4 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_globals.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_type_annotations.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_destructure_from_closure.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_catch_clause_params.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_idents_inside_of_ctx.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_recursively.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +6 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_arrow_function.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_function_expr.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +4 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_alias.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general_mixed.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets_in_func.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_lepus.js +2 -4
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +27 -1
- package/transform/src/lib.rs +354 -23
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +53 -52
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +63 -293
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +0 -8
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +0 -23
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +0 -1
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +0 -25
- package/runtime/worklet-runtime/dev.js +0 -775
- package/runtime/worklet-runtime/main.js +0 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_inner_ident.js +0 -13
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_outer_ident.js +0 -13
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
|
|
5
5
|
import path from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
installElementTemplateRefInitValueListener,
|
|
8
|
+
resetElementTemplateRefInitValueListener,
|
|
9
|
+
} from '../../../../../src/element-template/main-thread-ref-init-value.js';
|
|
6
10
|
import { fileURLToPath } from 'node:url';
|
|
7
11
|
|
|
8
12
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
@@ -100,15 +104,11 @@ describe('Compiled runOnMainThread background fixtures', () => {
|
|
|
100
104
|
installElementTemplateCommitHook();
|
|
101
105
|
installElementTemplateHydrationListener();
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
vi.fn().mockImplementation(() => {
|
|
106
|
-
initWorklet();
|
|
107
|
-
return true;
|
|
108
|
-
}),
|
|
109
|
-
);
|
|
107
|
+
initWorklet();
|
|
108
|
+
vi.stubGlobal('__LoadLepusChunk', vi.fn());
|
|
110
109
|
|
|
111
110
|
envManager.switchToMainThread();
|
|
111
|
+
installElementTemplateRefInitValueListener();
|
|
112
112
|
installElementTemplatePatchListener();
|
|
113
113
|
lynx.getJSContext().addEventListener(ElementTemplateLifecycleConstant.update, onUpdate);
|
|
114
114
|
envManager.switchToBackground();
|
|
@@ -118,6 +118,7 @@ describe('Compiled runOnMainThread background fixtures', () => {
|
|
|
118
118
|
envManager.switchToMainThread();
|
|
119
119
|
lynx.getJSContext().removeEventListener(ElementTemplateLifecycleConstant.update, onUpdate);
|
|
120
120
|
resetElementTemplatePatchListener();
|
|
121
|
+
resetElementTemplateRefInitValueListener();
|
|
121
122
|
envManager.switchToBackground();
|
|
122
123
|
resetElementTemplateHydrationListener();
|
|
123
124
|
resetElementTemplateCommitState();
|
|
@@ -142,7 +143,7 @@ describe('Compiled runOnMainThread background fixtures', () => {
|
|
|
142
143
|
}> {
|
|
143
144
|
return loadCompiledFixturePair<CompiledRunOnMainThreadModule>(
|
|
144
145
|
FIXTURE,
|
|
145
|
-
{ enableWorkletTransform: true },
|
|
146
|
+
{ enableWorkletTransform: true, envManager },
|
|
146
147
|
);
|
|
147
148
|
}
|
|
148
149
|
|
|
@@ -182,9 +183,12 @@ describe('Compiled runOnMainThread background fixtures', () => {
|
|
|
182
183
|
expect(backgroundArtifact.code).not.toContain('__globalSnapshotPatch');
|
|
183
184
|
expect(backgroundArtifact.code).not.toContain('PatchList');
|
|
184
185
|
expect(backgroundArtifact.code).not.toContain('isRendering');
|
|
185
|
-
expect(mainArtifact.code).toContain(
|
|
186
|
+
expect(mainArtifact.code).toContain(
|
|
187
|
+
'import { registerWorklet as __registerWorklet } from "@lynx-js/react/worklet-runtime/init"',
|
|
188
|
+
);
|
|
189
|
+
expect(mainArtifact.code).not.toContain('loadWorkletRuntime');
|
|
186
190
|
expect(mainArtifact.code).toContain('element-template-formatter');
|
|
187
|
-
expect(mainArtifact.code).toContain('
|
|
191
|
+
expect(mainArtifact.code).toContain('__registerWorklet("main-thread"');
|
|
188
192
|
expect(mainArtifact.code).not.toContain('snapshot/');
|
|
189
193
|
});
|
|
190
194
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { createElement, render } from 'preact';
|
|
6
|
+
import { Component } from 'preact/compat';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
installElementTemplateCommitHook,
|
|
10
|
+
markElementTemplateHydrated,
|
|
11
|
+
uninstallElementTemplateCommitHookForTesting,
|
|
12
|
+
} from '../../../../src/element-template/background/commit-hook.js';
|
|
13
|
+
import { callDestroyLifetimeFun } from '../../../../src/element-template/native/callDestroyLifetimeFun.js';
|
|
14
|
+
import { reloadBackground } from '../../../../src/element-template/native/reload-background.js';
|
|
15
|
+
import { __root } from '../../../../src/element-template/runtime/page/root-instance.js';
|
|
16
|
+
import { ElementTemplateEnvManager } from '../../test-utils/debug/envManager.js';
|
|
17
|
+
|
|
18
|
+
describe('ElementTemplate entry reload', () => {
|
|
19
|
+
const env = new ElementTemplateEnvManager();
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
env.resetEnv('background');
|
|
23
|
+
vi.stubGlobal('__EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__', true);
|
|
24
|
+
lynx[Symbol.for('__LYNX_ENTRY_SUPPORTS_RE_EVAL__')] = true;
|
|
25
|
+
installElementTemplateCommitHook();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
uninstallElementTemplateCommitHookForTesting();
|
|
30
|
+
delete lynx[Symbol.for('__LYNX_ENTRY_SUPPORTS_RE_EVAL__')];
|
|
31
|
+
vi.restoreAllMocks();
|
|
32
|
+
vi.unstubAllGlobals();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('runs old component cleanup without sending removals to the new native tree', () => {
|
|
36
|
+
const cleanup = vi.fn();
|
|
37
|
+
class Probe extends Component {
|
|
38
|
+
componentWillUnmount() {
|
|
39
|
+
cleanup();
|
|
40
|
+
}
|
|
41
|
+
render() {
|
|
42
|
+
return createElement('view', null, 'old page');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
__root.__jsx = createElement(Probe);
|
|
46
|
+
render(__root.__jsx, __root as never);
|
|
47
|
+
markElementTemplateHydrated();
|
|
48
|
+
const dispatch = vi.spyOn(lynx.getCoreContext(), 'dispatchEvent');
|
|
49
|
+
dispatch.mockClear();
|
|
50
|
+
const oldRoot = __root;
|
|
51
|
+
lynx.__initData = { retained: 'initial', count: 1 };
|
|
52
|
+
const reloadCard = vi.fn(() => {
|
|
53
|
+
expect(cleanup).toHaveBeenCalledOnce();
|
|
54
|
+
expect(oldRoot.__jsx).toBeUndefined();
|
|
55
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
56
|
+
return true;
|
|
57
|
+
});
|
|
58
|
+
vi.spyOn(lynx, 'getApp').mockReturnValue({ callDestroyLifetimeFun, reloadCard } as never);
|
|
59
|
+
const options = { processorName: 'reload' };
|
|
60
|
+
|
|
61
|
+
reloadBackground({ count: 2 }, options);
|
|
62
|
+
|
|
63
|
+
expect(reloadCard).toHaveBeenCalledWith({ retained: 'initial', count: 2 }, options);
|
|
64
|
+
// An already queued old globalProps rerender cannot remount its page.
|
|
65
|
+
render(oldRoot.__jsx, oldRoot as never);
|
|
66
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
67
|
+
expect(cleanup).toHaveBeenCalledOnce();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
installElementTemplateRefInitValueListener,
|
|
3
|
+
resetElementTemplateRefInitValueListener,
|
|
4
|
+
} from '../../../../src/element-template/main-thread-ref-init-value.js';
|
|
1
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
6
|
|
|
3
7
|
import { WorkletEvents } from '@lynx-js/react/worklet-runtime/bindings';
|
|
@@ -262,8 +266,12 @@ describe('ElementTemplate hydration listener', () => {
|
|
|
262
266
|
isHydration: true,
|
|
263
267
|
reloadVersion: getReloadVersion(),
|
|
264
268
|
delayedRunOnMainThreadData: undefined,
|
|
265
|
-
mainThreadRefInitValuePatch: [[1, 'hydrate-init']],
|
|
266
269
|
});
|
|
270
|
+
expect(dispatchSpy.mock.calls.map(([event]) => event.type)).toEqual([
|
|
271
|
+
ElementTemplateLifecycleConstant.updateMTRefInitValue,
|
|
272
|
+
ElementTemplateLifecycleConstant.update,
|
|
273
|
+
]);
|
|
274
|
+
expect(dispatchSpy.mock.calls[0]![0].data).toBe(JSON.stringify([[1, 'hydrate-init']]));
|
|
267
275
|
expect(takeMainThreadRefInitValuePatch()).toEqual([]);
|
|
268
276
|
});
|
|
269
277
|
|
|
@@ -287,6 +295,7 @@ describe('ElementTemplate hydration listener', () => {
|
|
|
287
295
|
new MainThreadRef('reload-init');
|
|
288
296
|
|
|
289
297
|
envManager.switchToMainThread();
|
|
298
|
+
installElementTemplateRefInitValueListener();
|
|
290
299
|
installElementTemplatePatchListener();
|
|
291
300
|
dispatchHydrate([createSerializedTemplate(after.instanceId, '_et_test')]);
|
|
292
301
|
|
|
@@ -302,6 +311,7 @@ describe('ElementTemplate hydration listener', () => {
|
|
|
302
311
|
} finally {
|
|
303
312
|
envManager.switchToMainThread();
|
|
304
313
|
resetElementTemplatePatchListener();
|
|
314
|
+
resetElementTemplateRefInitValueListener();
|
|
305
315
|
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
306
316
|
envManager.switchToBackground();
|
|
307
317
|
}
|
|
@@ -603,7 +613,7 @@ describe('ElementTemplate hydration listener', () => {
|
|
|
603
613
|
}
|
|
604
614
|
});
|
|
605
615
|
|
|
606
|
-
it('resets commit state when
|
|
616
|
+
it.each(['update', 'ref', 'circular-ref', 'dispatch'])('resets hydrate commit state when %s fails', (failure) => {
|
|
607
617
|
SystemInfo.lynxSdkVersion = '4.0';
|
|
608
618
|
const serializeError = new Error('hydrate update serialization failed');
|
|
609
619
|
const oldReportError = lynx.reportError;
|
|
@@ -623,6 +633,12 @@ describe('ElementTemplate hydration listener', () => {
|
|
|
623
633
|
envManager.switchToBackground();
|
|
624
634
|
installElementTemplateHydrationListener();
|
|
625
635
|
const removeEventListener = vi.spyOn(lynx.getCoreContext(), 'removeEventListener');
|
|
636
|
+
const dispatch = vi.spyOn(lynx.getCoreContext(), 'dispatchEvent');
|
|
637
|
+
if (failure === 'dispatch') {
|
|
638
|
+
dispatch.mockImplementationOnce(() => {
|
|
639
|
+
throw serializeError;
|
|
640
|
+
});
|
|
641
|
+
}
|
|
626
642
|
|
|
627
643
|
const backgroundRoot = __root as BackgroundElementTemplateInstance;
|
|
628
644
|
const throwingValue = {
|
|
@@ -630,11 +646,19 @@ describe('ElementTemplate hydration listener', () => {
|
|
|
630
646
|
throw serializeError;
|
|
631
647
|
},
|
|
632
648
|
} as unknown as SerializableValue;
|
|
633
|
-
const after = new BackgroundElementTemplateInstance('_et_serialize_failure', [
|
|
649
|
+
const after = new BackgroundElementTemplateInstance('_et_serialize_failure', [
|
|
650
|
+
failure === 'update' ? throwingValue : 'after',
|
|
651
|
+
eventHandler,
|
|
652
|
+
ref,
|
|
653
|
+
]);
|
|
634
654
|
backgroundRoot.appendChild(after);
|
|
635
655
|
publishEvent('-1:1:', { type: 'tap' });
|
|
636
656
|
new ElementTemplateRefProxy(after.instanceId, 2).setNativeProps({ opacity: 1 }).exec();
|
|
637
|
-
|
|
657
|
+
const circularValue: { self?: unknown } = {};
|
|
658
|
+
circularValue.self = circularValue;
|
|
659
|
+
new MainThreadRef(
|
|
660
|
+
failure === 'ref' ? throwingValue : failure === 'circular-ref' ? circularValue : 'failed-serialize-init',
|
|
661
|
+
);
|
|
638
662
|
void runOnMainThread({ _wkltId: 'failed-serialize-main-thread-function' } as unknown as () => void)();
|
|
639
663
|
|
|
640
664
|
envManager.switchToMainThread();
|
|
@@ -646,7 +670,9 @@ describe('ElementTemplate hydration listener', () => {
|
|
|
646
670
|
]);
|
|
647
671
|
|
|
648
672
|
expect(() => envManager.switchToBackground()).not.toThrow();
|
|
649
|
-
expect(reportError).
|
|
673
|
+
expect(reportError).toHaveBeenCalledExactlyOnceWith(
|
|
674
|
+
failure === 'circular-ref' ? expect.any(TypeError) : serializeError,
|
|
675
|
+
);
|
|
650
676
|
expect(globalCommitContext.ops).toEqual([]);
|
|
651
677
|
expect([...globalCommitContext.nonPayload.removedSubtreesAwaitingTeardown]).toEqual([]);
|
|
652
678
|
expect(takeMainThreadRefInitValuePatch()).toEqual([]);
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
|
|
5
|
+
import {
|
|
6
|
+
installElementTemplateRefInitValueListener,
|
|
7
|
+
resetElementTemplateRefInitValueListener,
|
|
8
|
+
} from '../../../../src/element-template/main-thread-ref-init-value.js';
|
|
5
9
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
10
|
|
|
7
11
|
import { getReloadVersion, increaseReloadVersion } from '../../../../src/core/reload-version.js';
|
|
@@ -1439,7 +1443,7 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1439
1443
|
}
|
|
1440
1444
|
});
|
|
1441
1445
|
|
|
1442
|
-
it('applies
|
|
1446
|
+
it('applies independent ref initialization before delayed main-thread tasks', () => {
|
|
1443
1447
|
const callOrder: string[] = [];
|
|
1444
1448
|
const updateWorkletRefInitValueChanges = vi.fn(() => {
|
|
1445
1449
|
callOrder.push('init-patch');
|
|
@@ -1461,12 +1465,17 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1461
1465
|
|
|
1462
1466
|
try {
|
|
1463
1467
|
envManager.switchToMainThread();
|
|
1468
|
+
installElementTemplateRefInitValueListener();
|
|
1464
1469
|
installElementTemplatePatchListener();
|
|
1465
1470
|
mockFlushElementTree.mockImplementationOnce(() => {
|
|
1466
1471
|
callOrder.push('flushElementTree');
|
|
1467
1472
|
});
|
|
1468
1473
|
|
|
1469
1474
|
envManager.switchToBackground();
|
|
1475
|
+
lynx.getCoreContext().dispatchEvent({
|
|
1476
|
+
type: ElementTemplateLifecycleConstant.updateMTRefInitValue,
|
|
1477
|
+
data: JSON.stringify([[1, 'same-payload-init']]),
|
|
1478
|
+
});
|
|
1470
1479
|
dispatchElementTemplateUpdate({
|
|
1471
1480
|
ops: [],
|
|
1472
1481
|
flushOptions: {},
|
|
@@ -1477,7 +1486,6 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1477
1486
|
resolveId: 10,
|
|
1478
1487
|
},
|
|
1479
1488
|
],
|
|
1480
|
-
mainThreadRefInitValuePatch: [[1, 'same-payload-init']],
|
|
1481
1489
|
});
|
|
1482
1490
|
envManager.switchToMainThread();
|
|
1483
1491
|
|
|
@@ -1489,6 +1497,7 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1489
1497
|
'flushElementTree',
|
|
1490
1498
|
]);
|
|
1491
1499
|
} finally {
|
|
1500
|
+
resetElementTemplateRefInitValueListener();
|
|
1492
1501
|
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
1493
1502
|
}
|
|
1494
1503
|
});
|
|
@@ -1512,10 +1521,15 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1512
1521
|
try {
|
|
1513
1522
|
increaseReloadVersion();
|
|
1514
1523
|
envManager.switchToMainThread();
|
|
1524
|
+
installElementTemplateRefInitValueListener();
|
|
1515
1525
|
installElementTemplatePatchListener();
|
|
1516
1526
|
mockFlushElementTree.mockClear();
|
|
1517
1527
|
|
|
1518
1528
|
envManager.switchToBackground();
|
|
1529
|
+
lynx.getCoreContext().dispatchEvent({
|
|
1530
|
+
type: ElementTemplateLifecycleConstant.updateMTRefInitValue,
|
|
1531
|
+
data: JSON.stringify([[1, 'stale-init']]),
|
|
1532
|
+
});
|
|
1519
1533
|
dispatchElementTemplateUpdate({
|
|
1520
1534
|
ops: [],
|
|
1521
1535
|
flushOptions: {},
|
|
@@ -1527,7 +1541,6 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1527
1541
|
resolveId: 10,
|
|
1528
1542
|
},
|
|
1529
1543
|
],
|
|
1530
|
-
mainThreadRefInitValuePatch: [[1, 'stale-init']],
|
|
1531
1544
|
});
|
|
1532
1545
|
envManager.switchToMainThread();
|
|
1533
1546
|
|
|
@@ -1535,6 +1548,7 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1535
1548
|
expect(runRunOnMainThreadTask).not.toHaveBeenCalled();
|
|
1536
1549
|
expect(mockFlushElementTree).not.toHaveBeenCalled();
|
|
1537
1550
|
} finally {
|
|
1551
|
+
resetElementTemplateRefInitValueListener();
|
|
1538
1552
|
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
1539
1553
|
}
|
|
1540
1554
|
});
|
|
@@ -22,6 +22,7 @@ import { applyElementTemplateUpdateCommands } from '../../../../src/element-temp
|
|
|
22
22
|
import { ElementTemplateUpdateOps } from '../../../../src/element-template/protocol/opcodes.js';
|
|
23
23
|
import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
|
|
24
24
|
import { resetElementTemplatePatchListener } from '../../../../src/element-template/native/patch-listener.js';
|
|
25
|
+
import { resetElementTemplateRefInitValueListener } from '../../../../src/element-template/main-thread-ref-init-value.js';
|
|
25
26
|
import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
|
|
26
27
|
import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
|
|
27
28
|
import type {
|
|
@@ -181,6 +182,7 @@ async function compileAndRender(
|
|
|
181
182
|
};
|
|
182
183
|
} finally {
|
|
183
184
|
resetElementTemplatePatchListener();
|
|
185
|
+
resetElementTemplateRefInitValueListener();
|
|
184
186
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
185
187
|
}
|
|
186
188
|
}
|
|
@@ -206,7 +208,7 @@ describe('render transform contract', () => {
|
|
|
206
208
|
resetTemplateId();
|
|
207
209
|
});
|
|
208
210
|
|
|
209
|
-
it('imports
|
|
211
|
+
it('imports the runtime init entry for direct main-thread events', async () => {
|
|
210
212
|
const result = await compileMainThreadElementTemplate(`
|
|
211
213
|
function handleTap() {
|
|
212
214
|
'main thread';
|
|
@@ -218,8 +220,11 @@ describe('render transform contract', () => {
|
|
|
218
220
|
`);
|
|
219
221
|
const code = result.code ?? '';
|
|
220
222
|
|
|
221
|
-
expect(code).toContain(
|
|
222
|
-
|
|
223
|
+
expect(code).toContain(
|
|
224
|
+
'import { registerWorklet as __registerWorklet } from "@lynx-js/react/worklet-runtime/init"',
|
|
225
|
+
);
|
|
226
|
+
expect(code).not.toContain('loadWorkletRuntime');
|
|
227
|
+
expect(code).toContain('__registerWorklet("main-thread"');
|
|
223
228
|
expect(code).toContain('adaptMTEventAttrSlot');
|
|
224
229
|
expect(code).not.toContain('adaptEventAttrSlot');
|
|
225
230
|
expect(code).not.toContain('registerWorkletOnBackground');
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import { WorkletEvents } from '@lynx-js/react/worklet-runtime/bindings';
|
|
7
|
+
import { WorkletEvents, registerWorklet } from '@lynx-js/react/worklet-runtime/bindings';
|
|
8
8
|
import { options } from 'preact';
|
|
9
9
|
import { createElement } from 'preact/compat';
|
|
10
10
|
import { useLayoutEffect, useState } from 'preact/hooks';
|
|
@@ -16,11 +16,22 @@ import {
|
|
|
16
16
|
} from '../../../../src/element-template/background/commit-hook.js';
|
|
17
17
|
import { destroyElementTemplateBackgroundRuntime } from '../../../../src/element-template/background/destroy.js';
|
|
18
18
|
import { clearMtsConfigCacheForTesting } from '../../../../src/core/mts-capability.js';
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
delayedRunOnMainThreadData,
|
|
21
|
+
takeDelayedRunOnMainThreadData,
|
|
22
|
+
} from '../../../../src/core/thread-function-call/main-thread.js';
|
|
20
23
|
import { resetFunctionCallReturnListener } from '../../../../src/core/thread-function-call/return-value.js';
|
|
24
|
+
import {
|
|
25
|
+
installElementTemplatePatchListener,
|
|
26
|
+
resetElementTemplatePatchListener,
|
|
27
|
+
} from '../../../../src/element-template/native/patch-listener.js';
|
|
28
|
+
import { reloadBackground } from '../../../../src/element-template/native/reload-background.js';
|
|
29
|
+
import { reloadMainThread } from '../../../../src/element-template/native/reload-main-thread.js';
|
|
21
30
|
import { resetElementTemplateBackgroundFunctionRuntime } from '../../../../src/element-template/runtime/template/main-thread-background-function.js';
|
|
22
31
|
import { ElementTemplateLifecycleConstant } from '../../../../src/element-template/protocol/lifecycle-constant.js';
|
|
23
32
|
import { parseElementTemplateUpdateEventPayload } from '../../../../src/element-template/protocol/update-event.js';
|
|
33
|
+
import { createElementTemplatePage, setupPage } from '../../../../src/element-template/runtime/page/page.js';
|
|
34
|
+
import { initWorklet } from '../../../../src/worklet-runtime/workletRuntime.js';
|
|
24
35
|
import { ElementTemplateEnvManager } from '../../test-utils/debug/envManager.js';
|
|
25
36
|
|
|
26
37
|
describe('ElementTemplate runOnMainThread', () => {
|
|
@@ -60,6 +71,7 @@ describe('ElementTemplate runOnMainThread', () => {
|
|
|
60
71
|
worklet,
|
|
61
72
|
params: ['hello'],
|
|
62
73
|
resolveId: 1,
|
|
74
|
+
reloadVersion: 0,
|
|
63
75
|
}),
|
|
64
76
|
});
|
|
65
77
|
|
|
@@ -208,6 +220,7 @@ describe('ElementTemplate runOnMainThread', () => {
|
|
|
208
220
|
worklet,
|
|
209
221
|
params: ['from-layout-effect'],
|
|
210
222
|
resolveId: 1,
|
|
223
|
+
reloadVersion: 0,
|
|
211
224
|
}),
|
|
212
225
|
});
|
|
213
226
|
expect(takeDelayedRunOnMainThreadData()).toEqual([]);
|
|
@@ -262,6 +275,80 @@ describe('ElementTemplate runOnMainThread', () => {
|
|
|
262
275
|
expect(removeEventListener).toHaveBeenCalledWith(WorkletEvents.FunctionCallRet, expect.any(Function));
|
|
263
276
|
});
|
|
264
277
|
|
|
278
|
+
it('drops pre-hydration and unmount calls before a reload reuses their return IDs', async () => {
|
|
279
|
+
const oldResult = vi.fn();
|
|
280
|
+
const cleanupResult = vi.fn();
|
|
281
|
+
const cleanup = vi.fn(() => {
|
|
282
|
+
void runOnMainThread({ _wkltId: 'unmount-call' } as unknown as () => string)().then(cleanupResult);
|
|
283
|
+
expect(delayedRunOnMainThreadData.map(data => data.resolveId)).toEqual([1, 2]);
|
|
284
|
+
});
|
|
285
|
+
function App() {
|
|
286
|
+
useLayoutEffect(() => cleanup, []);
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const oldCall = vi.fn(() => 'old-page');
|
|
291
|
+
const unmountCall = vi.fn(() => 'old-page');
|
|
292
|
+
const newCall = vi.fn(() => 'new-page');
|
|
293
|
+
const workletGlobals = {
|
|
294
|
+
lynxWorkletImpl: globalThis.lynxWorkletImpl as unknown,
|
|
295
|
+
runWorklet: globalThis.runWorklet as unknown,
|
|
296
|
+
registerWorklet: globalThis.registerWorklet as unknown,
|
|
297
|
+
registerWorkletInternal: globalThis.registerWorkletInternal as unknown,
|
|
298
|
+
};
|
|
299
|
+
const dispatch = vi.spyOn(lynx.getCoreContext(), 'dispatchEvent');
|
|
300
|
+
try {
|
|
301
|
+
envManager.switchToMainThread();
|
|
302
|
+
initWorklet();
|
|
303
|
+
registerWorklet('main-thread', 'old-call', oldCall);
|
|
304
|
+
registerWorklet('main-thread', 'unmount-call', unmountCall);
|
|
305
|
+
registerWorklet('main-thread', 'new-call', newCall);
|
|
306
|
+
setupPage(createElementTemplatePage());
|
|
307
|
+
root.render(null);
|
|
308
|
+
installElementTemplatePatchListener();
|
|
309
|
+
envManager.switchToBackground();
|
|
310
|
+
root.render(createElement(App));
|
|
311
|
+
void runOnMainThread({ _wkltId: 'old-call' } as unknown as () => string)().then(oldResult);
|
|
312
|
+
expect(delayedRunOnMainThreadData[0]?.resolveId).toBe(1);
|
|
313
|
+
|
|
314
|
+
reloadBackground({});
|
|
315
|
+
expect(cleanup).toHaveBeenCalledOnce();
|
|
316
|
+
expect(delayedRunOnMainThreadData).toEqual([]);
|
|
317
|
+
// The harness shares resolver state between threads. Finish MTS reload
|
|
318
|
+
// before registering the new BTS call, then deliver the real hydration.
|
|
319
|
+
envManager.switchToMainThread(() => reloadMainThread({}, { reloadTemplate: true }));
|
|
320
|
+
let result!: Promise<string>;
|
|
321
|
+
envManager.switchToBackground(() => {
|
|
322
|
+
result = runOnMainThread({ _wkltId: 'new-call' } as unknown as () => string)();
|
|
323
|
+
expect(delayedRunOnMainThreadData[0]?.resolveId).toBe(1);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
const update = dispatch.mock.calls.find(([event]) =>
|
|
327
|
+
String(event.type) === ElementTemplateLifecycleConstant.update
|
|
328
|
+
)?.[0];
|
|
329
|
+
expect(parseElementTemplateUpdateEventPayload(update?.data)).toMatchObject({
|
|
330
|
+
isHydration: true,
|
|
331
|
+
delayedRunOnMainThreadData: [{ worklet: { _wkltId: 'new-call' }, params: [], resolveId: 1 }],
|
|
332
|
+
});
|
|
333
|
+
envManager.switchToMainThread();
|
|
334
|
+
envManager.switchToBackground();
|
|
335
|
+
|
|
336
|
+
expect(newCall).toHaveBeenCalledExactlyOnceWith();
|
|
337
|
+
expect(oldCall).not.toHaveBeenCalled();
|
|
338
|
+
expect(unmountCall).not.toHaveBeenCalled();
|
|
339
|
+
await expect(result).resolves.toBe('new-page');
|
|
340
|
+
expect(oldResult).not.toHaveBeenCalled();
|
|
341
|
+
expect(cleanupResult).not.toHaveBeenCalled();
|
|
342
|
+
} finally {
|
|
343
|
+
// Do not enqueue another cleanup call while disposing the replacement tree.
|
|
344
|
+
cleanup.mockImplementation(() => {});
|
|
345
|
+
envManager.switchToBackground(() => destroyElementTemplateBackgroundRuntime());
|
|
346
|
+
envManager.switchToMainThread(() => resetElementTemplatePatchListener());
|
|
347
|
+
envManager.switchToBackground();
|
|
348
|
+
Object.assign(globalThis, workletGlobals);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
265
352
|
it('throws on the main thread', () => {
|
|
266
353
|
envManager.switchToMainThread();
|
|
267
354
|
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type CompiledFixtureTarget,
|
|
10
10
|
} from './compiledFixtureCompiler.js';
|
|
11
11
|
import { primeCompiledFixtureTemplates } from './compiledFixtureRegistry.js';
|
|
12
|
+
import type { ElementTemplateEnvManager } from './envManager.js';
|
|
12
13
|
|
|
13
14
|
export interface CompiledFixtureModuleExports {
|
|
14
15
|
App: (props?: Record<string, unknown>) => JSX.Element;
|
|
@@ -33,6 +34,7 @@ export async function loadCompiledFixtureModule<T extends object = CompiledFixtu
|
|
|
33
34
|
interface LoadCompiledFixturePairOptions {
|
|
34
35
|
backgroundTarget?: CompiledFixtureTarget;
|
|
35
36
|
enableWorkletTransform?: boolean;
|
|
37
|
+
envManager?: ElementTemplateEnvManager;
|
|
36
38
|
isDynamicComponent?: boolean;
|
|
37
39
|
mainTarget?: CompiledFixtureTarget;
|
|
38
40
|
registerMainTemplates?: boolean;
|
|
@@ -48,6 +50,7 @@ export async function loadCompiledFixturePair<T extends object = CompiledFixture
|
|
|
48
50
|
const {
|
|
49
51
|
backgroundTarget = 'JS',
|
|
50
52
|
enableWorkletTransform = false,
|
|
53
|
+
envManager,
|
|
51
54
|
isDynamicComponent = false,
|
|
52
55
|
mainTarget = 'LEPUS',
|
|
53
56
|
registerMainTemplates = true,
|
|
@@ -61,6 +64,7 @@ export async function loadCompiledFixturePair<T extends object = CompiledFixture
|
|
|
61
64
|
if (registerMainTemplates) {
|
|
62
65
|
primeCompiledFixtureTemplates(mainArtifact);
|
|
63
66
|
}
|
|
67
|
+
envManager?.switchToMainThread();
|
|
64
68
|
const mainModule = await loadCompiledFixtureModule<T>(mainArtifact);
|
|
65
69
|
|
|
66
70
|
const backgroundArtifact = await compileFixtureSource(sourcePath, {
|
|
@@ -68,6 +72,7 @@ export async function loadCompiledFixturePair<T extends object = CompiledFixture
|
|
|
68
72
|
isDynamicComponent,
|
|
69
73
|
target: backgroundTarget,
|
|
70
74
|
});
|
|
75
|
+
envManager?.switchToBackground();
|
|
71
76
|
const backgroundModule = await loadCompiledFixtureModule<T>(backgroundArtifact);
|
|
72
77
|
|
|
73
78
|
return { backgroundModule, mainModule };
|
|
@@ -29,6 +29,12 @@ export function injectGlobals() {
|
|
|
29
29
|
|
|
30
30
|
globalThis.requestAnimationFrame = setTimeout;
|
|
31
31
|
globalThis.cancelAnimationFrame = clearTimeout;
|
|
32
|
+
globalThis.lynx.setTimeout = globalThis.setTimeout;
|
|
33
|
+
globalThis.lynx.setInterval = globalThis.setInterval;
|
|
34
|
+
globalThis.lynx.clearTimeout = globalThis.clearTimeout;
|
|
35
|
+
globalThis.lynx.clearInterval = globalThis.clearInterval;
|
|
36
|
+
globalThis.lynx.requestAnimationFrame = globalThis.requestAnimationFrame;
|
|
37
|
+
globalThis.lynx.cancelAnimationFrame = globalThis.cancelAnimationFrame;
|
|
32
38
|
globalThis._ReportError = vi.fn();
|
|
33
39
|
|
|
34
40
|
console.alog = vi.fn();
|
|
@@ -69,6 +69,10 @@ const config: UserConfigExport = defineConfig({
|
|
|
69
69
|
dedupe: ['preact'],
|
|
70
70
|
alias: {
|
|
71
71
|
'@lynx-js/react/compat': path.resolve(__dirname, '../../compat/index.js'),
|
|
72
|
+
'@lynx-js/react/worklet-runtime/init': path.resolve(
|
|
73
|
+
__dirname,
|
|
74
|
+
'../../src/worklet-runtime/index.ts',
|
|
75
|
+
),
|
|
72
76
|
'@lynx-js/react/worklet-runtime/bindings': path.resolve(
|
|
73
77
|
__dirname,
|
|
74
78
|
'../../src/worklet-runtime/bindings/index.ts',
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
3
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
4
|
+
// LICENSE file in the root directory of this source tree.
|
|
5
|
+
*/
|
|
6
|
+
import { render } from 'preact';
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { registerDestroyTask } from '../../../src/core/runtime-destroy';
|
|
10
|
+
import { __root, setRoot } from '../../../src/root';
|
|
11
|
+
import { completeMainThreadReload } from '../../../src/snapshot/lifecycle/reload';
|
|
12
|
+
import { SnapshotInstance } from '../../../src/snapshot/snapshot/snapshot';
|
|
13
|
+
import { globalEnvManager } from '../utils/envManager';
|
|
14
|
+
import { elementTree } from '../utils/nativeMethod';
|
|
15
|
+
|
|
16
|
+
const supportsReEvalKey = Symbol.for('__LYNX_ENTRY_SUPPORTS_RE_EVAL__');
|
|
17
|
+
const reloaderKey = Symbol.for('__LYNX_MAIN_THREAD_ENTRY_RELOADER__');
|
|
18
|
+
const completerKey = Symbol.for('__LYNX_MAIN_THREAD_RELOAD_COMPLETER__');
|
|
19
|
+
|
|
20
|
+
function App({ label = 'app' }) {
|
|
21
|
+
return (
|
|
22
|
+
<view>
|
|
23
|
+
<text>{label}</text>
|
|
24
|
+
</view>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('re-evaluating the main-thread entry on reload', () => {
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
globalEnvManager.resetEnv();
|
|
31
|
+
vi.stubGlobal('__EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__', true);
|
|
32
|
+
globalEnvManager.switchToMainThread();
|
|
33
|
+
lynx[supportsReEvalKey] = true;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
delete lynx[supportsReEvalKey];
|
|
38
|
+
delete lynx[reloaderKey];
|
|
39
|
+
delete lynx[completerKey];
|
|
40
|
+
vi.restoreAllMocks();
|
|
41
|
+
vi.unstubAllGlobals();
|
|
42
|
+
globalEnvManager.resetEnv();
|
|
43
|
+
elementTree.clear();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('retires the entry, evaluates it again and lets it hydrate the existing tree', () => {
|
|
47
|
+
__root.__jsx = <App label='old' />;
|
|
48
|
+
renderPage({ kept: 'yes', count: 1 });
|
|
49
|
+
const page = __root.__element_root;
|
|
50
|
+
const events = [];
|
|
51
|
+
registerDestroyTask(() => events.push('retire'));
|
|
52
|
+
lynx[reloaderKey] = () => {
|
|
53
|
+
events.push('evaluate');
|
|
54
|
+
// What evaluating the entry does: reset init data, install its completer, render into a fresh root.
|
|
55
|
+
lynx.__initData = {};
|
|
56
|
+
lynx[completerKey] = completeMainThreadReload;
|
|
57
|
+
setRoot(new SnapshotInstance('root'));
|
|
58
|
+
__root.__jsx = <App label='new' />;
|
|
59
|
+
};
|
|
60
|
+
const createText = vi.spyOn(globalThis, '__CreateText');
|
|
61
|
+
|
|
62
|
+
updatePage({ count: 2 }, { reloadTemplate: true });
|
|
63
|
+
|
|
64
|
+
expect(events).toEqual(['retire', 'evaluate']);
|
|
65
|
+
expect(lynx.__initData).toEqual({ kept: 'yes', count: 2 });
|
|
66
|
+
expect(__root.__element_root).toBe(page);
|
|
67
|
+
expect(createText).not.toHaveBeenCalled();
|
|
68
|
+
expect(JSON.stringify(page)).toContain('new');
|
|
69
|
+
expect(JSON.stringify(page)).not.toContain('old');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('re-evaluating the background entry on reload', () => {
|
|
74
|
+
let reloadCard;
|
|
75
|
+
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
globalEnvManager.resetEnv();
|
|
78
|
+
vi.stubGlobal('__EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__', true);
|
|
79
|
+
globalEnvManager.switchToBackground();
|
|
80
|
+
lynx[supportsReEvalKey] = true;
|
|
81
|
+
reloadCard = vi.fn();
|
|
82
|
+
lynx.getApp().reloadCard = reloadCard;
|
|
83
|
+
lynx.__globalProps = {};
|
|
84
|
+
__root.__jsx = <App />;
|
|
85
|
+
render(<App />, __root);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
afterEach(() => {
|
|
89
|
+
delete lynx[supportsReEvalKey];
|
|
90
|
+
delete lynx.getApp().reloadCard;
|
|
91
|
+
vi.unstubAllGlobals();
|
|
92
|
+
globalEnvManager.resetEnv();
|
|
93
|
+
elementTree.clear();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('retires the entry, then asks the client to evaluate it with the merged data', () => {
|
|
97
|
+
lynx.__initData = { kept: 'yes', count: 1 };
|
|
98
|
+
const destroy = vi.spyOn(lynx.getApp(), 'callDestroyLifetimeFun');
|
|
99
|
+
|
|
100
|
+
lynx.getApp().onAppReload({ count: 2 }, { source: 'test' });
|
|
101
|
+
|
|
102
|
+
expect(reloadCard).toHaveBeenCalledWith({ kept: 'yes', count: 2 }, { source: 'test' });
|
|
103
|
+
expect(destroy.mock.invocationCallOrder[0]).toBeLessThan(reloadCard.mock.invocationCallOrder[0]);
|
|
104
|
+
expect(__root.childNodes).toEqual([]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('does not render the old tree again from a globalProps update queued before the reload', async () => {
|
|
108
|
+
lynx.getApp().updateGlobalProps({ theme: 'dark' });
|
|
109
|
+
lynx.getApp().onAppReload({});
|
|
110
|
+
await Promise.resolve();
|
|
111
|
+
|
|
112
|
+
expect(__root.childNodes).toEqual([]);
|
|
113
|
+
});
|
|
114
|
+
});
|