-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implement meta tag deduplication logic #5676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add logic to determine if meta tags should be deduplicated.
WalkthroughThe change modifies the meta tag deduplication logic in HeadContent.tsx to allow multiple Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 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 |
|
View your CI Pipeline Execution ↗ for commit 893579a
☁️ Nx Cloud last updated this comment at |
More templates
@tanstack/arktype-adapter
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/nitro-v2-vite-plugin
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-ssr-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-server
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-devtools-core
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-ssr-query-core
@tanstack/router-utils
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-router-ssr-query
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-static-server-functions
@tanstack/start-storage-context
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/zod-adapter
commit: |
There was a problem hiding this 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., differentmediaattributes 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
shouldAllowMultipleand 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-colormeta tags with different attributes. The logic flow is:
- Meta tags in
METAS_TO_ALLOW_MULTIPLEskip the deduplication check (line 48 returns false for them)- Other meta tags are deduplicated by name/property as before
- The
uniqByfilter at lines 185-196 removes exact duplicates across all meta tagsThis achieves the goal: multiple
theme-colortags with differentmediaattributes will all render, while identical duplicates are removed.Optional micro-optimization:
Line 52 sets
metaByAttribute[attribute] = trueeven 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
📒 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
Add logic to determine if meta tags should be deduplicated.
Closes #5146
Summary by CodeRabbit