fix(dom): hoist titles from element roots #80
main fromrefs/pull/80/head·opened Fix <title> handling for createRoot(element). In Redact 0.2.1, the title stays in the body, so document.title still shows the title from index.html. React 19.3.0 moves the rendered title into the head.
StackBlitz reproduction · Source
Click Read document.title, then Change title and read it again. The component changes its title from Page A to Page B, but Redact keeps reporting Static shell title. Run pnpm react instead of pnpm start to compare with React.
Changes#
- Hoist Element-root titles into the root's owner document, before the existing title. Keep the original title so it becomes active again when the rendered title is removed.
- Leave Document-root metadata handling unchanged and retain the SVG,
itemProp, and portal exclusions. - During Element-root hydration, adopt titles from the root's markup rather than taking ownership of an unrelated title in the head.
- Add five regression tests and a patch changeset.
Validation#
Checked against main at 20f6dd6 with Node 24.22.0:
- 1,960 tests pass, including the five new cases; 91 existing tests are skipped.
- Type checks and build verification pass.
- Chromium: mounting, updating, removing, and remounting the title produces
Page A → Page B → Static shell title → Page A. - Confirmed the bug with unpatched 0.2.1 locally and in StackBlitz.
Size#
The size check still fails for the four entries below, so this remains a draft. Size limits are unchanged.
| Entry | Gzip bytes | Limit | Over limit |
|---|---|---|---|
| Source default Vite client | 23,429 | 23,335 | 94 |
| Source client, viewTransitions stub | 20,497 | 20,451 | 46 |
| Built default Vite client | 23,448 | 23,335 | 113 |
| Built client, viewTransitions stub | 20,502 | 20,452 | 50 |
Implementation and tests prepared with GPT-6.1 Terra.
Summary by CodeRabbit#
- New Features
- Titles rendered inside element roots appear before the existing page title. When a rendered title is removed or the root is unmounted, the existing title is restored.
- Title handling works during hydration and within HTML content inside SVG
foreignObjectelements. Titles in certain SVG, portal, oritemPropcontexts remain in place.
- 1
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
873f6775-74f2-45ef-9b1f-fcf17f93dc25
Commits-
Reviewing files that changed from the base of the PR and between 5f6780c919388f8cd2431293ac2110f4b50c593e and f8e9baa7dc055773da350e478898c4e8f621b077.
Files selected for processing: 2-
packages/redact/src/dom/features/hydration/full.tspackages/redact/src/dom/reconcile.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
-
Walkthrough
-
Eligible titles rendered into element roots are hoisted to the owning document’s head before the shell title. The shell title is restored when the rendered title is removed or the root is unmounted. Tests cover hydration, alternate document ownership, and excluded contexts.
Changes: Element-root title handling
Layer / File(s) Summary Metadata parent eligibility
packages/redact/src/dom/document-metadata.tsMetadata-parent selection supports eligible titles in element containers. It excludes itemPropelements, portal ancestry, and SVG contexts outsideforeignObject.Title placement, hydration, and validation
packages/redact/src/dom/reconcile.ts,packages/redact/src/dom/features/hydration/full.ts,tests/element-root-title.test.tsx,.changeset/tidy-element-titles.mdPlacement inserts an element-root title before an existing direct title. Hydration checks for a projected metadata parent only for document roots. Tests cover title updates, restoration, hydration, alternate document ownership, and excluded contexts. Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Suggested reviewers:
tannerlinsley
Merge Risk:
Minimal · up tof8e9b-
No actionable merge-blocking correctness or availability risk is established by the reviewed change.
Pre-merge checks:
5-
Check name Status Explanation Description Check Check skipped - CodeRabbit’s high-level summary is enabled. Title check The title clearly and concisely describes the main change: hoisting titles from element roots. Docstring Coverage Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment `@coderabbitai help` to get the list of available commands.-
Codex Review Summary#
This comment shows the latest Codex review activity on this pull request.
Review Status Commit Review trigger 📝 Code Review ⚠️ Failed 2026-10-27T11:31:26.605077Z
We couldn’t complete this review. Comment@codex reviewto try again.5f6780cDraft marked ready ℹ️ About Codex in GitHub
Your team has set up Codex to 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" or "@codex security review".
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: f8e9baa7dc055773da350e478898c4e8f621b077
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