Skip to content

fix(page-translation): translate initially visible content#1538

Open
frogGuaGuaGuaGua wants to merge 1 commit into
mainfrom
hermes/issue-1537-20260517-200017
Open

fix(page-translation): translate initially visible content#1538
frogGuaGuaGuaGua wants to merge 1 commit into
mainfrom
hermes/issue-1537-20260517-200017

Conversation

@frogGuaGuaGuaGua

Copy link
Copy Markdown
Collaborator

Type of Changes

  • ✨ New feature (feat)
  • 🐛 Bug fix (fix)
  • 📝 Documentation change (docs)
  • 💄 UI/style change (style)
  • ♻️ Code refactoring (refactor)
  • ⚡ Performance improvement (perf)
  • ✅ Test related (test)
  • 🔧 Build or dependencies update (build)
  • 🔄 CI/CD related (ci)
  • 🌐 Internationalization (i18n)
  • 🧠 AI model related (ai)
  • 🔄 Revert a previous commit (revert)
  • 📦 Other changes that do not modify src or test files (chore)

Description

When page translation starts, existing paragraphs are registered with IntersectionObserver and 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?

  • Added unit tests
  • Verified through manual testing

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.ts
  • SKIP_FREE_API=true pnpm type-check
  • SKIP_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.ts
  • WXT_SKIP_ENV_VALIDATION=true SKIP_FREE_API=true pnpm build:edge
  • Push hook also passed nx run @read-frog/extension:lint, nx run @read-frog/extension:type-check, and nx 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

  • I have tested these changes locally
  • I have updated the documentation accordingly if necessary
  • My code follows the code style of this project
  • My changes do not break existing functionality
  • If my code was generated by AI, I have proofread and improved it as necessary.

Additional Information

  • Includes a patch changeset for @read-frog/extension.

@changeset-bot

changeset-bot Bot commented May 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bf3f1a2

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

@github-actions github-actions Bot added fix contrib-trust:moderate PR author trust score is 30-59. labels May 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Contributor trust score

43/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 24/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: 15 (author commits reachable from the repository default branch)
  • Repo PR history: merged 17, open 5, closed-unmerged 27
  • Repo reviews: 0
  • PR changed lines: 146 (+132 / -14)
  • Repo permission: write
  • Followers: 0
  • Account age: 2 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.

@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: 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".

Comment on lines +426 to 428
if (container.hasAttribute("data-read-frog-paragraph") && container.getAttribute("data-read-frog-walked") === walkId) {
observer.observe(container)
return

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 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 👍 / 👎.

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

This PR has been inactive for 14 days and is now marked as stale.
It will be automatically closed in 30 days if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] edge搜索页面翻译小问题

2 participants