Skip to content

Commit

Permalink
Remove wrapperState from select
Browse files Browse the repository at this point in the history
wasMultiple can be derived from props instead
  • Loading branch information
sebmarkbage committed Apr 9, 2023
1 parent 63b40e5 commit 18a5a9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/react-dom-bindings/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
initSelect,
postInitSelect,
restoreControlledSelectState,
postUpdateSelect,
updateSelect,
} from './ReactDOMSelect';
import {
initTextarea,
Expand Down Expand Up @@ -1319,7 +1319,7 @@ export function updateProperties(
}
// <select> value update needs to occur after <option> children
// reconciliation
postUpdateSelect(domElement, nextProps);
updateSelect(domElement, lastProps, nextProps);
return;
}
case 'textarea': {
Expand Down
27 changes: 9 additions & 18 deletions packages/react-dom-bindings/src/client/ReactDOMSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ if (__DEV__) {
didWarnValueDefaultValue = false;
}

type SelectWithWrapperState = HTMLSelectElement & {
_wrapperState: {wasMultiple: boolean},
};

function getDeclarationErrorAddendum() {
const ownerName = getCurrentFiberOwnerNameInDevOrNull();
if (ownerName) {
Expand Down Expand Up @@ -127,16 +123,8 @@ function updateOptions(
*/

export function initSelect(element: Element, props: Object) {
const node = ((element: any): SelectWithWrapperState);
if (__DEV__) {
checkSelectPropTypes(props);
}

node._wrapperState = {
wasMultiple: !!props.multiple,
};

if (__DEV__) {
if (
props.value !== undefined &&
props.defaultValue !== undefined &&
Expand All @@ -155,7 +143,7 @@ export function initSelect(element: Element, props: Object) {
}

export function postInitSelect(element: Element, props: Object) {
const node = ((element: any): SelectWithWrapperState);
const node: HTMLSelectElement = (element: any);
node.multiple = !!props.multiple;
const value = props.value;
if (value != null) {
Expand All @@ -165,10 +153,13 @@ export function postInitSelect(element: Element, props: Object) {
}
}

export function postUpdateSelect(element: Element, props: Object) {
const node = ((element: any): SelectWithWrapperState);
const wasMultiple = node._wrapperState.wasMultiple;
node._wrapperState.wasMultiple = !!props.multiple;
export function updateSelect(
element: Element,
prevProps: Object,
props: Object,
) {
const node: HTMLSelectElement = (element: any);
const wasMultiple = !!prevProps.multiple;

const value = props.value;
if (value != null) {
Expand All @@ -185,7 +176,7 @@ export function postUpdateSelect(element: Element, props: Object) {
}

export function restoreControlledSelectState(element: Element, props: Object) {
const node = ((element: any): SelectWithWrapperState);
const node: HTMLSelectElement = (element: any);
const value = props.value;

if (value != null) {
Expand Down

0 comments on commit 18a5a9f

Please sign in to comment.