From 7cb38191bdae947faa348a49ec657a8b9c5e3707 Mon Sep 17 00:00:00 2001 From: Yradex <11014207+Yradex@users.noreply.github.com> Date: Wed, 9 Apr 2025 10:56:58 +0800 Subject: [PATCH] fix(react/runtime): disable MTS hmr --- .changeset/sad-parents-pay.md | 5 +++ .../runtime/__test__/snapshotPatch.test.jsx | 2 +- .../src/lifecycle/patch/snapshotPatchApply.ts | 20 +++++------ packages/react/runtime/src/worklet/hmr.ts | 34 +++++++++++-------- 4 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 .changeset/sad-parents-pay.md diff --git a/.changeset/sad-parents-pay.md b/.changeset/sad-parents-pay.md new file mode 100644 index 0000000000..0840ae2a9a --- /dev/null +++ b/.changeset/sad-parents-pay.md @@ -0,0 +1,5 @@ +--- +"@lynx-js/react": patch +--- + +Disable MTS HMR functionality temporarily to address stability issues. This is a temporary fix while we work on a more robust solution. diff --git a/packages/react/runtime/__test__/snapshotPatch.test.jsx b/packages/react/runtime/__test__/snapshotPatch.test.jsx index 207288008a..8c83208646 100644 --- a/packages/react/runtime/__test__/snapshotPatch.test.jsx +++ b/packages/react/runtime/__test__/snapshotPatch.test.jsx @@ -1194,7 +1194,7 @@ describe('DEV_ONLY_addSnapshot', () => { }); }); -describe('DEV_ONLY_RegisterWorklet', () => { +describe.skip('DEV_ONLY_RegisterWorklet', () => { beforeEach(() => { initGlobalSnapshotPatch(); }); diff --git a/packages/react/runtime/src/lifecycle/patch/snapshotPatchApply.ts b/packages/react/runtime/src/lifecycle/patch/snapshotPatchApply.ts index 8dee7468f0..3510f5468e 100644 --- a/packages/react/runtime/src/lifecycle/patch/snapshotPatchApply.ts +++ b/packages/react/runtime/src/lifecycle/patch/snapshotPatchApply.ts @@ -92,16 +92,16 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void { } break; } - case SnapshotOperation.DEV_ONLY_RegisterWorklet: { - // HMR-related - if (__DEV__) { - const hash: string = snapshotPatch[++i]; - const fnStr: string = snapshotPatch[++i]; - const fn = evaluate<(ctx: SnapshotInstance) => FiberElement[]>(fnStr); - registerWorklet('main-thread', hash, fn); - } - break; - } + // case SnapshotOperation.DEV_ONLY_RegisterWorklet: { + // // HMR-related + // if (__DEV__) { + // const hash: string = snapshotPatch[++i]; + // const fnStr: string = snapshotPatch[++i]; + // const fn = evaluate<(ctx: SnapshotInstance) => FiberElement[]>(fnStr); + // registerWorklet('main-thread', hash, fn); + // } + // break; + // } } } } diff --git a/packages/react/runtime/src/worklet/hmr.ts b/packages/react/runtime/src/worklet/hmr.ts index c5698c2988..46754bfd0d 100644 --- a/packages/react/runtime/src/worklet/hmr.ts +++ b/packages/react/runtime/src/worklet/hmr.ts @@ -1,26 +1,30 @@ // 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 { SnapshotOperation, __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js'; +// import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js'; -const workletHashSet: Set = /* @__PURE__ */ new Set(); +// const workletHashSet: Set = /* @__PURE__ */ new Set(); +/* v8 ignore start */ /** * @internal */ -function registerWorkletOnBackground(_type: string, hash: string, fn: Function) { - if (workletHashSet.has(hash)) { - return; - } - workletHashSet.add(hash); - if (__globalSnapshotPatch) { - __globalSnapshotPatch.push( - SnapshotOperation.DEV_ONLY_RegisterWorklet, - hash, - // We use `Function.prototype.toString` to serialize the function for Lepus. - fn.toString(), - ); - } +// disable hmr until bugs are fixed +// TODO: re-enable hmr or change a way to impl it; also need to fix the test case DEV_ONLY_RegisterWorklet +function registerWorkletOnBackground(_type: string, _hash: string, _fn: Function) { + // if (workletHashSet.has(hash)) { + // return; + // } + // workletHashSet.add(hash); + // if (__globalSnapshotPatch) { + // __globalSnapshotPatch.push( + // SnapshotOperation.DEV_ONLY_RegisterWorklet, + // hash, + // // We use `Function.prototype.toString` to serialize the function for Lepus. + // fn.toString(), + // ); + // } } +/* v8 ignore stop */ export { registerWorkletOnBackground };