Skip to content

Fix React19Dispatcher html/body attribute handling to be instance-aware#263

Merged
staylor merged 3 commits intov3.0.0from
copilot/sub-pr-260-another-one
Mar 3, 2026
Merged

Fix React19Dispatcher html/body attribute handling to be instance-aware#263
staylor merged 3 commits intov3.0.0from
copilot/sub-pr-260-another-one

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 3, 2026

React19Dispatcher managed html/body attributes globally: componentWillUnmount blindly cleared all managed attributes regardless of other mounted instances, so unmounting an inner <Helmet> would wipe attributes that an outer <Helmet> still owns.

Changes

Instance registry + merged sync (src/React19Dispatcher.tsx)

  • Added module-level react19Instances array tracking all mounted React19Dispatcher instances
  • Added syncAllAttributes() — merges html/body attributes across all registered instances (later-mounted wins on conflicts, matching legacy reducePropsToState semantics), then applies the merged result to the DOM
  • componentDidMount registers the instance and calls syncAllAttributes()
  • componentWillUnmount unregisters first, then calls syncAllAttributes() — remaining instances' attributes are preserved
  • Removed DOM side effects from render() (init() → applyNonHostedAttributes()); deleted both now-dead methods

Multi-instance tests

  • htmlAttributes.test.tsx: inner instance overrides outer on conflicts; unmount of inner restores outer's attrs; non-conflicting attrs from two instances are merged
  • bodyAttributes.test.tsx: same override and restore scenarios for body attributes

Example of the fixed behavior:

// Outer sets lang="en"; inner overrides with lang="ja"
<Helmet htmlAttributes={{ lang: 'en' }} />
<Helmet htmlAttributes={{ lang: 'ja' }} />
// → <html lang="ja">

// After inner unmounts:
// → <html lang="en">  (previously would clear lang entirely)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 3, 2026 11:49
Co-authored-by: staylor <52932+staylor@users.noreply.github.com>
Co-authored-by: staylor <52932+staylor@users.noreply.github.com>
Copilot AI changed the title [WIP] Update to address feedback on v3.0.0 — React 19 support and TypeScript cleanup Fix React19Dispatcher html/body attribute handling to be instance-aware Mar 3, 2026
@staylor staylor marked this pull request as ready for review March 3, 2026 11:52
@staylor staylor merged commit 3493c93 into v3.0.0 Mar 3, 2026
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.

2 participants