Skip to content

fix(dom): hoist titles from element roots - #80

Open
Clickin wants to merge 2 commits into
TanStack:mainfrom
Clickin:fix/element-root-title-hoisting
Open

Clickin wants to merge 2 commits into
TanStack:mainfrom
Clickin:fix/element-root-title-hoisting

Conversation

@Clickin

@Clickin Clickin commented Oct 27, 2026 •

Copy link
Copy Markdown

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 foreignObject elements. Titles in certain SVG, portal, or itemProp contexts remain in place.

@changeset-bot

changeset-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f8e9baa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/redact 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

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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 5f6780c and f8e9baa.

Files selected for processing: 2
  • packages/redact/src/dom/features/hydration/full.ts
  • packages/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.ts
Metadata-parent selection supports eligible titles in element containers. It excludes itemProp elements, portal ancestry, and SVG contexts outside foreignObject.
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.md
Placement 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 to f8e9b

No actionable merge-blocking correctness or availability risk is established by the reviewed change.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: hoisting titles from element roots.
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Clickin
Clickin marked this pull request as ready for review October 27, 2026 11:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

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 review to try again.
5f6780c Draft 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 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