Skip to content

Commit

Permalink
fix(ComboBox): remove flushSync console error for React18 (#3253)
Browse files Browse the repository at this point in the history
  • Loading branch information
JackUait committed Aug 25, 2023
1 parent 54d0349 commit e71cbad
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/react-ui/internal/CustomComboBox/CustomComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export class CustomComboBox<T> extends React.PureComponent<CustomComboBoxProps<T
}

public componentDidMount() {
this.dispatch({ type: 'Mount' });
this.dispatch({ type: 'Mount' }, false);
if (this.props.autoFocus) {
this.focus();
}
Expand All @@ -319,7 +319,7 @@ export class CustomComboBox<T> extends React.PureComponent<CustomComboBoxProps<T
if (prevState.editing && !this.state.editing) {
this.handleBlur();
}
this.dispatch({ type: 'DidUpdate', prevProps, prevState });
this.dispatch({ type: 'DidUpdate', prevProps, prevState }, false);
}

/**
Expand All @@ -329,7 +329,7 @@ export class CustomComboBox<T> extends React.PureComponent<CustomComboBoxProps<T
this.dispatch({ type: 'Reset' });
}

private dispatch = (action: CustomComboBoxAction<T>) => {
private dispatch = (action: CustomComboBoxAction<T>, sync = true) => {
const updateState = (action: CustomComboBoxAction<T>) => {
let effects: Array<CustomComboBoxEffect<T>>;
let nextState: Pick<CustomComboBoxState<T>, never>;
Expand All @@ -348,7 +348,7 @@ export class CustomComboBox<T> extends React.PureComponent<CustomComboBoxProps<T

// Auto-batching React@18 creates problems that are fixed with flushSync
// https://github.com/skbkontur/retail-ui/pull/3144#issuecomment-1535235366
if (React.version.search('18') === 0) {
if (sync && React.version.search('18') === 0) {
ReactDOM.flushSync(() => updateState(action));
} else {
updateState(action);
Expand Down

0 comments on commit e71cbad

Please sign in to comment.