Skip to content

Cross-platform observation delivery + WebAssembly build support - #152

Closed
0xLeif wants to merge 0 commit into
mainfrom
fix/cross-platform-observation-wasm
Closed

Cross-platform observation delivery + WebAssembly build support#152
0xLeif wants to merge 0 commit into
mainfrom
fix/cross-platform-observation-wasm

Conversation

@0xLeif

@0xLeif 0xLeif commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Makes AppState's reactivity work everywhere Swift's Observation runs, and unblocks WebAssembly.

#150 — observation delivery off Apple

The Observation framework is cross-platform, but AppState only delivered changes on Apple: state setters write to the untracked Cache, and the Combine bridge consume(object: cache) (Apple-only) called notifyChange(). On Linux/Windows/wasm there was no bridge, so withObservationTracking { … } onChange: never fired.

Now every mutation path (State / StoredState / FileState / SyncState / SecureState / DependencySlice) calls notifyChange() directly on all platforms, and the Combine cache bridge is removed so Apple still fires exactly once. Observation tests are un-gated to run cross-platform (Apple-only SecureState/SyncState assertions guarded individually) — CI now exercises observation on Linux.

#149 — WebAssembly build

Combine-gated #if !os(Linux) && !os(Windows) guards (import Combine, the cancellable bag, consume, @ObservedDependency, OSLog/SwiftUI) included os(WASI). Switched the Combine/OSLog/SwiftUI ones to canImport(...). Keychain (SecureState) and iCloud KV (SyncState) stay Apple-only.

Verification

163 tests pass on macOS, against both published Cache 2.1.2 and the WASM/Linux-fixed Cache branch.

Sequencing

Full WebAssembly build and Linux collection-typed state also need the Cache fix — 0xLeif/Cache#30. Recommend merging + releasing that first, then bumping AppState's Cache pin. #150 observation delivery is AppState-only and verified by this PR's Linux CI independently.

Addresses #149, #150, #151.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors platform-specific checks (#if !os(Linux) && !os(Windows)) to use feature-based checks (canImport) across the codebase, and adds a detailed note regarding a known Swift-on-Linux runtime crash (Issue #151). It also introduces notifyChange() calls to several state setters to ensure proper observation. However, a critical thread-safety issue was identified: because these state setters (such as StoredState, FileState, SyncState, and DependencySlice) are not restricted to @MainActor, they can be invoked from background threads. This would trigger a main-thread assertion in notifyChange() and crash the application. It is highly recommended to make notifyChange() thread-safe or dispatch it to the main thread.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@0xLeif
0xLeif force-pushed the fix/cross-platform-observation-wasm branch 2 times, most recently from 1c54db2 to b47b388 Compare June 11, 2026 15:22
@cursor cursor Bot closed this Jul 17, 2026
@cursor
cursor Bot force-pushed the fix/cross-platform-observation-wasm branch from b47b388 to 515e7c3 Compare July 17, 2026 20:19
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.

1 participant