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

Skip to content

fix: avoid mutating cached titleTemplate tag in resolveTitleTemplate#715

Merged
harlan-zw merged 1 commit into
mainfrom
perf/incremental-tag-resolution
Apr 5, 2026
Merged

fix: avoid mutating cached titleTemplate tag in resolveTitleTemplate#715
harlan-zw merged 1 commit into
mainfrom
perf/incremental-tag-resolution

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Apr 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • resolveTitleTemplate() was mutating the titleTemplate tag object in-place (tpl.tag = 'title', tpl.textContent = v), which corrupts the entry's _tags cache on subsequent renders. Now creates a new object via spread instead.

This is a correctness fix — the mutation could cause stale titleTemplate data to persist across re-renders when the entry's _tags cache is reused.

Test plan

  • All 1019 tests pass
  • Verify titleTemplate updates correctly across multiple reactive re-renders

🤖 Generated with Claude Code

Summary by CodeRabbit

Bug Fixes

  • Improved title template resolution to prevent unintended mutations of cached objects, enhancing stability and reliability of title tag handling.

@coderabbitai

coderabbitai Bot commented Apr 5, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 64fc60ec-0b7d-4559-8ef9-9d5e7e5a674a

📥 Commits

Reviewing files that changed from the base of the PR and between 94f6dcc and dcc118d.

📒 Files selected for processing (1)
  • packages/unhead/src/utils/resolve.ts

📝 Walkthrough

Walkthrough

The resolveTitleTemplate function was refactored to avoid mutating the cached title template tag object. Instead of directly modifying the original object, it now creates a new entry in ctx.tagMap with a copy of the template, setting the appropriate tag and content values.

Changes

Cohort / File(s) Summary
Title Template Resolution
packages/unhead/src/utils/resolve.ts
Modified resolveTitleTemplate to avoid in-place mutation of cached tag objects by creating a new mapped entry instead of directly assigning properties to the original tag.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A copy, not a change in place,
The template finds its proper space,
No mutations spoil the cached way,
Fresh entries bloom where shadows lay,
Immutability saves the day!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is incomplete. It lacks the required template sections including 'Linked issue' and 'Type of change' checkboxes that are specified in the repository's description template. Add the missing template sections: include a 'Linked issue' section and mark the appropriate 'Type of change' checkbox (e.g., 'Bug fix' for this correctness fix).
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly and accurately summarizes the main change: avoiding mutation of the cached titleTemplate tag in the resolveTitleTemplate function.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/incremental-tag-resolution

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 and usage tips.

@github-actions

github-actions Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Bundle Size Gzipped
Client (Minimal) 10.5 kB 4.3 kB
Server (Minimal) 10.3 kB 4.2 kB
Vue Client (Minimal) 11.4 kB 4.7 kB
Vue Server (Minimal) 11.1 kB 4.6 kB

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.claude/settings.local.json (1)

1-7: Consider whether .local settings should be committed.

Files with .local suffix typically indicate user-specific configurations that shouldn't be version-controlled. If this permission is intended for CI/CD or all developers, consider renaming to .claude/settings.json. Otherwise, consider adding .claude/settings.local.json to .gitignore.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/settings.local.json around lines 1 - 7, This file
.claude/settings.local.json contains a user-specific permission
("permissions.allow" -> "Bash(pnpm test:*)") that likely shouldn’t be committed;
either move the permission into a shared config file (rename to
.claude/settings.json and commit) if it is intended for all developers/CI, or
restore the file to developer-local state and add .claude/settings.local.json to
.gitignore to prevent committing personal settings; update the repository README
or CONTRIBUTING to document where to put shared vs local Claude settings.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.claude/settings.local.json:
- Around line 1-7: This file .claude/settings.local.json contains a
user-specific permission ("permissions.allow" -> "Bash(pnpm test:*)") that
likely shouldn’t be committed; either move the permission into a shared config
file (rename to .claude/settings.json and commit) if it is intended for all
developers/CI, or restore the file to developer-local state and add
.claude/settings.local.json to .gitignore to prevent committing personal
settings; update the repository README or CONTRIBUTING to document where to put
shared vs local Claude settings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0a38caf3-6411-4e77-a80f-8f4b15edafc5

📥 Commits

Reviewing files that changed from the base of the PR and between 125ef67 and 94f6dcc.

📒 Files selected for processing (2)
  • .claude/settings.local.json
  • packages/unhead/src/utils/resolve.ts

resolveTitleTemplate() was mutating the titleTemplate tag in-place
(tpl.tag = 'title', tpl.textContent = v), which corrupts the entry's
_tags cache on subsequent renders. Now creates a new object instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@harlan-zw harlan-zw force-pushed the perf/incremental-tag-resolution branch from 94f6dcc to dcc118d Compare April 5, 2026 15:35
@harlan-zw harlan-zw merged commit 977db36 into main Apr 5, 2026
6 checks passed
@harlan-zw harlan-zw mentioned this pull request Apr 6, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jun 27, 2026
6 tasks
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