-
Notifications
You must be signed in to change notification settings - Fork 51k
Restore old behavior for empty href props on anchor tags
#28124
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -1508,6 +1508,54 @@ function checkSelectProp(props: any, propName: string) { | |
| } | ||
| } | ||
|
|
||
| function pushStartAnchor( | ||
| target: Array<Chunk | PrecomputedChunk>, | ||
| props: Object, | ||
| ): ReactNodeList { | ||
| target.push(startChunkForTag('a')); | ||
|
|
||
| let children = null; | ||
| let innerHTML = null; | ||
| for (const propKey in props) { | ||
| if (hasOwnProperty.call(props, propKey)) { | ||
| const propValue = props[propKey]; | ||
| if (propValue == null) { | ||
| continue; | ||
| } | ||
| switch (propKey) { | ||
| case 'children': | ||
| children = propValue; | ||
| break; | ||
| case 'dangerouslySetInnerHTML': | ||
| innerHTML = propValue; | ||
| break; | ||
| case 'href': | ||
| if (propValue === '') { | ||
| // Empty `href` is special on anchors so we're short-circuiting here. | ||
| // On other tags it should trigger a warning | ||
| pushStringAttribute(target, 'href', ''); | ||
| } else { | ||
| pushAttribute(target, propKey, propValue); | ||
| } | ||
| break; | ||
| default: | ||
| pushAttribute(target, propKey, propValue); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| target.push(endOfStartTag); | ||
| pushInnerHTML(target, innerHTML, children); | ||
| if (typeof children === 'string') { | ||
| // Special case children as a string to avoid the unnecessary comment. | ||
| // TODO: Remove this special case after the general optimization is in place. | ||
| target.push(stringToChunk(encodeHTMLTextNode(children))); | ||
| return null; | ||
| } | ||
| return children; | ||
| } | ||
|
|
||
| function pushStartSelect( | ||
| target: Array<Chunk | PrecomputedChunk>, | ||
| props: Object, | ||
|
|
@@ -3513,12 +3561,17 @@ export function pushStartInstance( | |
| case 'span': | ||
| case 'svg': | ||
| case 'path': | ||
| case 'a': | ||
| case 'g': | ||
| case 'p': | ||
| case 'li': | ||
| // Fast track very common tags | ||
| break; | ||
| case 'a': | ||
| if (enableFilterEmptyStringAttributesDOM) { | ||
| return pushStartAnchor(target, props); | ||
| } else { | ||
| break; | ||
| } | ||
|
Comment on lines
+3569
to
+3571
Collaborator
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. not sure the ordering was picked with scientific rigor but since a is pretty common maybe put it back where it was and just add the extra break before it?
Collaborator
Author
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. If I put it back up I have to make an additional check that we're dealing with an As far as I can tell, I can only put it before the common group or after but not in between without having an additional check. But then maybe I'm missing some neat tricks with
Collaborator
Author
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.
That was the important bit I missed. |
||
| // Special tags | ||
| case 'select': | ||
| return pushStartSelect(target, props); | ||
|
|
||
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 are we distinguishing href from src in the hydration branch but not here?
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.
Forgot. But
(tag !== 'a' || propKey !== 'href')is not very nice to read so I went with!(tag === 'a' && key === 'href')to match the comment better.