Conversation
🦋 Changeset detectedLatest commit: 90a9cc3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughAdds a MainThreadValue framework for serializable main-thread-persistent values, a workletCapture helper, SWC transform integration to emit captures, MotionValue example and hook, and hydration/registration plumbing plus tests and exports to support custom main-thread value types. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
❌ 15 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/react/worklet-runtime/__test__/workletRef.test.js (1)
6-22: Clean up__LYNX_MTV_REGISTRY__after each test.Line 18 introduces a global registry; without cleanup it can leak into other suites sharing the same process.
🧹 Suggested cleanup
afterEach(() => { delete globalThis.lynxWorkletImpl; + delete globalThis.__LYNX_MTV_REGISTRY__; });Also applies to: 26-28
🤖 Fix all issues with AI agents
In @.changeset/better-pigs-run.md:
- Line 7: The fenced code block in the changeset uses a plain triple-backtick
with no language hint; update that fence to include a language tag (e.g., change
``` to ```ts) so the block is annotated (satisfies MD040). Locate the
triple-backtick fence in .changeset/better-pigs-run.md and add the appropriate
language identifier after the opening backticks.
In `@packages/react/runtime/src/worklet/ref/mainThreadValue.ts`:
- Around line 81-86: The _lifecycleObserver field in mainThreadValue.ts is only
set in the __JS__ branch and fails strict property initialization; update the
declaration of protected _lifecycleObserver to be optional or include undefined
(e.g., make it protected _lifecycleObserver?: unknown or protected
_lifecycleObserver: unknown | undefined) so the compiler knows it may be unset
on the main thread, leaving the existing assignment in the __JS__ branch (where
it's used) unchanged.
In `@packages/react/transform/crates/swc_plugin_worklet/gen_stmt.rs`:
- Around line 99-128: Clippy flags useless conversions in the object property
handling: avoid converting symbols/strings to &str and back or calling
to_string() unnecessarily. In the Prop::Shorthand and Prop::KeyValue arms (refer
to context_ident, val_obj, Prop::Shorthand, Prop::KeyValue, kv.key, kv.value),
replace patterns like id.sym.as_str().into(),
s.value.to_string_lossy().to_string(), and the intermediate key_str -> .into()
with direct clones of the underlying JsWord/Str (e.g., use id.sym.clone() and
s.value.clone() or push the appropriate cloned value directly) and push
kv.value.clone() without extra deref/conversion; remove the redundant
conversions so the Str.value fields and args use the correct cloned types
directly.
🧹 Nitpick comments (7)
packages/react/worklet-runtime/src/bindings/types.ts (1)
19-24: LGTM! Well-designed interface for main-thread persistent values.The interface correctly includes the
__MT_PERSIST__: truediscriminant that aligns with the runtime check inworkletCapture(packages/react/runtime/src/worklet/capture.ts).Minor consistency nit:
WorkletRefImplusesWorkletRefIdtype alias for_wvid(line 12), while this interface uses rawnumber. Consider usingWorkletRefIdfor consistency:export interface MainThreadValueImpl<T> { __MT_PERSIST__: true; - _wvid: number; + _wvid: WorkletRefId; _initValue: T; _type: string; }packages/react/runtime/src/worklet/capture.ts (1)
15-16: Guard against odd key/value args inworkletCapture.If
argslength is odd,args[i + 1]becomesundefined, which can silently skew captured data. Consider guarding the loop.♻️ Suggested guard
- for (let i = 0; i < args.length; i += 2) { - result[args[i]] = args[i + 1]; - } + for (let i = 0; i + 1 < args.length; i += 2) { + result[args[i]] = args[i + 1]; + }examples/react/src/MotionValue.ts (1)
13-56: De-duplicate the MotionValue type string to avoid drift.The type identifier is repeated in the constructor default and registration. Hoist it to a single constant (e.g., static
type) to keep future edits in sync.♻️ Suggested refactor
-export class MotionValue<T> extends MainThreadValue<T> { - private _subscribers: Set<(value: T) => void> = new Set(); - - constructor(initValue: T, type = '@example/motion-value') { - super(initValue, type); - } +export class MotionValue<T> extends MainThreadValue<T> { + static readonly type = '@example/motion-value'; + private _subscribers: Set<(value: T) => void> = new Set(); + + constructor(initValue: T, type = MotionValue.type) { + super(initValue, type); + } @@ -MainThreadValue.register(MotionValue, '@example/motion-value'); +MainThreadValue.register(MotionValue, MotionValue.type);packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_js.js (1)
1-2: UnusedworkletCaptureimport in generated code.The
workletCapturefunction is imported and aliased but not used in this particular snapshot. Since this is an auto-generated snapshot file, if this unused import is unintentional, the fix should be applied in the SWC transform logic (e.g., conditionally emitting the import only whenworkletCaptureis actually needed).If the transform intentionally adds the import unconditionally for simplicity, this is acceptable but may result in slightly larger bundle sizes when tree-shaking is not available.
packages/react/worklet-runtime/__test__/api/element.test.js (1)
17-22: Consider cleaning upglobalThis.lynxinafterEach.The
globalThis.lynxmock is set up inbeforeEachbut not cleaned up inafterEach. For test isolation consistency, consider addingdelete globalThis.lynx;in theafterEachblock alongside the existing cleanup ofglobalThis.lynxWorkletImpl.Suggested addition to afterEach
afterEach(() => { delete globalThis.lynxWorkletImpl; + delete globalThis.lynx; vi.useRealTimers(); vi.clearAllMocks(); setShouldFlush(true); });packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_js.js (1)
1-2: Same pattern as other snapshots -workletCaptureimported but unused.This is consistent with other auto-generated snapshots in this PR. The import is present but not utilized in the output. As noted for the other snapshot file, if this is unintentional, the transform logic should be adjusted.
packages/react/transform/crates/swc_plugin_worklet/gen_stmt.rs (1)
260-266: Remove duplicate comment block.The comment
/* registerWorklet($type, $hash, $function); */appears twice consecutively. This looks unintentional.♻️ Proposed fix
- /* - * registerWorklet($type, $hash, $function); - */ - /* * registerWorklet($type, $hash, $function); */ fn gen_register_worklet_stmt(
|
|
||
| Add support for `MainThreadValue` to enable Main Thread Persistent Data other than `MainThreadRef`, to make library developers able to create their own main thread values. | ||
|
|
||
| ``` |
There was a problem hiding this comment.
Add a language hint to the fenced code block.
This satisfies MD040 and keeps markdown linting clean.
🛠️ Minimal fix
-```
+```tsAs per coding guidelines, ...
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ``` |
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)
7-7: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
In @.changeset/better-pigs-run.md at line 7, The fenced code block in the
changeset uses a plain triple-backtick with no language hint; update that fence
to include a language tag (e.g., change ``` to ```ts) so the block is annotated
(satisfies MD040). Locate the triple-backtick fence in
.changeset/better-pigs-run.md and add the appropriate language identifier after
the opening backticks.
| /** | ||
| * @internal | ||
| * Observer for garbage collection lifecycle. | ||
| */ | ||
| protected _lifecycleObserver: unknown; | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's look at the file structure and find the target file
fd mainThreadValue.tsRepository: lynx-family/lynx-stack
Length of output: 123
🏁 Script executed:
# Read the file to see the property definition and its usage
cat -n packages/react/runtime/src/worklet/ref/mainThreadValue.ts | head -120Repository: lynx-family/lynx-stack
Length of output: 4297
🏁 Script executed:
# Check the tsconfig.json for strict mode settings
cat tsconfig.jsonRepository: lynx-family/lynx-stack
Length of output: 12684
🏁 Script executed:
# Search for all assignments to _lifecycleObserver in the file
rg "_lifecycleObserver" packages/react/runtime/src/worklet/ref/mainThreadValue.ts -A 2Repository: lynx-family/lynx-stack
Length of output: 309
Make _lifecycleObserver optional to satisfy strict property initialization.
The property is only assigned in the __JS__ branch (background thread), leaving it uninitialized on the main thread. With strictPropertyInitialization enabled (via strict: true in tsconfig.json), this fails type checking. Make it optional:
Suggested fix
- protected _lifecycleObserver: unknown;
+ protected _lifecycleObserver?: unknown;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** | |
| * @internal | |
| * Observer for garbage collection lifecycle. | |
| */ | |
| protected _lifecycleObserver: unknown; | |
| /** | |
| * `@internal` | |
| * Observer for garbage collection lifecycle. | |
| */ | |
| protected _lifecycleObserver?: unknown; |
🤖 Prompt for AI Agents
In `@packages/react/runtime/src/worklet/ref/mainThreadValue.ts` around lines 81 -
86, The _lifecycleObserver field in mainThreadValue.ts is only set in the __JS__
branch and fails strict property initialization; update the declaration of
protected _lifecycleObserver to be optional or include undefined (e.g., make it
protected _lifecycleObserver?: unknown or protected _lifecycleObserver: unknown
| undefined) so the compiler knows it may be unset on the main thread, leaving
the existing assignment in the __JS__ branch (where it's used) unchanged.
574e746 to
c6a25f6
Compare
c6a25f6 to
90a9cc3
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@examples/react/src/App.tsx`:
- Around line 22-52: The cleanup race occurs because unsubscribeHandle may be
undefined when the component unmounts; change the runOnMainThread call to an
async IIFE that awaits the result and uses a local "cancelled" flag (or keeps
the pending Promise) so cleanup can safely no-op if the subscription setup
hasn't completed: in useEffect, replace the .then/.catch pattern with an async
function that calls runOnMainThread(), assigns the returned unsubscribe function
to a local variable (e.g., unsubscribeHandle) only if not cancelled, and on
return set cancelled=true and, if unsubscribeHandle is set, call it; reference
the existing useEffect, runOnMainThread, unsubscribeHandle, opacity.subscribe,
tapCount.subscribe, and the unsubscribe/unsubscribeTapCount variables to locate
where to implement this guard and explicit error handling.
In `@packages/react/runtime/src/worklet/ref/workletRef.ts`:
- Around line 25-34: The try/catch in the current getter is redundant because
catch calls super.getValueOnMainThread() which will rethrow the same error;
either remove the try/catch and directly return this.getValueOnMainThread(), or
if a fallback is desired change the catch to return the stored fallback
(this._initValue) instead of calling super.getValueOnMainThread(); update the
current getter accordingly and keep references to getValueOnMainThread,
super.getValueOnMainThread, current, and _initValue to locate the change.
🧹 Nitpick comments (3)
packages/react/transform/crates/swc_plugin_worklet/gen_stmt.rs (1)
260-266: Remove duplicate comment block.Lines 260-262 duplicate the comment block at lines 264-266. This appears to be an accidental leftover.
🔧 Proposed fix
} - /* - * registerWorklet($type, $hash, $function); - */ - /* * registerWorklet($type, $hash, $function); */ fn gen_register_worklet_stmt(packages/react/worklet-runtime/__test__/workletRuntime.test.js (1)
133-136: Consider adding_typetoarg2for consistency.The
arg2worklet ref at lines 133-135 lacks the_typefield, unlike other refs in this file. If this is intentional to test backward compatibility (fallback behavior when_typeis missing), consider adding a comment to clarify.packages/react/worklet-runtime/src/workletRef.ts (1)
21-29: Remove duplicate comment block.The comment "Registry for custom MainThreadValue types..." appears twice (lines 21-24 and 25-28).
🔧 Proposed fix
/** * Registry for custom MainThreadValue types. * Maps type string (e.g., 'main-thread', 'motion-value') to constructor. */ -/** - * Registry for custom MainThreadValue types. - * Maps type string (e.g., 'main-thread', 'motion-value') to constructor. - */ const typeRegistry: Record<string, new(initValue: unknown, type: string) => unknown> = {};
| useEffect(() => { | ||
| console.info('Hello, ReactLynx'); | ||
|
|
||
| let unsubscribeHandle: (() => void) | undefined; | ||
|
|
||
| runOnMainThread(() => { | ||
| 'main thread'; | ||
|
|
||
| // Demo: Subscribe to value changes (main thread only) | ||
| const unsubscribe = opacity.subscribe((newValue) => { | ||
| console.info('Opacity changed to:', newValue); | ||
| }); | ||
|
|
||
| // Demo: Subscribe to value changes (main thread only) | ||
| const unsubscribeTapCount = tapCount.subscribe((newValue) => { | ||
| console.info('TapCount changed to:', newValue); | ||
| }); | ||
|
|
||
| return () => { | ||
| unsubscribe(); | ||
| unsubscribeTapCount(); | ||
| }; | ||
| })().then((res) => { | ||
| unsubscribeHandle = res as () => void; | ||
| }).catch(_err => { | ||
| // omitted | ||
| }); | ||
|
|
||
| return () => { | ||
| void runOnMainThread(unsubscribeHandle!)(); | ||
| }; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's check the actual code in App.tsx at the specified lines
cat -n examples/react/src/App.tsx | sed -n '1,70p'Repository: lynx-family/lynx-stack
Length of output: 2332
🏁 Script executed:
# Find where runOnMainThread is defined
fd -t f '*.ts' -o '*.tsx' -o '*.js' | xargs rg -l 'runOnMainThread' | head -20Repository: lynx-family/lynx-stack
Length of output: 1352
🏁 Script executed:
# Get the definition of runOnMainThread
rg -A 10 'export.*runOnMainThread|function runOnMainThread' --type ts --type tsxRepository: lynx-family/lynx-stack
Length of output: 93
🏁 Script executed:
# Check the type definitions or interface for runOnMainThread
rg -B 2 -A 5 'runOnMainThread' examples/react/src/App.tsxRepository: lynx-family/lynx-stack
Length of output: 592
🏁 Script executed:
# Find the runOnMainThread implementation
cat packages/react/runtime/src/worklet/call/runOnMainThread.tsRepository: lynx-family/lynx-stack
Length of output: 2409
🏁 Script executed:
# Check the test files for runOnMainThread to understand expected behavior
cat packages/react/runtime/__test__/worklet/runOnMainThread.test.jsxRepository: lynx-family/lynx-stack
Length of output: 8942
🏁 Script executed:
# Also check the basic test
cat packages/react/worklet-runtime/__test__/runOnMainThread.test.jsRepository: lynx-family/lynx-stack
Length of output: 1316
🏁 Script executed:
# Check the web platform test to understand what runOnMainThread does
cat packages/web-platform/web-core-wasm-e2e/tests/reactlynx/basic-mts-run-on-main-thread/index.jsx | head -80Repository: lynx-family/lynx-stack
Length of output: 915
🏁 Script executed:
# Look for similar subscription patterns with cleanup
rg -B 3 -A 5 '\.subscribe\(' packages/motion/src/ --type ts --type tsxRepository: lynx-family/lynx-stack
Length of output: 93
🏁 Script executed:
# Search for other useEffect + runOnMainThread patterns
rg -B 2 -A 8 'useEffect.*runOnMainThread|runOnMainThread.*\.then' --type ts --type tsxRepository: lynx-family/lynx-stack
Length of output: 93
🏁 Script executed:
# Check if there are other examples in examples directory
find examples -name "*.tsx" -o -name "*.ts" | xargs rg -l "useEffect" | head -5Repository: lynx-family/lynx-stack
Length of output: 237
🏁 Script executed:
# Search for subscription patterns without type specification
rg '\.subscribe\(' packages/motion/src/ -A 5Repository: lynx-family/lynx-stack
Length of output: 126
🏁 Script executed:
# Check other example apps for comparison
for file in examples/tailwindcss/src/App.tsx examples/react-lazy-bundle/src/App.tsx examples/react-externals/src/App.tsx; do
echo "=== $file ===";
cat -n "$file" | head -60;
doneRepository: lynx-family/lynx-stack
Length of output: 4904
🏁 Script executed:
# Look for async patterns with runOnMainThread
rg 'async.*runOnMainThread|runOnMainThread.*async' -B 2 -A 5Repository: lynx-family/lynx-stack
Length of output: 3317
Guard main-thread subscription cleanup against race conditions.
The component can unmount before the .then() promise resolves, leaving unsubscribeHandle undefined. The non-null assertion at line 51 masks this type safety issue and cleanup will fail silently. Use async/await with a cancellation guard and explicit error handling instead.
🔧 Proposed fix
useEffect(() => {
console.info('Hello, ReactLynx');
- let unsubscribeHandle: (() => void) | undefined;
-
- runOnMainThread(() => {
- 'main thread';
-
- // Demo: Subscribe to value changes (main thread only)
- const unsubscribe = opacity.subscribe((newValue) => {
- console.info('Opacity changed to:', newValue);
- });
-
- // Demo: Subscribe to value changes (main thread only)
- const unsubscribeTapCount = tapCount.subscribe((newValue) => {
- console.info('TapCount changed to:', newValue);
- });
-
- return () => {
- unsubscribe();
- unsubscribeTapCount();
- };
- })().then((res) => {
- unsubscribeHandle = res as () => void;
- }).catch(_err => {
- // omitted
- });
-
- return () => {
- void runOnMainThread(unsubscribeHandle!)();
- };
+ let unsubscribeHandle: (() => void) | undefined;
+ let cancelled = false;
+
+ const init = async () => {
+ try {
+ const res = await runOnMainThread(() => {
+ 'main thread';
+
+ // Demo: Subscribe to value changes (main thread only)
+ const unsubscribe = opacity.subscribe((newValue) => {
+ console.info('Opacity changed to:', newValue);
+ });
+
+ // Demo: Subscribe to value changes (main thread only)
+ const unsubscribeTapCount = tapCount.subscribe((newValue) => {
+ console.info('TapCount changed to:', newValue);
+ });
+
+ return () => {
+ unsubscribe();
+ unsubscribeTapCount();
+ };
+ })();
+
+ if (typeof res !== 'function') {
+ return;
+ }
+
+ if (cancelled) {
+ await runOnMainThread(res)();
+ return;
+ }
+
+ unsubscribeHandle = res;
+ } catch (err) {
+ console.error('Main thread subscription failed', err);
+ }
+ };
+
+ void init();
+
+ return () => {
+ cancelled = true;
+ if (unsubscribeHandle) {
+ void runOnMainThread(unsubscribeHandle)().catch((err) => {
+ console.error('Main thread cleanup failed', err);
+ });
+ }
+ };
}, []);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| useEffect(() => { | |
| console.info('Hello, ReactLynx'); | |
| let unsubscribeHandle: (() => void) | undefined; | |
| runOnMainThread(() => { | |
| 'main thread'; | |
| // Demo: Subscribe to value changes (main thread only) | |
| const unsubscribe = opacity.subscribe((newValue) => { | |
| console.info('Opacity changed to:', newValue); | |
| }); | |
| // Demo: Subscribe to value changes (main thread only) | |
| const unsubscribeTapCount = tapCount.subscribe((newValue) => { | |
| console.info('TapCount changed to:', newValue); | |
| }); | |
| return () => { | |
| unsubscribe(); | |
| unsubscribeTapCount(); | |
| }; | |
| })().then((res) => { | |
| unsubscribeHandle = res as () => void; | |
| }).catch(_err => { | |
| // omitted | |
| }); | |
| return () => { | |
| void runOnMainThread(unsubscribeHandle!)(); | |
| }; | |
| useEffect(() => { | |
| console.info('Hello, ReactLynx'); | |
| let unsubscribeHandle: (() => void) | undefined; | |
| let cancelled = false; | |
| const init = async () => { | |
| try { | |
| const res = await runOnMainThread(() => { | |
| 'main thread'; | |
| // Demo: Subscribe to value changes (main thread only) | |
| const unsubscribe = opacity.subscribe((newValue) => { | |
| console.info('Opacity changed to:', newValue); | |
| }); | |
| // Demo: Subscribe to value changes (main thread only) | |
| const unsubscribeTapCount = tapCount.subscribe((newValue) => { | |
| console.info('TapCount changed to:', newValue); | |
| }); | |
| return () => { | |
| unsubscribe(); | |
| unsubscribeTapCount(); | |
| }; | |
| })(); | |
| if (typeof res !== 'function') { | |
| return; | |
| } | |
| if (cancelled) { | |
| await runOnMainThread(res)(); | |
| return; | |
| } | |
| unsubscribeHandle = res; | |
| } catch (err) { | |
| console.error('Main thread subscription failed', err); | |
| } | |
| }; | |
| void init(); | |
| return () => { | |
| cancelled = true; | |
| if (unsubscribeHandle) { | |
| void runOnMainThread(unsubscribeHandle)().catch((err) => { | |
| console.error('Main thread cleanup failed', err); | |
| }); | |
| } | |
| }; | |
| }, []); |
🤖 Prompt for AI Agents
In `@examples/react/src/App.tsx` around lines 22 - 52, The cleanup race occurs
because unsubscribeHandle may be undefined when the component unmounts; change
the runOnMainThread call to an async IIFE that awaits the result and uses a
local "cancelled" flag (or keeps the pending Promise) so cleanup can safely
no-op if the subscription setup hasn't completed: in useEffect, replace the
.then/.catch pattern with an async function that calls runOnMainThread(),
assigns the returned unsubscribe function to a local variable (e.g.,
unsubscribeHandle) only if not cancelled, and on return set cancelled=true and,
if unsubscribeHandle is set, call it; reference the existing useEffect,
runOnMainThread, unsubscribeHandle, opacity.subscribe, tapCount.subscribe, and
the unsubscribe/unsubscribeTapCount variables to locate where to implement this
guard and explicit error handling.
| get current(): T { | ||
| try { | ||
| return this.getValueOnMainThread(); | ||
| } catch { | ||
| // For backward compatibility / safety in background thread (though it throws in base) | ||
| // The base class throws if on BG. | ||
| // The original MainThreadRef threw on BG in DEV. | ||
| // Base class throws Error. | ||
| return super.getValueOnMainThread(); | ||
| } |
There was a problem hiding this comment.
Redundant try/catch in current getter.
The catch block calls super.getValueOnMainThread(), which is the same method that just threw. This will throw again, making the try/catch ineffective. If the intent is to provide a fallback, it should return this._initValue directly or handle the error differently.
🔧 Proposed fix
get current(): T {
- try {
- return this.getValueOnMainThread();
- } catch {
- // For backward compatibility / safety in background thread (though it throws in base)
- // The base class throws if on BG.
- // The original MainThreadRef threw on BG in DEV.
- // Base class throws Error.
- return super.getValueOnMainThread();
- }
+ return this.getValueOnMainThread();
}Or if a fallback to _initValue is intended:
get current(): T {
- try {
- return this.getValueOnMainThread();
- } catch {
- // For backward compatibility / safety in background thread (though it throws in base)
- // The base class throws if on BG.
- // The original MainThreadRef threw on BG in DEV.
- // Base class throws Error.
- return super.getValueOnMainThread();
- }
+ return this.getValueOnMainThread();
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| get current(): T { | |
| try { | |
| return this.getValueOnMainThread(); | |
| } catch { | |
| // For backward compatibility / safety in background thread (though it throws in base) | |
| // The base class throws if on BG. | |
| // The original MainThreadRef threw on BG in DEV. | |
| // Base class throws Error. | |
| return super.getValueOnMainThread(); | |
| } | |
| get current(): T { | |
| return this.getValueOnMainThread(); | |
| } |
🤖 Prompt for AI Agents
In `@packages/react/runtime/src/worklet/ref/workletRef.ts` around lines 25 - 34,
The try/catch in the current getter is redundant because catch calls
super.getValueOnMainThread() which will rethrow the same error; either remove
the try/catch and directly return this.getValueOnMainThread(), or if a fallback
is desired change the catch to return the stored fallback (this._initValue)
instead of calling super.getValueOnMainThread(); update the current getter
accordingly and keep references to getValueOnMainThread,
super.getValueOnMainThread, current, and _initValue to locate the change.
CodSpeed Performance ReportMerging this PR will degrade performance by 38.04%Comparing Summary
Performance Changes
Footnotes
|
Web Explorer#7380 Bundle Size — 384.24KiB (-0.13%).90a9cc3(current) vs 43fc7e7 main#7379(baseline) Bundle metrics
Bundle size by type
Bundle analysis report Branch f0rdream:main_thread_value Project dashboard Generated by RelativeCI Documentation Report issue |
|
This pull request has been automatically marked as stale because it has not had recent activity. If this pull request is still relevant, please leave any comment (for example, "bump"). |
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.
Checklist