You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix offline widget book covers with shared caching - #82
Widgets lose their book cover when an offline app update cannot download it: the native bridges delete the previously saved image. This change shares a persistent cover cache between the app and widget publishing, reuses WebView-cached images when available, and preserves native covers only when the account, document, and exact cover URL match.
Missing covers remain retryable. Image decoding precedes cache writes, and book metadata edits invalidate saved cover lookups so corrected or cleared covers cannot restore an old image.
Validation:
415 frontend tests passed, including offline cache, book/URL changes, sign-out races, invalid image responses, and lookup invalidation.
No actionable comments were generated in the recent review.
Walkthrough
The app now caches cover blobs and URLs, uses them when preparing widget covers, and checks widget identity before removing saved cover data.
Changes: Cover caching and widget updates
Layer / File(s)
Summary
Cover URL and blob cache lifecycle app/src/api.js, app/src/api.test.js, app/src/coverCache.js, app/src/coverCache.test.js
The API exposes cached cover URLs and invalidates them when book metadata changes or a book is removed. coverBlob reads and validates cached images, uses the WebView cache or HTTP fallback, and best-effort caches successful blobs. Tests cover reuse, retrieval paths, validation, and stale responses.
Cache covers displayed in the app app/src/ui.jsx, app/src/Cover.test.jsx
When the app is active and a cover is near the viewport, the UI calls coverBlob. The test checks calls for the displayed cover URLs.
Resolve and publish widget covers app/src/widget.js, app/src/widget.test.js, app/src-tauri/src/widget.rs, app/scripts/widget-tests/main.swift
The widget resolves a cover URL from the book or cached API data, converts the image to PNG, and publishes the update. The native update compares identity fields before retaining saved cover data. Tests cover URL lookup, retries, snapshot refresh, and identity matching.
No actionable issue remains from this review; the change is mergeable after normal checks.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "Fix offline widget book covers with shared caching" matches the main change. The changeset adds a shared persistent cover cache (coverBlob in coverCache.js, used by widget.js and ui.jsx) an…
Description check
The description explains the problem and the change. It states that widgets lose covers during offline updates, that a shared persistent cover cache is added, that native covers are kept only on exact…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "Fix offline widget book covers with shared caching" matches the main change. The changeset adds a shared persistent cover cache (coverBlob in coverCache.js, used by widget.js and ui.jsx) and keeps native widget covers when the account, document, and cover URL match (widget.rs matching_cover). The title is specific and under 80 characters, so it passes.
Full details: Description check
Explanation
The description explains the problem and the change. It states that widgets lose covers during offline updates, that a shared persistent cover cache is added, that native covers are kept only on exact account, document, and cover URL matches, and that book metadata edits invalidate saved cover lookups. These points match the raw summary and the changed files. It also lists validation steps. The description is related to the changeset, so it passes.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
Clippy (1.99.1)
Clippy execution timed out
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: cc339f3d-62d8-4a53-91a7-9a209eb8f20f
Commits
Reviewing files that changed from the base of the PR and between bb1eb50 and ba95372.
Files ignored due to path filters: 3
app/src-tauri/gen/android/app/src/main/java/com/crosspointreader/sync/ReadingWidget.kt is excluded by !**/gen/**
app/src-tauri/gen/apple/CrossPointWidget/CrossPointWidget.swift is excluded by !**/gen/**
app/src-tauri/gen/apple/CrossPointWidget/ReadingMetrics.swift is excluded by !**/gen/**
Files selected for processing: 10
app/scripts/widget-tests/main.swift
app/src-tauri/src/widget.rs
app/src/Cover.test.jsx
app/src/api.js
app/src/api.test.js
app/src/coverCache.js
app/src/coverCache.test.js
app/src/ui.jsx
app/src/widget.js
app/src/widget.test.js
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.
Recent review details
Context from checks skipped due to timeout: 1
GitHub Check: CodeRabbit
Additional comments: 11
app/src-tauri/src/widget.rs: 2
25-31: Functional Correctness · Low value
An empty-cover update now fails when json is invalid, before any snapshot write.
Line 25 returns early when json fails to parse. The JS caller always sends JSON.stringify output, so this is safe today. The behavior differs from before: an invalid payload used to be written as-is. It is also acceptable. No action is required.
The reason will be displayed to describe this comment to others. Learn more.
Preserve covers written during a provider retry
When the sync server is reachable but the cover host is not, this can set coverChanged because cover.png was missing and then wait on the network; meanwhile the app can recover the image from crosspoint-covers-v1 and publish the same JSON snapshot plus cover bytes. The final supersession guard compares only widget.json, so it still passes and the newCover == nil branch removes the cover the app just wrote. The Android !hasCover path has the same same-JSON race; recheck the cover under the final lock or track a cover generation before deleting it.
The reason will be displayed to describe this comment to others. Learn more.
Treat password rotation as the same account
When a signed-in reader changes their password, Settings keeps the server and username but replaces only session.key; if the ensuing cover fetch is unavailable, comparing the whole session makes same_cover false and removes cover.png even though the account, document, and URL still match. Android explicitly includes key in the analogous comparison as well, so both widgets can become blank after credential rotation; compare stable account fields rather than the credential.
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Do not let the WebView fetch reuse a stale HTTP-cached response for a changed image.
fetch(url, { cache: 'force-cache' }) returns any WebView-cached response, even a stale one. The cache key is the exact URL, so this is acceptable for corrected covers. If a server replaces the image at the same URL, the widget keeps the old bytes. The Cache API entry then keeps those bytes with no expiry.
Consider this a known limitation. Document it, or add a TTL to the stored entry.
app/src/widget.js: 1
24-34: Trivial · Stability & Availability · Low value
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Close img on all paths in coverBase64.
img.close() runs only on success. If getContext returns null or drawImage throws, the ImageBitmap stays open until garbage collection. Use try/finally to release it.
25-27: Trivial · Stability & Availability · Low value
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Do not fail the widget update when json is not parseable.
The old code always removed the cover and wrote the snapshot. Now a parse error returns Err before any write. The JS caller always sends valid JSON, so the impact is small. For safety, treat a parse failure as "no match": remove the cover and continue.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 0b8dc028-2b5d-43f4-b574-4821fa07c90d
Commits
Reviewing files that changed from the base of the PR and between bb1eb50 and 841c1ea.
Files ignored due to path filters: 2
app/src-tauri/gen/android/app/src/main/java/com/crosspointreader/sync/ReadingWidget.kt is excluded by !**/gen/**
app/src-tauri/gen/apple/CrossPointWidget/CrossPointWidget.swift is excluded by !**/gen/**
Files selected for processing: 9
app/src-tauri/src/widget.rs
app/src/Cover.test.jsx
app/src/api.js
app/src/api.test.js
app/src/coverCache.js
app/src/coverCache.test.js
app/src/ui.jsx
app/src/widget.js
app/src/widget.test.js
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
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
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.
Widgets lose their book cover when an offline app update cannot download it: the native bridges delete the previously saved image. This change shares a persistent cover cache between the app and widget publishing, reuses WebView-cached images when available, and preserves native covers only when the account, document, and exact cover URL match.
Missing covers remain retryable. Image decoding precedes cache writes, and book metadata edits invalidate saved cover lookups so corrected or cleared covers cannot restore an old image.
Validation:
Before and after with airplane mode on: