Skip to content

fix: prevent metadata hoisting in hidden Activity boundaries#720

Open
everettbu wants to merge 1 commit intomainfrom
activity-metadata-hoisting
Open

fix: prevent metadata hoisting in hidden Activity boundaries#720
everettbu wants to merge 1 commit intomainfrom
activity-metadata-hoisting

Conversation

@everettbu
Copy link
Copy Markdown

Mirror of facebook/react#34983
Original author: ronnakamoto


Summary

This fixes #34738

In React 19.2, metadata tags (<title>) are automatically hoisted to the document . However, these tags were incorrectly being hoisted even when inside hidden components, causing the browser's document title to be set by hidden content.

image

This commit fixes the issue by making the hoisting logic Activity-aware:

  1. Check offscreenSubtreeIsHidden before mounting hoistables during the initial commit phase to prevent hoisting in hidden Activities
  2. Add recursivelyMountHoistablesInSubtree() to mount hoistables when an Activity transitions from hidden to visible
  3. Add recursivelyUnmountHoistablesInSubtree() to unmount hoistables when an Activity transitions from visible to hidden

How did you test this change?

Added tests for this as well as tested this on local using the reference code from the link https://github.com/nilshartmann/react-activity-title given in #34738 issue description.

@everettbu everettbu added CLA Signed Resolution: Stale Automatically closed due to inactivity and removed Resolution: Stale Automatically closed due to inactivity labels Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants