Skip to content

Fix offline widget book covers with shared caching - #82

Merged
itsthisjustin merged 2 commits into
crosspoint-reader:mainfrom
jcapayne:codex/widget-offline-covers
Nov 9, 2026
Merged

itsthisjustin merged 2 commits into
crosspoint-reader:mainfrom
jcapayne:codex/widget-offline-covers

Conversation

@jcapayne

@jcapayne jcapayne commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

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.
  • Rust library tests: 20 passed, 1 ignored, including account/book/cover identity boundaries.
  • Production frontend and iOS widget builds passed; the signed iOS app and widget were built and installed on a physical iPhone.
  • Android compilation was attempted but blocked before project compilation by the local Java 26/Gradle incompatibility.

Before and after with airplane mode on:

IMG_1420 IMG_1421

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T21:22:49.752880Z ba95372 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant widget.js
  participant cached.cover
  participant coverBlob
  participant update_widget
  widget.js->>cached.cover: Resolve cover URL when book URL is absent
  widget.js->>coverBlob: Load blob for resolved URL
  coverBlob-->>widget.js: Return cover blob
  widget.js->>update_widget: Publish cover data and identity
  update_widget->>update_widget: Compare incoming identity with previous snapshot
Loading

Possibly related PRs

Suggested reviewers: itsthisjustin

Merge Risk: Minimal · up to ba953

No actionable issue remains from this review; the change is mergeable after normal checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

Recent 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: 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.

82-122: LGTM!

app/src/api.js: 2

118-118: LGTM!

301-302: LGTM!

Also applies to: 334-334, 545-545

app/src/api.test.js: 1

372-387: LGTM!

app/src/coverCache.test.js: 1

1-49: LGTM!

app/src/ui.jsx: 1

4-4: LGTM!

Also applies to: 218-223

app/src/Cover.test.jsx: 1

5-7: LGTM!

Also applies to: 22-27

app/src/widget.js: 1

3-4: LGTM!

Also applies to: 24-24, 32-34, 76-76, 81-86

app/src/widget.test.js: 1

5-8: LGTM!

Also applies to: 17-22, 77-81, 97-138

app/scripts/widget-tests/main.swift: 1

32-49: LGTM!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 841c1ea400

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

data.title = current?.title ?? current?.filename ?? "Nothing in progress"
data.author = current?.author ?? ""
data.percent = current.map { min(100, max(0, Int((($0.percentage ?? 0) * 100).rounded()))) } ?? -1
coverChanged = current?.document != data.book_document || current?.cover_url != data.cover_url || !hasCover

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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.

Useful? React with 👍 / 👎.

Comment thread app/src-tauri/src/widget.rs Outdated
Comment on lines +86 to +87
["session", "book_document", "cover_url"].iter().all(|key|
!incoming[*key].is_null() && incoming[*key] == previous[*key])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Additional comments: 3

app/src/coverCache.js: 1

20-22: Trivial · Functional Correctness · Poor tradeoff

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.

Proposed fix

-    const img = await createImageBitmap(await coverBlob(url))
+    const img = await createImageBitmap(await coverBlob(url))
+    try {
       ...
-    const cover = canvas.toDataURL('image/png').split(',')[1]
-    img.close()
-    return cover
+      return canvas.toDataURL('image/png').split(',')[1]
+    } finally {
+      img.close()
+    }
app/src-tauri/src/widget.rs: 1

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.

Review details

Context from checks skipped due to timeout: 2

  • GitHub Check: CodeRabbit
  • GitHub Check: docker (linux/arm64)
Additional comments: 12

app/src/api.js: 4

118-118: LGTM!


301-302: LGTM!


334-334: LGTM!


545-545: LGTM!

app/src/api.test.js: 1

372-387: LGTM!

app/src/coverCache.js: 1

5-30: LGTM!

app/src/coverCache.test.js: 1

1-49: LGTM!

app/src/ui.jsx: 1

4-4: LGTM!

Also applies to: 218-223

app/src/Cover.test.jsx: 1

5-7: LGTM!

Also applies to: 22-28

app/src/widget.js: 1

76-86: LGTM!

app/src/widget.test.js: 1

5-8: LGTM!

Also applies to: 17-22, 77-81, 97-138

app/src-tauri/src/widget.rs: 1

82-117: LGTM!

@jcapayne

jcapayne commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

good to go @itsthisjustin

@itsthisjustin
itsthisjustin merged commit 054e157 into crosspoint-reader:main Nov 9, 2026
5 checks passed
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.

2 participants