Skip to content

Fix: Ignore Symbol and Function values in input/textarea elements #33506

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dekalouis
Copy link

@dekalouis dekalouis commented Jun 11, 2025

Summary

This PR fixes an issue where passing Symbol or Function values to input elements and textarea elements causes errors or unwanted behavior.
Fixes #11734

Problem:

  • When a Symbol is passed as value or defaultValue, React attempts to stringify it, which throws a TypeError
  • When a Function is passed, React stringifies it to unwanted representations like "function() { ... }"
  • This can happen accidentally in dynamic applications where data types aren't strictly controlled

Solution:

  • Added shouldIgnoreValue() helper to detect Symbol and Function values
  • These values are now treated as if no value was provided (empty string behavior)
  • Prevents stringification errors while maintaining backward compatibility
  • Follows React's pattern of graceful handling of edge cases

This ensures React doesn't crash or display unwanted content when developers accidentally pass non-string values to form elements.

How did you test this change?

Ran full test suite:

yarn test
# Result: 326 test suites passed, 6762 tests passed
# All existing ReactDOMInput and ReactDOMTextarea tests pass
# Symbol/Function values correctly treated as empty strings

yarn flow dom-node
# No type errors

yarn prettier && yarn linc
# Code formatting and linting passed

- Add shouldIgnoreValue() checks in ReactDOMInput.js and ReactDOMTextarea.js
- Filter out symbols and functions from value and defaultValue props
- Prevents stringification errors and unwanted string representations
- Maintains backward compatibility for all other value types

Fixes facebook#11734
@facebook-github-bot
Copy link

Hi @dekalouis!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign 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 to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

value|defaultValue={Symbol|Function} should be ignored, not stringified
2 participants