-
Notifications
You must be signed in to change notification settings - Fork 47.1k
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 a crash when using dynamic children in <option> tag #13261
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
0367120
to
388028e
Compare
'<div> cannot appear as a child of <option>.\n' + | ||
' in div (at **)\n' + | ||
' in option (at **)', | ||
'<div> cannot appear as a child of <option>.\n' + ' in option (at **)', |
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.
This is a behavior change and I'm not sure how to avoid this with this solution. But it's only warning, so shouldn't be critical.
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.
I think this is okay. Particularly since the problem is still identified in the message (even if the nest doesn't show up).
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.
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.
Can you revert scripts/rollup/results.json
?
Other than that, this looks good.
'<div> cannot appear as a child of <option>.\n' + | ||
' in div (at **)\n' + | ||
' in option (at **)', | ||
'<div> cannot appear as a child of <option>.\n' + ' in option (at **)', |
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.
I think this is okay. Particularly since the problem is still identified in the message (even if the nest doesn't show up).
if (__DEV__) { | ||
// We do not have HostContext here | ||
// but we can put some parent information at least | ||
// Also this cause a bit different message than it was previously |
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.
Nit: “a bit different message” would become meaningless after merging this PR. Let’s ensure any comments are helpful to future readers.
- Remove meaningless comments - revert scripts/rollup/results.json
My IDE automatically insert an empty row at the end of file -_- |
} | ||
if (__DEV__) { | ||
// We do not have HostContext here | ||
// but we can put some parent information at least |
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.
Nit: Could you reformat this like:
// We do not have HostContext here, but we can at least
// put some parent information
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.
Does this behavior cause an issue in JSDOM too? I'm curious if the manual fixture could be moved into a unit test.
I can try to write a test. I think It's a case for |
Yep!
…On Thu, Jul 26, 2018, 11:19 AM Konstantin Yakushin ***@***.***> wrote:
I can try to write a test. I think It's a case for DOMSelect-test, right?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#13261 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAkEOLqoQTtDM7zWlvJhVfMKOjkx-dFQks5uKggfgaJpZM4VdHP6>
.
|
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.
I don't understand why "we don't have host context here".
This function is called from getHostProps
which is called from setInitialProperties
which is called from finalizeInitialChildren
which definitely has host context. Pass it through.
@gaearon You are right, I've totally missed it. But after a quick look, it seems that sometimes hostContext is |
Can you push the code that doesn't work so I can take a look? |
Sorry, I wasn't able to push right away. |
@@ -545,6 +545,48 @@ describe('ReactDOMSelect', () => { | |||
expect(node.options[2].selected).toBe(false); // gorilla | |||
}); | |||
|
|||
it('should not fail', () => { |
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.
This is very vague.
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.
Yeah, It's some temporary "name" until we get a full working version.
Going to change it to some concrete form 😄
Have you taken a look on anccestorInfo
in current case?
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.
What about this description: "Options with stateful children; it should change its state properly and shouldn't fail"
What do you think?
Seems like the reason this doesn't work is because the host context we get is from option's parent, not option itself. |
* 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
FYI, I just upgraded React and I suspect this change (or one of the other Despite the HTML
All three of the above worked in 16.4.x, but will render Edit: looks like this was already discussed in #13586 |
This works again in 18 if you specify |
fix #11911
I had to move
validateDOMNesting
into the flattening process so it causes a different warning message. I'm not sure if this is a right approach.The problem
After the investigation, I got that the reason of crash was desynchronization of Fiber and real node.
<option />
flattens its children, while Fiber does not. So we can pass into<option />
an array of children e.g.It flattens to a string
But Fiber keeps links to all children. Let's assume that
null
depends on some state. Fiber will try to update children usinginsertBefore
, but as we don't have a real node in DOM, it caused a runtime error.Solution
<option />
's children should be a string and we have to filter children. The simplest solution was to allow react to set content as a direct text child. It solves the issue and makes a behavior of<option />
like in React v.15... Unfortunately, this solution leads us to skipvalidateDOMNesting
.