fix(module): use relative tagPriority for inline style tags#6299
fix(module): use relative tagPriority for inline style tags#6299benjamincanac merged 4 commits intonuxt:v4from
tagPriority for inline style tags#6299Conversation
af3ebc6 to
9d84180
Compare
📝 WalkthroughWalkthroughThis pull request updates Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
The absolute `tagPriority: -2` overrides the CAPO weight entirely, forcing style tags to render before meta tags in `<head>`. This can push SEO/OG meta tags past the 1MB mark that social crawlers parse. Using `'critical'` instead applies a -8 offset to the CAPO weight (60-8=52), keeping these styles first among style tags without jumping ahead of meta tags. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9d84180 to
6a378d4
Compare
tagPriority from style tagstagPriority for inline style tags
commit: |
TypeScript widens `'critical'` to `string` in object literals, which doesn't match the `TagPriority` union type. Adding `as const` preserves the literal type. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
tagPriority for inline style tagstagPriority for inline style tags
There was a problem hiding this comment.
Thanks @harlan-zw! Should we also replace tagPriority: -1 with tagPriority: 'high' across the docs or it doesn't matter?
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/app/plugins/theme.ts (1)
98-118: InconsistenttagPriorityacross inline scripts.The black-as-primary script (lines 98-106) and font restoration script (lines 106-118) do not have
tagPriorityset, while the other four scripts in thisuseHeadcall usetagPriority: 'high'. This inconsistency could lead to unpredictable script ordering in the<head>.For consistent behavior, consider adding
tagPriority: 'high'to these two scripts as well.♻️ Proposed fix to add tagPriority to remaining scripts
} else { document.querySelector('style#nuxt-ui-black-as-primary').innerHTML = ''; } - `.replace(/\s+/g, ' ') + `.replace(/\s+/g, ' '), + type: 'text/javascript', + tagPriority: 'high' }, { innerHTML: [ `if (localStorage.getItem('nuxt-ui-font')) {`, `var font = localStorage.getItem('nuxt-ui-font');`, `document.querySelector('style#nuxt-ui-font').innerHTML = ':root { --font-sans: \\'' + font + '\\', sans-serif; }';`, `if (font !== 'Public Sans') {`, `var lnk = document.createElement('link');`, `lnk.rel = 'stylesheet';`, `lnk.href = 'https://fonts.googleapis.com/css2?family=' + encodeURIComponent(font) + ':wght@400;500;600;700&display=swap';`, `lnk.id = 'font-' + font.toLowerCase().replace(/\\s+/g, '-');`, `document.head.appendChild(lnk);`, `}}` - ].join(' ') + ].join(' '), + type: 'text/javascript', + tagPriority: 'high' }, {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/app/plugins/theme.ts` around lines 98 - 118, The two inline script entries that set/restores theme/font inside the useHead call (the scripts manipulating style#nuxt-ui-black-as-primary and style#nuxt-ui-font / creating link id 'font-...') are missing tagPriority and should be given tagPriority: 'high' to match the other head scripts; update the two script objects (the one whose innerHTML toggles ':root { --ui-primary... }' and the one that reads localStorage 'nuxt-ui-font' and appends the Google Fonts link) to include tagPriority: 'high' so head ordering is consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@docs/app/plugins/theme.ts`:
- Around line 98-118: The two inline script entries that set/restores theme/font
inside the useHead call (the scripts manipulating style#nuxt-ui-black-as-primary
and style#nuxt-ui-font / creating link id 'font-...') are missing tagPriority
and should be given tagPriority: 'high' to match the other head scripts; update
the two script objects (the one whose innerHTML toggles ':root { --ui-primary...
}' and the one that reads localStorage 'nuxt-ui-font' and appends the Google
Fonts link) to include tagPriority: 'high' so head ordering is consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4c568476-b93a-4fb9-95b7-ba6d6319f84d
📒 Files selected for processing (3)
docs/app/plugins/data.tsdocs/app/plugins/theme.tssrc/runtime/plugins/colors.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/runtime/plugins/colors.ts
|
Oh sorry, yes that looks good, thanks for the assist :) |
🔗 Linked issue
Related to unjs/unhead#693
❓ Type of change
📚 Description
The hardcoded
tagPriority: -2on inline<style>tags overrides Unhead's CAPO weight entirely, forcing styles to render before<meta>tags in<head>. On sites with large inline styles (Tailwind, embedded SVGs), this pushes SEO/OG meta tags past the 1MB limit that social crawlers (Facebook, Twitter) parse, breaking OG previews.Replaced with
tagPriority: 'critical'which applies a relative offset (-8) to the natural CAPO style weight (60 - 8 = 52), keeping these CSS variable styles first among style tags without jumping ahead of meta tags.