-
Notifications
You must be signed in to change notification settings - Fork 47k
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
React DOM crashes when <option> contains three interpolated value if one is a conditional. #11911
Comments
Tagging as good first issue. |
@gaearon i can take this up :) |
* Add some very basic tests to expose the issue * Fix bug caused by facebook/react#11911 * Add more tests and fixes
Could this be related to #11602 ? |
@mannanali413 Any progress? |
@gaearon I experienced this regression myself yesterday when upgrading from 15.4.2 to 16.2.0. Same issue - different error message: I'm not sure if @mannanali413 is still working on a fix for this, but I can take a closer look later today too. To anyone else experiencing this problem, the only workaround I've found so far is to remove the conditional logic (at least until a fix is found). |
@kevinzwhuang Would you like to work on figuring out the fix? |
Sure @gaearon I can work on finding a fix. Did some digging in devtools
What we should be seeing is 4 elements in the childNodes array, instead of a single flattened text element - this might have something to do with #11602 like @jorrit mentioned |
@kevinzwhuang can you make a video or a blog post about how did u solve this issue once u solved this. |
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: @gaearon - I think the solution has something to do with going back to the old behavior of doing |
Sounds good. I really haven't dug into that code but happy to review a PR once you have something that works. |
I think function insertBefore: function (parentInstance, child, beforeChild) {
parentInstance.insertBefore(child, beforeChild);
}, That is correct , if I use insertBefore: function (parentInstance, child, beforeChild) {
parentInstance.insertBefore(child, parentInstance.childNodes[0]);
}, So, in my options, the problem is My solution is // in ReactDOMFiberOption.js file
function flattenChildren(children) {
let content = document.createElement('span');
// Flatten children and warn if they aren't strings or numbers;
// invalid types are ignored.
// We can silently skip them because invalid DOM nesting warning
// catches these cases in Fiber.
React.Children.forEach(children, function(child) {
if (child == null) {
return;
}
if (typeof child === 'string' || typeof child === 'number') {
if (typeof children === 'string') {
content += child;
} else {
if (!content) {
content = document.createElement('span');
}
const textNode = document.createTextNode(child);
content.appendChild(textNode);
}
// content += child;
}
});
return content;
} |
…e if one is a conditional. facebook#11911
@gaearon would you please code review? |
reduce option child
I have the same problem with this code
or
because React try to delete each node from @kevinzwhuang my workaround is to use unique keys |
Got the same issue with |
I'm hitting this too |
@itssumitrai This issue is about @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! |
If someone wants to take another look at #12078 and specifically #12078 (comment) you're most welcome to do it. That will likely lead us closer to fixing this. |
@gaearon Hi Dan! I would like to investigate into this problem and try to help with fix. |
Sounds great! This should be a good starting point: #12078 (comment) |
@gaearon Hi Dan!
I think the easiest solution would be a changing of flattening (or replacing) in a right way. As I get it an By the way, it's cool to dip into react sources :) |
Sounds good to me, wanna try it? |
Yeah, of course! |
I have tried to change flattening, but it didn't fix all problems and became a reason for new issues. |
@gaearon Hi, Dan! |
Fixed by @Slowyn |
* Make option children a text content by default fix #11911 * Apply requested changes - Remove meaningless comments - revert scripts/rollup/results.json * remove empty row * Update comment * Add a simple unit-test * [WIP: no flow] Pass through hostContext * [WIP: no flow] Give better description for test * Fixes * Don't pass hostContext through It ended up being more complicated than I thought. * Also warn on hydration
* Make option children a text content by default fix facebook#11911 * Apply requested changes - Remove meaningless comments - revert scripts/rollup/results.json * remove empty row * Update comment * Add a simple unit-test * [WIP: no flow] Pass through hostContext * [WIP: no flow] Give better description for test * Fixes * Don't pass hostContext through It ended up being more complicated than I thought. * Also warn on hydration
after update 16.13.1 does anyone found any solution ? |
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/
<select>
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
The text was updated successfully, but these errors were encountered: