fix(page-translation): translate initially visible content#1538
fix(page-translation): translate initially visible content#1538frogGuaGuaGuaGua wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: bf3f1a2 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 trust score43/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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf3f1a2620
ℹ️ 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".
| if (container.hasAttribute("data-read-frog-paragraph") && container.getAttribute("data-read-frog-walked") === walkId) { | ||
| observer.observe(container) | ||
| return |
There was a problem hiding this comment.
Translate visible paragraph containers before returning
When the observed container itself is the paragraph (for example a newly inserted visible <p> or a page whose body has direct text and is labeled as a paragraph), this branch still only calls observe() and returns, so it bypasses the new translateIfAlreadyWithinPreloadRange path. In the same browsers/pages where the initial IntersectionObserver callback is delayed until scroll, that top-level visible paragraph remains untranslated even though it is already inside the preload range.
Useful? React with 👍 / 👎.
|
This PR has been inactive for 14 days and is now marked as stale. |
Type of Changes
Description
When page translation starts, existing paragraphs are registered with
IntersectionObserverand translated once the observer reports them as intersecting. On some search-result pages this initial observer callback may not run until the page is scrolled, so the text already visible at the top can stay untranslated until the user scrolls.This PR keeps the existing observer-based lazy translation path, but also checks each newly observed top-level paragraph against the current viewport plus the configured preload margin. If it is already in range when page translation starts, it is translated immediately and unobserved to avoid duplicate work.
Related Issue
Closes #1537
How Has This Been Tested?
Commands run:
SKIP_FREE_API=true pnpm exec vitest run src/entrypoints/host.content/translation-control/__tests__/page-translation-mutations.test.ts --testNamePattern 'immediately translates already visible paragraphs'SKIP_FREE_API=true pnpm exec vitest run src/entrypoints/host.content/translation-control/__tests__/page-translation-mutations.test.tsSKIP_FREE_API=true pnpm type-checkSKIP_FREE_API=true pnpm lint src/entrypoints/host.content/translation-control/page-translation.ts src/entrypoints/host.content/translation-control/__tests__/page-translation-mutations.test.tsWXT_SKIP_ENV_VALIDATION=true SKIP_FREE_API=true pnpm build:edgenx run @read-frog/extension:lint,nx run @read-frog/extension:type-check, andnx run @read-frog/extension:test(140 test files / 1219 tests).Screenshots
N/A — this is a behavioral content-script trigger fix, not a visual layout/style change. The regression is covered by the new test that confirms an already-visible paragraph is translated immediately when page translation starts.
Checklist
Additional Information
@read-frog/extension.