fix: stabilize AI-aware page translation cache title#1280
Closed
frogGuaGuaGuaGua wants to merge 1 commit intomainfrom
Closed
fix: stabilize AI-aware page translation cache title#1280frogGuaGuaGuaGua wants to merge 1 commit intomainfrom
frogGuaGuaGuaGua wants to merge 1 commit intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 63235c2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
Contributor trust score40/100 — Moderate This score estimates contributor familiarity with Outcome
Score breakdown
Signals used
Policy
Updated automatically when the PR changes or when a maintainer reruns the workflow. |
|
Related Documentation 1 document(s) may need updating based on files changed in this PR: Read Frog - Open Source Immersive Translate how translation cache worksView 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 providersNote: You must be authenticated to accept/decline updates. |
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.
Type of Changes
Description
This fixes the unstable same-page cache misses reported in #1254 when AI Content Aware is enabled.
Root cause
getOrFetchArticleData()cached articletextContentby URL, but it kept re-reading the livedocument.titleon every request.During page translation, the tab title itself can be translated, so the same page could produce two different article-title contexts:
That drift changed the AI-aware cache key for otherwise identical body text, causing needless cache misses and repeated API calls.
Fix
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.tseslint src/utils/host/translate/article-context.ts src/utils/host/translate/__tests__/article-context.test.tsSummary 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.
{ url, title, textContent }ingetOrFetchArticleData()and reuse the cached title while the URL stays the same.document.titlebehavior when Content Aware is off.Written for commit 63235c2. Summary will update on new commits.