Skip to content

Commit

Permalink
Merge branch 'canary' into chore/add-return-types
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jan 3, 2021
2 parents 66eef20 + 98752eb commit f75b35e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/api-reference/next/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default Home
- [`replace`](#replace-the-url-instead-of-push) - Replace the current `history` state instead of adding a new url into the stack. Defaults to `false`
- [`scroll`](#disable-scrolling-to-the-top-of-the-page) - Scroll to the top of the page after a navigation. Defaults to `true`
- [`shallow`](/docs/routing/shallow-routing.md) - Update the path of the current page without rerunning [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation), [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering) or [`getInitialProps`](/docs/api-reference/data-fetching/getInitialProps.md). Defaults to `false`
- `locale` - The active locale is automatically prepended. `locale` allows for providing a different locale. When `false` `href` has to include the locale as the default behavior is disabled.

## If the route has dynamic segments

Expand Down
4 changes: 3 additions & 1 deletion packages/next/next-server/lib/head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ function unique() {

return (h: React.ReactElement<any>) => {
let isUnique = true
let hasKey = false

if (h.key && typeof h.key !== 'number' && h.key.indexOf('$') > 0) {
hasKey = true
const key = h.key.slice(h.key.indexOf('$') + 1)
if (keys.has(key)) {
isUnique = false
Expand Down Expand Up @@ -96,7 +98,7 @@ function unique() {
} else {
const category = h.props[metatype]
const categories = metaCategories[metatype] || new Set()
if (categories.has(category)) {
if ((metatype !== 'name' || !hasKey) && categories.has(category)) {
isUnique = false
} else {
categories.add(category)
Expand Down
15 changes: 13 additions & 2 deletions test/integration/client-navigation/pages/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,28 @@ export default () => (
<meta property="fb:pages" content="fbpages1" />
<meta property="fb:pages" content="fbpages2" />

{/* both meta tags will be rendered since they use unique keys */}
<meta
name="citation_author"
content="authorName1"
key="citationAuthorTag1"
/>
<meta
name="citation_author"
content="authorName2"
key="citationAuthorTag2"
/>

<React.Fragment>
<title>Fragment title</title>
<meta content="meta fragment" />
</React.Fragment>

{/* the following 2 links tag will be rendered both */}
{/* the following 2 link tags will both be rendered */}
<link rel="stylesheet" href="/dup-style.css" />
<link rel="stylesheet" href="/dup-style.css" />

{/* only one tag will be rendered as they have the same key */}

<link rel="stylesheet" href="dedupe-style.css" key="my-style" />
<link rel="stylesheet" href="dedupe-style.css" key="my-style" />

Expand Down
10 changes: 10 additions & 0 deletions test/integration/client-navigation/test/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ export default function (render, fetch, ctx) {
expect(html).toContain('<meta property="fb:pages" content="fbpages2"/>')
})

test('header helper avoids dedupe of meta tags with the same name if they use unique keys', async () => {
const html = await render('/head')
expect(html).toContain(
'<meta name="citation_author" content="authorName1"/>'
)
expect(html).toContain(
'<meta name="citation_author" content="authorName2"/>'
)
})

test('header helper renders Fragment children', async () => {
const html = await render('/head')
expect(html).toContain('<title>Fragment title</title>')
Expand Down

0 comments on commit f75b35e

Please sign in to comment.