提交 e153bcbb 编写于 作者: D Davor Santic 提交者: Tim Neutkens

next/head allow duplicates if it has uniq keys (#4121)

resolves #4115

For now, I just added `'article:tag'` so it could be duplicated if we need more we have to extend:
```javascript
const ALLOWED_DUPLICATES = ['article:tag']
```
上级 098f3fd7
......@@ -49,9 +49,13 @@ function onStateChange (head) {
}
const METATYPES = ['name', 'httpEquiv', 'charSet', 'itemProp', 'property']
const ALLOWED_DUPLICATES = ['article:tag']
// returns a function for filtering head child elements
// which shouldn't be duplicated, like <title/>.
/*
returns a function for filtering head child elements
which shouldn't be duplicated, like <title/>,
except we explicit allow it in ALLOWED_DUPLICATES array
*/
function unique () {
const keys = new Set()
......@@ -81,7 +85,7 @@ function unique () {
} else {
const category = h.props[metatype]
const categories = metaCategories[metatype] || new Set()
if (categories.has(category)) return false
if (categories.has(category) && ALLOWED_DUPLICATES.indexOf(category) === -1) return false
categories.add(category)
metaCategories[metatype] = categories
}
......
......@@ -10,6 +10,12 @@ export default () => <div>
<meta content='my meta' />
{/* allow duplicates for specific tags */}
<meta property='article:tag' content='tag1' key='tag1key' />
<meta property='article:tag' content='tag2' key='tag2key' />
<meta property='dedupe:tag' content='tag3' key='tag3key' />
<meta property='dedupe:tag' content='tag4' key='tag4key' />
<React.Fragment>
<title>Fragment title</title>
<meta content='meta fragment' />
......
......@@ -43,6 +43,14 @@ export default function ({ app }, suiteName, render, fetch) {
expect(html).not.toContain('<link rel="stylesheet" href="dedupe-style.css" class="next-head"/><link rel="stylesheet" href="dedupe-style.css" class="next-head"/>')
})
test('header helper avoids dedupe of specific tags', async () => {
const html = await (render('/head'))
expect(html).toContain('<meta property="article:tag" content="tag1" class="next-head"/>')
expect(html).toContain('<meta property="article:tag" content="tag2" class="next-head"/>')
expect(html).not.toContain('<meta property="dedupe:tag" content="tag3" class="next-head"/>')
expect(html).toContain('<meta property="dedupe:tag" content="tag4" class="next-head"/>')
})
test('header helper renders Fragment children', async () => {
const html = await (render('/head'))
expect(html).toContain('<title class="next-head">Fragment title</title>')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册