fix(unhead): dispatch tag:normalise hook - #860
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesTag normalisation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
📦 Bundle Size
All bundles (14)
⚡ Performance (directional)✅ No significant change (within CI noise) All benchmarks (14)
Baseline: main @ 3c4f3c0 · 2026-07-19 · gzipped is the headline size metric · perf is directional (shared-runner, gated) |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/unhead/src/utils/resolve.ts (1)
27-29: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueConsider strengthening the cache invalidation hash.
Currently, the cache count is determined by a simple sum of the lengths of the registered hooks. If a listener is added to one hook and another listener is simultaneously removed from a different hook, the sum remains identical, which would fail to invalidate the cache.
While this is likely a rare edge case and follows the pre-existing pattern, you can eliminate this collision risk by using a bit-shift offset for each hook type to ensure a unique signature.
💡 Proposed refactor to use bit-shifting
- const count = (hooks['entries:resolve']?.length || 0) - + (hooks['entries:normalize']?.length || 0) - + (hooks['tag:normalise']?.length || 0) + const count = (hooks['entries:resolve']?.length || 0) + + ((hooks['entries:normalize']?.length || 0) << 10) + + ((hooks['tag:normalise']?.length || 0) << 20)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/unhead/src/utils/resolve.ts` around lines 27 - 29, Strengthen the cache signature calculation in the hook-count logic by assigning each hook type a distinct bit-shifted offset before combining their listener counts. Update the `count` expression for `entries:resolve`, `entries:normalize`, and `tag:normalise` so changes between hook groups cannot produce the same signature.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/unhead/src/utils/resolve.ts`:
- Around line 27-29: Strengthen the cache signature calculation in the
hook-count logic by assigning each hook type a distinct bit-shifted offset
before combining their listener counts. Update the `count` expression for
`entries:resolve`, `entries:normalize`, and `tag:normalise` so changes between
hook groups cannot produce the same signature.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 732fffeb-bf4d-41f2-840a-7e1128917b14
📒 Files selected for processing (2)
packages/unhead/src/utils/resolve.tspackages/unhead/test/unit/hooks/mutating-hooks.test.ts
|
Closing after checking the v4 migration. |
🔗 Linked issue
Related to #822
❓ Type of change
📚 Description
tag:normaliseis part of the public hook API, butresolveTags()never dispatched it. Dispatch the hook before weights and dedupe keys are calculated, then invalidate cached and precomputed tags when hook registrations change.Summary by CodeRabbit
tag:normalisehandling so it runs before tag weighting and deduplication.tag:normalisenow reliably update renderedheadTags, including after the hook is registered post-render and for default/precomputed tags.tag:normaliseordering, cache invalidation on late registration, and mutation of default-derived tags.