Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 packages/unhead/src/client/renderDOMHead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function renderDOMHead<T extends Unhead<any>>(head: T, options: Ren
const count = dupeKeyCounter.get(tag._d!) || 0
const res = {
tag,
id: (count ? `${tag._d}:${count}` : tag._d) || hashTag(tag),
id: (count ? `${tag._d}:${count}` : tag._d) || tag._h!,
shouldRender: true,
}
if (tag._d && isMetaArrayDupeKey(tag._d)) {
Expand Down
6 changes: 4 additions & 2 deletions 6 packages/unhead/src/unhead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
} from './types'
import { createHooks } from 'hookable'
import { isMetaArrayDupeKey, sortTags, tagWeight, UsesMergeStrategy, ValidHeadTags } from './utils'
import { dedupeKey } from './utils/dedupe'
import { dedupeKey, hashTag } from './utils/dedupe'
import { normalizeEntryToTags } from './utils/normalize'

function registerPlugin(head: Unhead<any>, p: HeadPluginInput) {
Expand Down Expand Up @@ -111,6 +111,8 @@ export function createUnhead<T = ResolvableHead>(resolvedOptions: CreateHeadOpti
t._w = tagWeight(head, t)
t._p = (e._i << 10) + i
t._d = dedupeKey(t)
if (!t._d)
t._h = hashTag(t)
return t
})
}
Expand All @@ -120,7 +122,7 @@ export function createUnhead<T = ResolvableHead>(resolvedOptions: CreateHeadOpti
.flatMap(e => (e._tags || []).map(t => ({ ...t, props: { ...t.props } })))
.sort(sortTags)
.reduce((acc, next) => {
const k = String(next._d || next._p)
const k = next._d || next._h!
if (!acc.has(k))
return acc.set(k, next)

Expand Down
1 change: 1 addition & 0 deletions 1 packages/unhead/test/unit/client/promises.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('promises', () => {
},
{
"_d": undefined,
"_h": "script:src:https://example.com/script.js",
"_p": 1025,
"_w": 50,
"props": {
Expand Down
5 changes: 5 additions & 0 deletions 5 packages/unhead/test/unit/client/resolveTags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('resolveTags', () => {
},
{
"_d": undefined,
"_h": "script:src:https://cdn.example.com/script.js",
"_p": 1026,
"_w": 50,
"props": {
Expand Down Expand Up @@ -88,6 +89,7 @@ describe('resolveTags', () => {
},
{
"_d": undefined,
"_h": "link:rel:icon,type:image/x-icon,href:https://cdn.example.com/favicon.ico",
"_p": 1028,
"_w": 100,
"props": {
Expand Down Expand Up @@ -122,6 +124,7 @@ describe('resolveTags', () => {
[
{
"_d": undefined,
"_h": "script:src:https://cdn.example.com/script2.js",
"_p": 2048,
"_w": 50,
"props": {
Expand Down Expand Up @@ -162,6 +165,7 @@ describe('resolveTags', () => {
},
{
"_d": undefined,
"_h": "script:src:https://cdn.example.com/script2.js",
"_p": 1026,
"_w": 50,
"props": {
Expand Down Expand Up @@ -192,6 +196,7 @@ describe('resolveTags', () => {
},
{
"_d": undefined,
"_h": "link:rel:icon,type:image/x-icon,href:https://cdn.example.com/favicon.ico",
"_p": 1028,
"_w": 100,
"props": {
Expand Down
46 changes: 46 additions & 0 deletions 46 packages/unhead/test/unit/e2e/deduping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,52 @@ describe('unhead e2e deduping', () => {



</body></html>"
`)
})

it('duplicate script src and link href across entries', async () => {
const ssrHead = createClientHeadWithContext()
ssrHead.push({
script: [{ src: 'https://example.com/app.js', async: true }],
link: [{ rel: 'stylesheet', href: 'https://example.com/style.css' }],
})
ssrHead.push({
script: [{ src: 'https://example.com/app.js', async: true }],
link: [{ rel: 'stylesheet', href: 'https://example.com/style.css' }],
})

const data = await renderSSRHead(ssrHead)
expect(data.headTags).toMatchInlineSnapshot(`
"<script src="https://example.com/app.js" async></script>
<link rel="stylesheet" href="https://example.com/style.css">"
`)

const dom = useDom(data)
const csrHead = createClientHeadWithContext()
csrHead.push({
script: [{ src: 'https://example.com/app.js', async: true }],
link: [{ rel: 'stylesheet', href: 'https://example.com/style.css' }],
})
csrHead.push({
script: [{ src: 'https://example.com/app.js', async: true }],
link: [{ rel: 'stylesheet', href: 'https://example.com/style.css' }],
})
await renderDOMHead(csrHead, { document: dom.window.document })

expect(dom.serialize()).toMatchInlineSnapshot(`
"<!DOCTYPE html><html><head>
<script src="https://example.com/app.js" async=""></script>
<link rel="stylesheet" href="https://example.com/style.css">
</head>
<body>

<div>
<h1>hello world</h1>
</div>



</body></html>"
`)
})
Expand Down
2 changes: 2 additions & 0 deletions 2 packages/unhead/test/unit/server/tagPriority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('tag priority', () => {
[
{
"_d": undefined,
"_h": "script:src:/very-important-script.js",
"_p": 1024,
"_w": 42,
"props": {
Expand All @@ -35,6 +36,7 @@ describe('tag priority', () => {
},
{
"_d": undefined,
"_h": "script:src:/not-important-script.js",
"_p": 2048,
"_w": 50,
"props": {
Expand Down
1 change: 1 addition & 0 deletions 1 packages/vue/test/unit/promises.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('vue promises', () => {
},
{
"_d": undefined,
"_h": "script:src:https://example.com/script.js",
"_p": 1025,
"_w": 50,
"props": {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.