Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(react): force invalidation on entry disposal#559

Merged
harlan-zw merged 1 commit into
mainfrom
fix/entry-disposal-invalidation
Jul 4, 2025
Merged

fix(react): force invalidation on entry disposal#559
harlan-zw merged 1 commit into
mainfrom
fix/entry-disposal-invalidation

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Jul 4, 2025

Copy link
Copy Markdown
Collaborator

πŸ”— Linked issue

#558

Maybe #530

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

There's two issues relating to this bug:

  1. In the React logic for managing the entry we're using useState, when we run React in strict mode it re-renders the component immediately which causes duplicate entries to be created. Using useRef doesn't have this same issue so we use that.
  2. The timing of when React is triggering Unhead internals is causing an issue where the disposal of an entry isn't invalidating the resolved tags, to work around this we have to explicitly invalidate all tags when we remove one, not ideal but it seems to solve the issue.
Time: 0ms - Application Start
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ head.entries Map: [1] β†’ Init Entry                 β”‚
β”‚ normalizeQueue: [1]                                 β”‚
β”‚ DOM: <title>Default Title</title>                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Time: 100ms - Component Mounts
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ head.entries Map: [1] β†’ Init, [2] β†’ Component       β”‚
β”‚ normalizeQueue: [1, 2]                              β”‚
β”‚ DOM: <title>Component Title</title>                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Time: 200ms - Component Unmounts (BUG OCCURS)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ head.entries Map: [1] β†’ Init Entry                 β”‚
β”‚ normalizeQueue: [] ← ❌ EMPTY! Entry 1 not queued   β”‚
β”‚ DOM: <title>Component Title</title> ← ❌ STALE!     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Expected After Fix:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ head.entries Map: [1] β†’ Init Entry                 β”‚
β”‚ normalizeQueue: [1] ← βœ… Init entry queued         β”‚
β”‚ DOM: <title>Default Title</title> ← βœ… RESTORED     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

@github-actions

github-actions Bot commented Jul 4, 2025

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Size Gzipped Size Size Diff Gzipped Size Diff
Client 11 kB (11266 B) 4.6 kB (4687 B) 1.19% (132 B) 0.86% ( 40 B)
Server 8.2 kB (8444 B) 3.5 kB (3569 B) 1.59% (132 B) 1.08% ( 38 B)

@harlan-zw harlan-zw merged commit 4ee5eac into main Jul 4, 2025
5 checks passed
@harlan-zw harlan-zw mentioned this pull request Apr 4, 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.

1 participant