Skip to content

Commit 591cc39

Browse files
committed
[switch][checkbox][radio][select][combobox] Add suppressHydrationWarning to hidden inputs
Browser extensions (e.g. Dark Reader) can modify the inline styles of hidden inputs before React hydrates, causing hydration mismatch warnings. This is already handled in Slider, Tabs, and NumberField but was missing from Switch, Checkbox, Radio, Select, and Combobox.
1 parent 3c3bd71 commit 591cc39

7 files changed

Lines changed: 7 additions & 4 deletions

File tree

packages/react/src/checkbox/root/CheckboxRoot.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ export const CheckboxRoot = React.forwardRef(function CheckboxRoot(
360360
{!checked && !groupContext && name && !parent && uncheckedValue !== undefined && (
361361
<input type="hidden" form={form} name={name} value={uncheckedValue} />
362362
)}
363-
<input {...inputProps} />
363+
<input {...inputProps} suppressHydrationWarning />
364364
</CheckboxRootContext.Provider>
365365
);
366366
});

packages/react/src/combobox/root/AriaCombobox.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,7 @@ export function AriaCombobox<Value = any, Mode extends SelectionMode = 'none'>(
12801280
style={hiddenInputName ? visuallyHiddenInput : visuallyHidden}
12811281
tabIndex={-1}
12821282
aria-hidden
1283+
suppressHydrationWarning
12831284
/>
12841285
{hiddenInputs}
12851286
</React.Fragment>

packages/react/src/number-field/root/NumberFieldRoot.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ export const NumberFieldRoot = React.forwardRef(function NumberFieldRoot(
499499
aria-hidden
500500
tabIndex={-1}
501501
style={name ? visuallyHiddenInput : visuallyHidden}
502+
suppressHydrationWarning
502503
/>
503504
</NumberFieldRootContext.Provider>
504505
);

packages/react/src/radio/root/RadioRoot.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export const RadioRoot = React.forwardRef(function RadioRoot<Value>(
271271
) : (
272272
element
273273
)}
274-
<input {...inputProps} />
274+
<input {...inputProps} suppressHydrationWarning />
275275
</RadioRootContext.Provider>
276276
);
277277
}) as {

packages/react/src/select/root/SelectRoot.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ export function SelectRoot<Value, Multiple extends boolean | undefined = false>(
580580
style={name ? visuallyHiddenInput : visuallyHidden}
581581
tabIndex={-1}
582582
aria-hidden
583+
suppressHydrationWarning
583584
/>
584585
{hiddenInputs}
585586
</SelectFloatingContext.Provider>

packages/react/src/slider/thumb/SliderThumb.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export const SliderThumb = React.forwardRef(function SliderThumb(
475475
children: (
476476
<React.Fragment>
477477
{childrenProp}
478-
<input ref={mergedInputRef} {...inputProps} />
478+
<input ref={mergedInputRef} {...inputProps} suppressHydrationWarning />
479479
{inset &&
480480
!isMounted &&
481481
renderBeforeHydration &&

packages/react/src/switch/root/SwitchRoot.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export const SwitchRoot = React.forwardRef(function SwitchRoot(
261261
{!checked && name && uncheckedValue !== undefined && (
262262
<input type="hidden" form={form} name={name} value={uncheckedValue} />
263263
)}
264-
<input {...inputProps} />
264+
<input {...inputProps} suppressHydrationWarning />
265265
</SwitchRootContext.Provider>
266266
);
267267
});

0 commit comments

Comments
 (0)