You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Form input name='nodeName' breaks onSubmit event handling #6284
It happened that I stumbled on following edge case. If you add name='nodeName' attribute to form's input, at some point of React event handling (ChangeEventPlugin.js: shouldUseChangeEvent()) it will call: elem.nodeName && elem.nodeName.toLowerCase(), but coincidentally nodeName property refers to input and invocation fails.
Ah, nice find. The issue is that elem in that code is actually window (or form) at that point and thanks to the magic of named inputs as properties on window, this is screwing up. I wonder if there are other cases like this…
I think the issue occurs as we traverse the DOM hierarchy for the purposes of synthetically bubbling the event. We are hitting the form node, which is the one that has magic expando properties. It's a bit more complicated to identify form nodes when tagName and nodeName can both be overwritten by named inputs.
In shouldUseChangeEvent, we are searching for input and select nodes. Cleanest solution I can think of at the moment is to return false for any node where typeof nodeName !== 'string'. The sucky thing is that this is not a general solution and there are likely other places in the codebase where we're going to need to play whack-a-bug.
Yea, I updated my comment and mentioned the form. Otherwise window properties are due to ids, not name, whereas form properties are there for names. Maybe something with the iframes + debugger screwed me up.
The risk is that we're in an environment that doesn't have the globals we expect. Maybe we read them from window instead & wrap potential problems in canUseDOM checks. We shouldn't hit this path at all in node anyway so I don't think it's a problem in this case, maybe in others.
# error
react-dom.development.js:2586 Uncaught TypeError: elem.nodeName.toLowerCase is not a function
at shouldUseChangeEvent (react-dom.development.js:2586)
at Object.extractEvents (react-dom.development.js:2770)
at extractEvents (react-dom.development.js:1072)
I have found a similar issue with using style as an id in a form element while trying to set inline styles on the form element.
functionApp(){return(<><divstyle={{backgroundColor: 'red'}}><inputid="style"defaultValue="should have a red background"/></div><formstyle={{backgroundColor: 'green'}}><inputid="style"defaultValue="my background wont be green"/></form><formstyle={{backgroundColor: 'blue'}}><inputid="stylez"defaultValue="should have a blue background"/></form></>);}
The middle form can't set it's inline styles because a child element occupies the form property style
Activity
zpao commentedon Mar 21, 2016
Ah, nice find. The issue is that
elemin that code is actuallywindow(orform) at that point and thanks to the magic of named inputs as properties onwindow, this is screwing up. I wonder if there are other cases like this…jimfb commentedon Mar 21, 2016
@zpao That was my first thought too, in which case we could special-case window, but I don't think that's quite right.
I think the issue occurs as we traverse the DOM hierarchy for the purposes of synthetically bubbling the event. We are hitting the
formnode, which is the one that has magic expando properties. It's a bit more complicated to identify form nodes whentagNameandnodeNamecan both be overwritten by named inputs.In
shouldUseChangeEvent, we are searching forinputandselectnodes. Cleanest solution I can think of at the moment is to return false for any node wheretypeof nodeName !== 'string'. The sucky thing is that this is not a general solution and there are likely other places in the codebase where we're going to need to play whack-a-bug.zpao commentedon Mar 21, 2016
Yea, I updated my comment and mentioned the form. Otherwise window properties are due to ids, not name, whereas form properties are there for names. Maybe something with the iframes + debugger screwed me up.
zpao commentedon Mar 21, 2016
So what we could do is instead of ever checking nodeName is do
instanceofchecks. So this code would becomeThe risk is that we're in an environment that doesn't have the globals we expect. Maybe we read them from
windowinstead & wrap potential problems in canUseDOM checks. We shouldn't hit this path at all in node anyway so I don't think it's a problem in this case, maybe in others.benjycui commentedon Sep 9, 2016
The following code will cause the same error:
It seems that jQuery had met the same issue and fixed, see: http://stackoverflow.com/questions/17329025/is-id-nodename-reserved-in-html5
shaozj commentedon Jul 5, 2017
I write this code:
run the code on chrome,
output: TypeError: (var).nodeName.toLowerCase is not a function
at :5:9
I think this is a browser bug.
nanjixiong218 commentedon Aug 22, 2017
it maybe a bug of chrome. the input has the id or name of 'nodeName' will override the nodeName of parent form.
but it won't affect the render of page。
but in react, if the outermost layer element is the form, react will check the nodeName ,so will throw error:
fritx commentedon May 3, 2018
+1, same problem here.
cc
@dvajs, @ant-design, @sorryccrelated: ant-design/ant-design#2950, ant-design/ant-design#2103
Workaround: avoid naming with the keyword
nodeNamedustinmoorenet commentedon Apr 16, 2020
I have found a similar issue with using
styleas anidin a form element while trying to set inline styles on the form element.The middle form can't set it's inline styles because a child element occupies the form property
style