Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-dom-bindings/src/client/ToStringValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ export function getToStringValue(value: mixed): ToStringValue {
// function, symbol are assigned as empty strings
return '';
}
}
}
28 changes: 28 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3109,4 +3109,32 @@ describe('ReactDOMInput', () => {
expect(log).toEqual(['']);
expect(node.value).toBe('a');
});
// Remove your custom warning tests (they're not needed since React already warns)
// Keep the existing Symbol/Function value tests but update the assertions:

it('treats initial Symbol value as an empty string', async () => {
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(<input value={Symbol('test')} />);
});
assertConsoleErrorDev([
'Invalid value for prop `value` on <input> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM. For details, see https://react.dev/link/attribute-behavior \n in input (at **)',
'You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.\n in input (at **)',
]);
expect(container.firstChild.value).toBe('');
});

it('treats initial function value as an empty string', async () => {
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(<input value={() => {}} />);
});
assertConsoleErrorDev([
'Invalid value for prop `value` on <input> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM. For details, see https://react.dev/link/attribute-behavior \n in input (at **)',
'You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.\n in input (at **)',
]);
expect(container.firstChild.value).toBe('');
});
});