Skip to content

fix: stabilize AI-aware page translation cache title#1280

Closed
frogGuaGuaGuaGua wants to merge 1 commit intomainfrom
fix/issue-1254-stable-page-title-cache
Closed

fix: stabilize AI-aware page translation cache title#1280
frogGuaGuaGuaGua wants to merge 1 commit intomainfrom
fix/issue-1254-stable-page-title-cache

Conversation

@frogGuaGuaGuaGua
Copy link
Copy Markdown
Collaborator

@frogGuaGuaGuaGua frogGuaGuaGuaGua commented Apr 4, 2026

Type of Changes

  • 🐛 Bug fix (fix)
  • ✅ Tests

Description

This fixes the unstable same-page cache misses reported in #1254 when AI Content Aware is enabled.

Root cause

getOrFetchArticleData() cached article textContent by URL, but it kept re-reading the live document.title on every request.
During page translation, the tab title itself can be translated, so the same page could produce two different article-title contexts:

  1. first translation pass → original source title
  2. second pass after toggling back on → translated browser title

That drift changed the AI-aware cache key for otherwise identical body text, causing needless cache misses and repeated API calls.

Fix

  • Cache the article title together with the article text content for a given URL
  • Reuse that stable source title while the URL stays the same
  • Add regression tests covering:
    • stable title reuse on the same URL
    • unchanged live-title behavior when AI Content Aware is off
    • cache refresh when the URL changes

Fixes #1254.

Testing

  • vitest run src/utils/host/translate/__tests__/article-context.test.ts src/utils/host/__tests__/translate-text.test.tsx src/entrypoints/host.content/translation-control/__tests__/page-translation-title.test.ts
  • eslint src/utils/host/translate/article-context.ts src/utils/host/translate/__tests__/article-context.test.ts

Summary by cubic

Stabilizes page translation caching by storing the source title with article text per URL, preventing cache key drift when the browser title changes during translation. Fixes #1254 and reduces duplicate API calls.

  • Bug Fixes
    • Cache { url, title, textContent } in getOrFetchArticleData() and reuse the cached title while the URL stays the same.
    • Keep live document.title behavior when Content Aware is off.
    • Refresh cached data when the URL changes.
    • Added tests for stable title reuse, live-title behavior, and URL-change refresh.

Written for commit 63235c2. Summary will update on new commits.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 4, 2026

🦋 Changeset detected

Latest commit: 63235c2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@read-frog/extension Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 4, 2026
@github-actions github-actions bot added fix contrib-trust:moderate PR author trust score is 30-59. labels Apr 4, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

Contributor trust score

40/100 — Moderate

This score estimates contributor familiarity with mengxi-ream/read-frog using public GitHub signals. It is advisory only and does not block merges automatically.

Outcome

Score breakdown

Dimension Score Signals
Repo familiarity 21/35 commits in repo, merged PRs, reviews
Community standing 11/25 account age, followers, repo role
OSS influence 0/20 stars on owned non-fork repositories
PR track record 8/20 merge rate across resolved PRs in this repo

Signals used

  • Repo commits: 6 (author commits reachable from the repository default branch)
  • Repo PR history: merged 6, open 2, closed-unmerged 9
  • Repo reviews: 0
  • PR changed lines: 110 (+106 / -4)
  • Repo permission: write
  • Followers: 1
  • Account age: 0 months
  • Owned non-fork repos considered: max 0, total 0 (none)

Policy

  • Low-score review threshold: < 30
  • Auto-close: score < 20 and changed lines > 1000
  • Policy version: v1.1

Updated automatically when the PR changes or when a maintainer reruns the workflow.

@dosubot dosubot bot added the app: browser extension Related to browser extension label Apr 4, 2026
@dosubot
Copy link
Copy Markdown

dosubot bot commented Apr 4, 2026

Related Documentation

1 document(s) may need updating based on files changed in this PR:

Read Frog - Open Source Immersive Translate

how translation cache works
View Suggested Changes
@@ -52,13 +52,13 @@
 This means that the same text will have different cache entries when:
 1. It appears on different pages (different article titles)
 2. It appears in articles with different content
-3. The page title changes
 
 **Article Context Extraction:**
 - Article context is extracted using the `article-context.ts` module
 - Uses Mozilla Readability to extract clean article content
 - Falls back to `document.body.textContent` if Readability fails
-- Context is cached per URL to avoid repeated extraction
+- Both the article title and text content are cached together per URL to ensure cache stability
+- The cached title is reused for the same URL even if the browser tab title is translated during page translation
 
 **Impact on Cache Behavior:**
 - Cache entries are more specific when AI Content Aware is enabled with LLM providers

[Accept] [Decline]

Note: You must be authenticated to accept/decline updates.

How did I do? Any feedback?  Join Discord

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

@mengxi-ream mengxi-ream closed this Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: browser extension Related to browser extension contrib-trust:moderate PR author trust score is 30-59. fix size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] 翻译文本缓存

2 participants