Skip to content

Commit 2418f24

Browse files
authored
Fix <select> check of defaultValue/value type (#21611)
1 parent 154a8cf commit 2418f24

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

packages/react-dom/src/server/ReactDOMServerFormatConfig.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -568,19 +568,22 @@ let didWarnSelectedSetOnOption = false;
568568

569569
function checkSelectProp(props, propName) {
570570
if (__DEV__) {
571-
const array = isArray(props[propName]);
572-
if (props.multiple && !array) {
573-
console.error(
574-
'The `%s` prop supplied to <select> must be an array if ' +
575-
'`multiple` is true.',
576-
propName,
577-
);
578-
} else if (!props.multiple && array) {
579-
console.error(
580-
'The `%s` prop supplied to <select> must be a scalar ' +
581-
'value if `multiple` is false.',
582-
propName,
583-
);
571+
const value = props[propName];
572+
if (value != null) {
573+
const array = isArray(value);
574+
if (props.multiple && !array) {
575+
console.error(
576+
'The `%s` prop supplied to <select> must be an array if ' +
577+
'`multiple` is true.',
578+
propName,
579+
);
580+
} else if (!props.multiple && array) {
581+
console.error(
582+
'The `%s` prop supplied to <select> must be a scalar ' +
583+
'value if `multiple` is false.',
584+
propName,
585+
);
586+
}
584587
}
585588
}
586589
}

0 commit comments

Comments
 (0)