Skip to content

Keep page translation tied to the current document and text - #59

Merged
rangaNP merged 3 commits into
mainfrom
fix/page-translation
Nov 22, 2026
Merged

rangaNP merged 3 commits into
mainfrom
fix/page-translation

Conversation

@rangaNP

@rangaNP rangaNP commented Nov 22, 2026

Copy link
Copy Markdown
Member

Summary

A delayed system translation session could start on a page the user had already left. Translation and Show Original could also overwrite text the site had since edited. Hidden text could consume the entire translation quota before the visible article reached the translator.

Changes

  • Give each request its own SwiftUI translation task. Check the request, live page, committed document and navigation when Apple supplies a session. Cancelling a partial translation restores the text still owned by that run.
  • Check each text node before writing a translation or restoring its original. Preserve site edits and replacements during batch delivery, Show Original and subsequent collection passes.
  • Skip hidden and excluded subtrees and follow rendered content through open shadow roots and slots. Keep the existing limits of 3,000 text nodes and 100,000 characters. Cap traversal at 30,000 inspected nodes.

Testing

  • All 1,033 Swift tests and eight release-script tests passed on macOS 27.2.1 with Xcode 27.2. Debug build-for-testing and the Release build succeeded. Both app signatures passed deep, strict verification.
  • Six regression tests detected the old behavior on the base commit. Delayed delivery was exercised after cancellation, a replacement request, a same-address reload, a same-document route change and closing and reopening the tab.
  • In real WebKit fixtures, the base commit sent 100,000 hidden characters or 3,000 hidden nodes and missed the article. The updated collector sent the six rendered segments in each fixture. Another fixture collected 41 text nodes under one article element with one style read for that element and zero style reads inside the hidden subtree.
  • A new CI-only UI test uses the system Translation framework. It exercises Show Original with installed languages or dismisses the language-download prompt. It skips an unsupported language pair. The test compiled locally and awaits CI execution.

Checklist

  • I reviewed the diff and kept the changes focused on this PR.
  • I described the validation performed and the remaining native UI check.
  • I understand the changes and can address maintainer questions in review.

Bind each system session to the request, page instance, document and navigation that created it. Scope DOM updates and restoration to the owning run and preserve text the page has edited or replaced.

Walk the rendered page and open shadow roots within node and character budgets. Cover late delivery, cancellation, site mutations, hidden content and the native translation UI.
@rangaNP
rangaNP merged commit 007f81d into main Nov 22, 2026
5 checks passed
@rangaNP
rangaNP deleted the fix/page-translation branch November 22, 2026 08:02
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.

1 participant