fix(reactivity): Prevent TypeError in wineCtx due to non-atomic property access - #99
Draft
sentry[bot] wants to merge 1 commit into
Draft
fix(reactivity): Prevent TypeError in wineCtx due to non-atomic property access#99sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses issue RUST-G, a
TypeError: undefined is not an object (evaluating 'game.runtime.runtime')originating from thewineCtxfunction insrc/lib/types.ts. The fix involves caching the result ofgame?.runtimeinto a local variable (r) immediately after the initial check. This ensures that both the existence check (if (!r)) and the subsequent property access (r.runtime === 'wine') operate on the same, stable value, thereby eliminating the race condition caused by Svelte's reactivity and preventing theTypeError.Changes
wineCtxfunction insrc/lib/types.tsto use an atomic pattern for accessinggame.runtime.game?.runtimeto prevent race conditions in Svelte 5 reactive contexts (e.g.,$derivedinsrc/routes/+page.svelte).Testing
cargo test -p corkscrewpassesnpx svelte-check --threshold errorpassescargo tauri dev(if UI changes)Notes
Root Cause:
The
wineCtxfunction (lines 114-115) had a non-atomic pattern for accessinggame.runtime. It first checkedif (!game?.runtime)and then, in the subsequent line, accessedgame.runtime.runtime. WhenwineCtxis called from a Svelte 5 reactive context (e.g., a$derivedinsrc/routes/+page.svelte),gameis a reactive Proxy. Between the initial nullish check and the second property access, Svelte's reactivity system could re-evaluategame.runtime, causing it to becomeundefinedand leading to theTypeError.Solution:
The fix involves caching the result of
game?.runtimeinto a local variable (r) immediately after the initial check. This ensures that both the existence check (if (!r)) and the subsequent property access (r.runtime === 'wine') operate on the same, stable value, thereby eliminating the race condition caused by Svelte's reactivity and preventing theTypeError.Fixes RUST-G