Skip to content

Commit 5bb2e39

Browse files
committed
Call toString to safely type string values
1 parent 222b0d9 commit 5bb2e39

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/react-dom/src/client/ReactDOMInput.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export function postMountWrapper(
207207
return;
208208
}
209209

210-
const node: HTMLInputElement = element;
210+
const node = ((element: any): HTMLInputElement);
211211

212212
// Do not assign value if it is already set. This prevents user text input
213213
// from being lost during SSR hydration.
@@ -219,7 +219,7 @@ export function postMountWrapper(
219219
// default value provided by the browser. See: #12872
220220
if (type === 'submit' || type === 'reset') {
221221
if (value !== undefined && value !== null) {
222-
node.setAttribute('value', value);
222+
node.setAttribute('value', toString(value));
223223
}
224224

225225
return;
@@ -229,15 +229,15 @@ export function postMountWrapper(
229229
// potentially avoids a DOM write and prevents Firefox (~60.0.1) from
230230
// prematurely marking required inputs as invalid
231231
if (value !== '') {
232-
node.value = value;
232+
node.value = toString(value);
233233
}
234234
}
235235

236236
if (props.hasOwnProperty('defaultValue')) {
237237
// value must be assigned before defaultValue. This fixes an issue where the
238238
// visually displayed value of date inputs disappears on mobile Safari and Chrome:
239239
// https://github.com/facebook/react/issues/7233
240-
node.defaultValue = getToStringValue(props.defaultValue);
240+
node.defaultValue = toString(getToStringValue(props.defaultValue));
241241
}
242242

243243
if (

0 commit comments

Comments
 (0)