Improve Symbol/Function error messages for form value props#128
Improve Symbol/Function error messages for form value props#128everettbu wants to merge 4 commits into
Conversation
Greptile OverviewGreptile SummaryEnhanced error messages for Symbol and Function values passed to input Key Issues:
Confidence Score: 3/5
Important Files ChangedFile Analysis
|
| if (name === 'value' || name === 'defaultValue') { | ||
| console.error( | ||
| 'Received a function as a `%s` prop on <%s> tag. ' + | ||
| 'Functions cannot be rendered as text and will be ignored. ' + | ||
| 'If you meant to render the function result, call it first: %s={myFunction()}. ' + | ||
| 'If you meant to pass a function reference, this is not supported for value props. ' + | ||
| 'For details, see https://react.dev/link/attribute-behavior', | ||
| name, | ||
| tagName, | ||
| name, | ||
| ); | ||
| warnedProperties[name] = true; | ||
| return true; |
There was a problem hiding this comment.
logic: checks for name === 'defaultValue' but this code is unreachable for defaultValue because line 180-184 returns true early for defaultValue, preventing this type validation from running
the new error message only works for value prop, not defaultValue (as evidenced by test comments "// TODO: we should warn here." at lines 2944, 2962, 3022, 3041 in the test file)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react-dom-bindings/src/shared/ReactDOMUnknownPropertyHook.js
Line: 274:286
Comment:
**logic:** checks for `name === 'defaultValue'` but this code is unreachable for `defaultValue` because line 180-184 returns `true` early for `defaultValue`, preventing this type validation from running
the new error message only works for `value` prop, not `defaultValue` (as evidenced by test comments "// TODO: we should warn here." at lines 2944, 2962, 3022, 3041 in the test file)
How can I resolve this? If you propose a fix, please make it concise.| if (name === 'value' || name === 'defaultValue') { | ||
| console.error( | ||
| 'Received a Symbol as a `%s` prop on <%s> tag. ' + | ||
| 'Symbols cannot be rendered as text and will be ignored. ' + | ||
| 'If you need to display this value, convert it to a string first with String() or .toString().' + | ||
| '\n\nFor example: %s={String(mySymbol)} or %s={mySymbol.toString()}. ' + | ||
| 'For details, see https://react.dev/link/attribute-behavior', | ||
| name, | ||
| tagName, | ||
| name, | ||
| name, | ||
| ); | ||
| warnedProperties[name] = true; | ||
| return true; |
There was a problem hiding this comment.
logic: same issue - checks for name === 'defaultValue' but unreachable for defaultValue due to early return at lines 180-184
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react-dom-bindings/src/shared/ReactDOMUnknownPropertyHook.js
Line: 291:304
Comment:
**logic:** same issue - checks for `name === 'defaultValue'` but unreachable for `defaultValue` due to early return at lines 180-184
How can I resolve this? If you propose a fix, please make it concise.|
Upstream PR was closed or merged. Code is synced via branch mirror. |
Mirror of facebook/react#34205
Original author: Raghuboi
Summary
Improves developer experience when Symbol or Function values are accidentally passed to form element
valueordefaultValueprops. Previously, React showed generic "Invalid value" errors that provided limited guidance. This PR replaces them with specific, actionable error messages.Fixes: React issue #11734
Before:
After (Symbol):
After (Function):
How did you test this change?
Verified existing behavior is preserved:
yarn test ReactDOMInput --no-coverageAll 124 tests pass.
Updated test expectations for new error messages:
ReactDOMInput-test.jsto expect enhanced error messagesValidated code quality standards:
Files changed:
packages/react-dom-bindings/src/shared/ReactDOMUnknownPropertyHook.jspackages/react-dom/src/__tests__/ReactDOMInput-test.jsImpact: Improves developer experience with zero breaking changes to runtime behavior.