-
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
Show warning on invalid value for option #22841
Show warning on invalid value for option #22841
Conversation
Comparing: 0cc724c...7f88d1c Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
Closes #11734 |
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you! |
Summary
Reference: #11734
if
value= {Symbol | Function}
for an option, we ensure that it is ignored (with a warning displayed in dev) rather than have an error thrown onto the browser. Note that this is specific to SSR.The reason why this occurred is because there was an attempt in converting
value
to a string at line 733, which would then throw if the type ofvalue
was asymbol
orfunction
. So to prevent this from happening, I re-used the functionshouldRemoveAttributeWithWarning
to firstly determine if the value was asymbol
orfunction
(or any other invalid type) before casting this into a string.How did you test this change?
I tested this by setting up a simple react component as shown below, and utilised
ReactDOMServer.renderToString
to render the component and sent this to the client (effectively replicating SSR behaviour).Behaviour if using Main branch (further debug information that is provided as part of the error message has been omitted):
Behaviour with my changes:
Note that I did attempt to write a test (via the file
ReactDOMServerIntegrationSelect-test
) to confirm that the html option object'svalue
property is empty if the developer specifies asymbol
orfunction
type. However, although this test would pass for client-side rendered html elements, this does not pass if rendered server side (even though novalue
attribute is explicitly attached to the option element). If rendered server-side and if the option'svalue
attribute is queried, it looks like the option element will implicitly return its child text element if itsvalue
attribute is empty. So going with the markup above as an example, querying the value for the first option element will return "A" if rendered server side. This does bring to light some very subtle differences in behaviour both server and client-side that I'm not too sure is worth addressing in this PR.Here's the test that I wrote below just as an FYI: