-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Fix false positive hydration warning for SVG attributes #10676
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -776,6 +776,7 @@ var ReactDOMFiberComponent = { | |
domElement: Element, | ||
tag: string, | ||
rawProps: Object, | ||
parentNamespace: string, | ||
rootContainerElement: Element | Document, | ||
): null | Array<mixed> { | ||
if (__DEV__) { | ||
|
@@ -912,6 +913,8 @@ var ReactDOMFiberComponent = { | |
case 'selected': | ||
break; | ||
default: | ||
// Intentionally use the original name. | ||
// See discussion in https://github.com/facebook/react/pull/10676. | ||
extraAttributeNames.add(attributes[i].name); | ||
} | ||
} | ||
|
@@ -1007,8 +1010,17 @@ var ReactDOMFiberComponent = { | |
nextProp, | ||
); | ||
} else { | ||
// $FlowFixMe - Should be inferred as not undefined. | ||
extraAttributeNames.delete(propKey.toLowerCase()); | ||
let ownNamespace = parentNamespace; | ||
if (ownNamespace === HTML_NAMESPACE) { | ||
ownNamespace = getIntrinsicNamespace(tag); | ||
} | ||
if (ownNamespace === HTML_NAMESPACE) { | ||
// $FlowFixMe - Should be inferred as not undefined. | ||
extraAttributeNames.delete(propKey.toLowerCase()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it's worth adding a comment for why we need to downcase the propKey (because HTML reports lowercase, right?) |
||
} else { | ||
// $FlowFixMe - Should be inferred as not undefined. | ||
extraAttributeNames.delete(propKey); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This made me realize that we probably don't validate that two components with the same name but different namespaces line up in the hydration. I'm not sure there's a way to get that wrong in another way than innerHTML SVG content in a HTML root. |
||
serverValue = DOMPropertyOperations.getValueForAttribute( | ||
domElement, | ||
propKey, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1325,19 +1325,30 @@ describe('ReactDOMServerIntegration', () => { | |
expect(e.namespaceURI).toBe('http://www.w3.org/2000/svg'); | ||
}); | ||
|
||
itRenders('svg child element', async render => { | ||
let e = await render( | ||
<svg><image xlinkHref="http://i.imgur.com/w7GCRPb.png" /></svg>, | ||
); | ||
e = e.firstChild; | ||
itRenders('svg child element with an attribute', async render => { | ||
let e = await render(<svg viewBox="0 0 0 0" />); | ||
expect(e.childNodes.length).toBe(0); | ||
expect(e.tagName).toBe('image'); | ||
expect(e.tagName).toBe('svg'); | ||
expect(e.namespaceURI).toBe('http://www.w3.org/2000/svg'); | ||
expect(e.getAttributeNS('http://www.w3.org/1999/xlink', 'href')).toBe( | ||
'http://i.imgur.com/w7GCRPb.png', | ||
); | ||
expect(e.getAttribute('viewBox')).toBe('0 0 0 0'); | ||
}); | ||
|
||
itRenders( | ||
'svg child element with a namespace attribute', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an old test. I just renamed it and moved down. |
||
async render => { | ||
let e = await render( | ||
<svg><image xlinkHref="http://i.imgur.com/w7GCRPb.png" /></svg>, | ||
); | ||
e = e.firstChild; | ||
expect(e.childNodes.length).toBe(0); | ||
expect(e.tagName).toBe('image'); | ||
expect(e.namespaceURI).toBe('http://www.w3.org/2000/svg'); | ||
expect(e.getAttributeNS('http://www.w3.org/1999/xlink', 'href')).toBe( | ||
'http://i.imgur.com/w7GCRPb.png', | ||
); | ||
}, | ||
); | ||
|
||
itRenders('svg child element with a badly cased alias', async render => { | ||
let e = await render( | ||
<svg><image xlinkhref="http://i.imgur.com/w7GCRPb.png" /></svg>, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why rename
parentNamespace
toownNamespace
here instead of usingparentNamespace
directly or settingownNamespace
as the argument?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disregard. Sorry I didn't catch the code below.