Skip to content

fix(reactivity): Prevent TypeError in wineCtx due to non-atomic property access - #99

Draft
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/wine-ctx-typerror
Draft

fix(reactivity): Prevent TypeError in wineCtx due to non-atomic property access#99
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/wine-ctx-typerror

Conversation

@sentry

@sentry sentry Bot commented May 27, 2026

Copy link
Copy Markdown

Summary

This PR addresses issue RUST-G, a TypeError: undefined is not an object (evaluating 'game.runtime.runtime') originating from the wineCtx function in src/lib/types.ts. The fix involves caching the result of game?.runtime into 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 the TypeError.

Changes

  • Modified the wineCtx function in src/lib/types.ts to use an atomic pattern for accessing game.runtime.
  • Introduced a local variable to cache the result of game?.runtime to prevent race conditions in Svelte 5 reactive contexts (e.g., $derived in src/routes/+page.svelte).

Testing

  • cargo test -p corkscrew passes
  • npx svelte-check --threshold error passes
  • Manually tested with cargo tauri dev (if UI changes)

Notes

Root Cause:
The wineCtx function (lines 114-115) had a non-atomic pattern for accessing game.runtime. It first checked if (!game?.runtime) and then, in the subsequent line, accessed game.runtime.runtime. When wineCtx is called from a Svelte 5 reactive context (e.g., a $derived in src/routes/+page.svelte), game is a reactive Proxy. Between the initial nullish check and the second property access, Svelte's reactivity system could re-evaluate game.runtime, causing it to become undefined and leading to the TypeError.

Solution:
The fix involves caching the result of game?.runtime into 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 the TypeError.

Fixes RUST-G

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants