fix: Currency API fetch works in Web Worker context (fixes #18)#41
Merged
fix: Currency API fetch works in Web Worker context (fixes #18)#41
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #18
The currency exchange rate API fetch was silently failing because `web_sys::window()` returns `None` in Web Worker contexts. Workers don't have a `window` object - they use `WorkerGlobalScope` instead. Changes: - Use `js_sys::global()` to detect the execution context - Support both `Window` and `WorkerGlobalScope` for fetch operations - Add `WorkerGlobalScope` feature to web-sys dependency - Update case study documentation with root cause analysis This is the actual root cause of issue #18 - the previous fix in PR #38 added the rate application code but the API fetch was never working. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This reverts commit a7c6759.
Contributor
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
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 fixes the root cause of issue #18 where exchange rates were showing as "hardcoded" with "unknown" date instead of using real-time API data.
Root Cause Analysis
The currency exchange rate API fetch was silently failing because
web_sys::window()returnsNonein Web Worker contexts. Web Workers don't have awindowobject - they useWorkerGlobalScopeinstead.Before (broken):
After (fixed):
Changes
src/currency_api.rs: Usejs_sys::global()to detect and use eitherWindoworWorkerGlobalScopecontext for fetch operationsCargo.toml: AddWorkerGlobalScopefeature to web-sys dependencydocs/case-studies/issue-18/README.md: Update documentation with root cause analysischangelog.d/: Add changelog fragment for the fixTest Plan
cargo fmt --checkpassescargo clippypassescargo testpasses (all 66+ tests)Related
🤖 Generated with Claude Code