Skip to content
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

Skip undefined attribute in Head #9856

Merged
merged 22 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d2e2efb
Fix #8655, skip rendering meta tags with undefined props
lachlanjc Dec 28, 2019
69c19b7
Filter all tags, not just meta
lachlanjc Dec 28, 2019
7a35d88
Only render defined props
lachlanjc Dec 29, 2019
3756877
Merge branch 'canary' into fix-meta-undefined
lachlanjc Dec 29, 2019
c247ee6
Remove filtering of undefined strings
lachlanjc Dec 30, 2019
ef8c6b0
Merge branch 'canary' into fix-meta-undefined
Timer Dec 30, 2019
f317700
Merge branch 'canary' into fix-meta-undefined
ijjk Dec 31, 2019
dfa1a6a
Merge branch 'canary' into fix-meta-undefined
lachlanjc Jan 6, 2020
ec22d86
Replace Object.entries
lachlanjc Jan 6, 2020
08ab007
Remove filtering code
lachlanjc Jan 6, 2020
a77ffeb
Simplify code
lachlanjc Jan 7, 2020
58f1cb1
Merge branch 'canary' into fix-meta-undefined
lachlanjc Jan 7, 2020
f05c2b3
Merge branch 'canary' into fix-meta-undefined
lachlanjc Jan 14, 2020
8050b7c
Merge branch 'canary' into fix-meta-undefined
lachlanjc Jan 31, 2020
69aef18
Add test
lachlanjc Jan 31, 2020
9e4e016
Merge remote-tracking branch 'upstream/canary' into fix-meta-undefined
ijjk Feb 2, 2020
ddbd3c5
Add tests for undefined head prop value and tweak check
ijjk Feb 2, 2020
6cc1c9e
Merge remote-tracking branch 'upstream/canary' into fix-meta-undefined
ijjk Feb 2, 2020
6ed862d
Merge remote-tracking branch 'upstream/canary' into fix-meta-undefined
ijjk Feb 3, 2020
dff4aa5
Update to strip undefined prop values to match react
ijjk Feb 3, 2020
57b7408
Update head.js
Timer Feb 3, 2020
2af71a2
Merge branch 'canary' into fix-meta-undefined
Timer Feb 3, 2020
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
3 changes: 3 additions & 0 deletions packages/next/client/head-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ function reactElementToDOM({ type, props }) {
if (!props.hasOwnProperty(p)) continue
if (p === 'children' || p === 'dangerouslySetInnerHTML') continue

// we don't render undefined props to the DOM
if (props[p] === undefined) continue

const attr = DOMAttributeNames[p] || p.toLowerCase()
el.setAttribute(attr, props[p])
}
Expand Down
3 changes: 3 additions & 0 deletions test/integration/client-navigation/pages/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export default () => (

<meta content="my meta" />

{/* this will not render the content prop */}
<meta name="empty-content" content={undefined} />

{/* allow duplicates for specific tags */}
<meta property="article:tag" content="tag1" key="tag1key" />
<meta property="article:tag" content="tag2" key="tag2key" />
Expand Down
9 changes: 9 additions & 0 deletions test/integration/client-navigation/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,15 @@ describe('Client Navigation', () => {
await browser.close()
})

it('should handle undefined prop in head client-side', async () => {
const browser = await webdriver(context.appPort, '/head')
const value = await browser.eval(
`document.querySelector('meta[name="empty-content"]').hasAttribute('content')`
)

expect(value).toBe(false)
})

renderingSuite(
(p, q) => renderViaHTTP(context.appPort, p, q),
(p, q) => fetchViaHTTP(context.appPort, p, q)
Expand Down
8 changes: 8 additions & 0 deletions test/integration/client-navigation/test/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export default function(render, fetch) {
expect(html.includes('My component!')).toBeTruthy()
})

it('should handle undefined prop in head server-side', async () => {
const html = await render('/head')
const $ = cheerio.load(html)
const value = 'content' in $('meta[name="empty-content"]').attr()

expect(value).toBe(false)
})

test('renders with fragment syntax', async () => {
const html = await render('/fragment-syntax')
expect(html.includes('My component!')).toBeTruthy()
Expand Down