react: React DOM crashes when
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
React DOM crashes when <option> contains three interpolated value if one is a conditional.
Reproduction: https://jsfiddle.net/0opjvycp/
- Change the value of the
<select> - React crashes with
NotFoundError: Node was not found
From what I can tell, the conditional value is necessary, and it must be three interpolated values.
What is the expected behavior?
React should not crash.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React DOM 16.2 and 16.0. I think this worked in 15.6 - https://jsfiddle.net/mrwkmuqc/ does not crash
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 26 (9 by maintainers)
Commits related to this issue
- Fix bug caused by https://github.com/facebook/react/issues/11911 — committed to nusmodifications/nusmods by ZhangYiJiang 7 years ago
- Fix filter dropdown crash (#545) * Add some very basic tests to expose the issue * Fix bug caused by https://github.com/facebook/react/issues/11911 * Add more tests and fixes — committed to nusmodifications/nusmods by ZhangYiJiang 7 years ago
- fix: React DOM crashes when <option> contains three interpolated value if one is a conditional. #11911 — committed to stephenkingsley/react by stephenkingsley 6 years ago
- fix: #11911 reduce option child — committed to stephenkingsley/react by stephenkingsley 6 years ago
- Make option children a text content by default fix #11911 — committed to Slowyn/react by Slowyn 6 years ago
- Make option children a text content by default fix #11911 — committed to Slowyn/react by Slowyn 6 years ago
- Fix a crash when using dynamic children in <option> tag (#13261) * Make option children a text content by default fix #11911 * Apply requested changes - Remove meaningless comments - revert... — committed to facebook/react by Slowyn 6 years ago
- Fix a crash when using dynamic children in <option> tag (#13261) * Make option children a text content by default fix #11911 * Apply requested changes - Remove meaningless comments - revert... — committed to segoddnja/react by Slowyn 6 years ago
@gaearon Hi, Dan! I’ve created a PR that solves the issue. I’ve added example into fixtures so it would be easy to test. Let’s discuss this solution 😃
after update 16.13.1 I am getting the same error
does anyone found any solution ?
@gaearon Hi Dan! I would like to investigate into this problem and try to help with fix.
@itssumitrai This issue is about
option. If you have a problem with some other tag please file a new issue with a reproducing example.@dgrcode Knowing that you hit it too doesn’t add anything to this conversation. Comments notify everybody subscribed to this thread so it’s best to avoid commenting if it doesn’t add new info. If you’d like to share more details, or help get it fixed, please let us know!
I have the same problem with this code
or
because React try to delete each node from
option@kevinzwhuang my workaround is to use unique keys https://jsfiddle.net/qkc4eyqe/5/ or https://jsfiddle.net/qkc4eyqe/8/
Getting closer to finding the root of the problem by running this code with v15 - it looks like what changed from 15/stack to 16/fiber for this operation is that: in v15, it would execute
setTextContentto update the<option>text for all cases. in v16, it executesremoveChildorinsertBefore, or whatever variation of the operation where ReactDOM assumes text nodes should be added or removed - when in fact there shouldn’t be more than 1 child node because it’s flattened inReactDOMFiberOption(option text nodes were also flattened before in v15, so flattening might be not the issue here) (whereas this is the normal set of operations for generic components in 15 and 16 because text nodes aren’t flattened in other components)@gaearon - I think the solution has something to do with going back to the old behavior of doing
setTextContentfor<option>updates - I’m not sure yet how to go about doing this yet, but this is a step closer to finding it.@gaearon i can take this up 😃