@@ -243,35 +243,36 @@ export function postMountWrapper(
243
243
// Do not assign value if it is already set. This prevents user text input
244
244
// from being lost during SSR hydration.
245
245
if ( props . hasOwnProperty ( 'value' ) || props . hasOwnProperty ( 'defaultValue' ) ) {
246
- const initialValue = node . _wrapperState . initialValue ;
247
- const currentValue = node . value ;
248
- const value = disableInputAttributeSyncing
249
- ? getToStringValue ( props . value )
250
- : initialValue ;
251
246
const type = props . type ;
247
+ const isButton = type === 'submit' || type === 'reset' ;
252
248
253
249
// Avoid setting value attribute on submit/reset inputs as it overrides the
254
250
// default value provided by the browser. See: #12872
255
- if ( type === 'submit' || type === 'reset' ) {
256
- if ( props . value !== undefined && props . value !== null ) {
257
- node . setAttribute ( 'value' , toString ( value ) ) ;
258
- }
259
-
251
+ if ( isButton && ( props . value === undefined || props . value === null ) ) {
260
252
return ;
261
253
}
262
254
255
+ const initialValue = node . _wrapperState . initialValue ;
256
+
263
257
// Do not assign value if it is already set. This prevents user text input
264
258
// from being lost during SSR hydration.
265
259
if ( ! isHydrating ) {
266
- // Do not re-assign the value property if is empty. This
267
- // potentially avoids a DOM write and prevents Firefox (~60.0.1) from
268
- // prematurely marking required inputs as invalid
269
260
if ( disableInputAttributeSyncing ) {
270
261
// When not syncing the value attribute, the value property points
271
262
// directly to the React prop. Only assign it if it exists.
272
263
if ( props . hasOwnProperty ( 'value' ) ) {
273
- if ( value !== currentValue ) {
274
- node . value = toString ( value ) ;
264
+ const value = toString ( getToStringValue ( props . value ) ) ;
265
+
266
+ // Always assign on buttons so that it is possible to assign an
267
+ // empty string to clear button text.
268
+ //
269
+ // Otherwise, do not re-assign the value property if is empty. This
270
+ // potentially avoids a DOM write and prevents Firefox (~60.0.1) from
271
+ // prematurely marking required inputs as invalid. Equality is compared
272
+ // to the current value in case the browser provided value is not an
273
+ // empty string.
274
+ if ( isButton || value !== node . value ) {
275
+ node . value = value ;
275
276
}
276
277
}
277
278
} else {
@@ -281,8 +282,8 @@ export function postMountWrapper(
281
282
// 1. The value React property when present
282
283
// 2. The defaultValue React property when present
283
284
// 3. An empty string
284
- if ( value !== currentValue ) {
285
- node . value = toString ( value ) ;
285
+ if ( initialValue !== node . value ) {
286
+ node . value = toString ( initialValue ) ;
286
287
}
287
288
}
288
289
}
0 commit comments