diff --git a/.changeset/remove-invalid-mtf-warn.md b/.changeset/remove-invalid-mtf-warn.md new file mode 100644 index 0000000000..b24626ede9 --- /dev/null +++ b/.changeset/remove-invalid-mtf-warn.md @@ -0,0 +1,5 @@ +--- +"@lynx-js/react": patch +--- + +Stop warning when `runWorklet` receives an invalid or missing main-thread function object. Invalid worklet contexts are still ignored, but nullish handler values no longer produce noisy `MainThreadFunction: Invalid function object` console output. diff --git a/packages/react/runtime/__test__/worklet-runtime/workletRuntime.test.js b/packages/react/runtime/__test__/worklet-runtime/workletRuntime.test.js index 4fcaf5c531..3703f1c9c7 100644 --- a/packages/react/runtime/__test__/worklet-runtime/workletRuntime.test.js +++ b/packages/react/runtime/__test__/worklet-runtime/workletRuntime.test.js @@ -303,14 +303,14 @@ describe('Worklet', () => { it('should not throw when invalid worklet ctx', () => { initWorklet(); + consoleMock.mockClear(); + globalThis.runWorklet({}); - expect(consoleMock).lastCalledWith('MainThreadFunction: Invalid function object: {}'); globalThis.runWorklet(undefined); - expect(consoleMock).lastCalledWith('MainThreadFunction: Invalid function object: undefined'); globalThis.runWorklet(null); - expect(consoleMock).lastCalledWith('MainThreadFunction: Invalid function object: null'); globalThis.runWorklet(1); - expect(consoleMock).lastCalledWith('MainThreadFunction: Invalid function object: 1'); + + expect(consoleMock).not.toHaveBeenCalled(); }); it('should not throw when depth of argument exceeds limit', () => { diff --git a/packages/react/runtime/src/worklet-runtime/workletRuntime.ts b/packages/react/runtime/src/worklet-runtime/workletRuntime.ts index aef075afa6..54b30ac41b 100644 --- a/packages/react/runtime/src/worklet-runtime/workletRuntime.ts +++ b/packages/react/runtime/src/worklet-runtime/workletRuntime.ts @@ -55,7 +55,6 @@ function registerWorklet(_type: string, id: string, worklet: (...args: unknown[] */ function runWorklet(ctx: Worklet, params: ClosureValueType[], options?: RunWorkletOptions): unknown { if (!validateWorklet(ctx)) { - console.warn('MainThreadFunction: Invalid function object: ' + JSON.stringify(ctx)); return; }