Skip to content

Conversation

@juliusmarminge
Copy link
Contributor

@juliusmarminge juliusmarminge commented Oct 28, 2025

Add logic to determine if meta tags should be deduplicated.

Closes #5146

Summary by CodeRabbit

  • Bug Fixes
    • Improved meta tag handling to allow multiple theme-color entries while preserving automatic deduplication for other meta attributes.

Add logic to determine if meta tags should be deduplicated.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 28, 2025

Walkthrough

The change modifies the meta tag deduplication logic in HeadContent.tsx to allow multiple theme-color meta tags instead of replacing them. A new set defines which attributes should allow duplicates, with a helper function determining eligibility for deduplication.

Changes

Cohort / File(s) Summary
Meta tag deduplication logic
packages/react-router/src/HeadContent.tsx
Introduced METAS_TO_ALLOW_MULTIPLE set containing 'theme-color' and shouldDeduplicateMetaTag() helper function. Updated deduplication logic to permit multiple meta tags for attributes in this set while maintaining deduplication for other attributes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Single file with localized changes to an existing deduplication mechanism
  • Straightforward logic: simple set definition and conditional check
  • Well-scoped change with clear intent and minimal side effects

Suggested reviewers

  • birkskyum

Poem

🌈 A coat of many colors now adorns the head,
Theme-color tags bloom where once just one spread,
Light and dark hues dance side by side,
Multiple shades, no longer cast aside! 🎨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Implement meta tag deduplication logic" directly and clearly describes the main change in the pull request. The raw summary confirms that the changes introduce meta tag deduplication logic with a METAS_TO_ALLOW_MULTIPLE set and shouldDeduplicateMetaTag helper function. The title is concise, specific, and accurately conveys the primary modification to the codebase.
Linked Issues Check ✅ Passed The PR directly addresses the requirement from issue #5146, which requests the ability to include multiple meta tags with the same name (specifically theme-color with different media attributes). The implementation introduces METAS_TO_ALLOW_MULTIPLE containing 'theme-color' and implements shouldDeduplicateMetaTag logic that permits multiple meta tags for specified attributes, effectively allowing multiple theme-color tags to coexist in the document head instead of being deduplicated. This satisfies the core objective of preserving multiple theme-color meta tags with different media attributes for light/dark color schemes.
Out of Scope Changes Check ✅ Passed All changes in this PR are contained within packages/react-router/src/HeadContent.tsx and are directly related to the scope defined in issue #5146. The modifications include introducing the METAS_TO_ALLOW_MULTIPLE set, adding the shouldDeduplicateMetaTag helper, and updating the meta deduplication logic to selectively allow multiple meta tags for certain attributes. These changes are focused solely on enabling multiple theme-color meta tags and do not introduce any unrelated modifications.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@nx-cloud
Copy link

nx-cloud bot commented Oct 28, 2025

View your CI Pipeline Execution ↗ for commit 893579a

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 9m 1s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 56s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-28 19:32:39 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 28, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5676

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5676

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5676

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5676

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5676

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5676

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5676

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5676

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5676

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5676

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5676

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5676

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5676

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5676

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5676

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5676

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5676

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5676

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5676

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5676

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5676

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5676

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5676

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5676

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5676

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5676

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5676

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5676

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5676

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5676

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5676

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5676

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5676

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5676

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5676

commit: 893579a

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/react-router/src/HeadContent.tsx (2)

7-11: Add documentation to explain the deduplication exemption logic.

The constant and helper function work correctly but lack documentation explaining their purpose. Consider adding JSDoc comments to clarify that certain meta tags (like theme-color) need to allow duplicates when they have different attributes (e.g., different media attributes for light/dark color schemes).

Apply this diff to add documentation:

+/**
+ * Meta tag attributes that should allow multiple instances in the document head.
+ * For example, 'theme-color' can have multiple entries with different media queries
+ * to support light and dark color schemes.
+ */
 const METAS_TO_ALLOW_MULTIPLE = new Set(['theme-color'])

+/**
+ * Determines if a meta tag with the given attribute should be deduplicated.
+ * Returns false for attributes that should allow multiple instances.
+ */
 function shouldDeduplicateMetaTag(attribute: string) {
   return METAS_TO_ALLOW_MULTIPLE.has(attribute) === false
 }

Optional: Consider inverting the logic for clarity.

The double-negative (allow multiple → should NOT deduplicate) can be confusing. You could rename to shouldAllowMultiple and invert the checks, though this is purely a readability preference.


46-54: The deduplication logic correctly allows multiple meta tags for specified attributes.

The implementation correctly handles the requirement to allow multiple theme-color meta tags with different attributes. The logic flow is:

  1. Meta tags in METAS_TO_ALLOW_MULTIPLE skip the deduplication check (line 48 returns false for them)
  2. Other meta tags are deduplicated by name/property as before
  3. The uniqBy filter at lines 185-196 removes exact duplicates across all meta tags

This achieves the goal: multiple theme-color tags with different media attributes will all render, while identical duplicates are removed.

Optional micro-optimization:

Line 52 sets metaByAttribute[attribute] = true even for attributes that allow multiples, where this tracking is unused. You could skip the tracking for these attributes, though the current approach is simpler and the performance impact is negligible:

            if (
              metaByAttribute[attribute] &&
              shouldDeduplicateMetaTag(attribute)
            ) {
              continue
-           } else {
+           } else if (shouldDeduplicateMetaTag(attribute)) {
              metaByAttribute[attribute] = true
            }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e06cfad and 893579a.

📒 Files selected for processing (1)
  • packages/react-router/src/HeadContent.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with extensive type safety across the codebase

Files:

  • packages/react-router/src/HeadContent.tsx
packages/{react-router,solid-router}/**

📄 CodeRabbit inference engine (AGENTS.md)

Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/

Files:

  • packages/react-router/src/HeadContent.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Preview
  • GitHub Check: Test

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.

Set multiple 'theme-color' in head

1 participant