Fix component stack depth crashes due to looping setState
This commit is contained in:
parent
c5b6d0bf45
commit
2fd16f441d
1 changed files with 3 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PortaledModal, { ModalProps } from '@/components/elements/Modal';
|
import PortaledModal, { ModalProps } from '@/components/elements/Modal';
|
||||||
import ModalContext, { ModalContextValues } from '@/context/ModalContext';
|
import ModalContext, { ModalContextValues } from '@/context/ModalContext';
|
||||||
|
import isEqual from 'react-fast-compare';
|
||||||
|
|
||||||
export interface AsModalProps {
|
export interface AsModalProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
|
@ -47,13 +48,13 @@ function asModal<P extends {}> (modalProps?: SettableModalProps | ((props: P) =>
|
||||||
/**
|
/**
|
||||||
* @this {React.PureComponent<P & AsModalProps, State>}
|
* @this {React.PureComponent<P & AsModalProps, State>}
|
||||||
*/
|
*/
|
||||||
componentDidUpdate (prevProps: Readonly<P & AsModalProps>) {
|
componentDidUpdate (prevProps: Readonly<P & AsModalProps>, prevState: Readonly<State>) {
|
||||||
if (prevProps.visible && !this.props.visible) {
|
if (prevProps.visible && !this.props.visible) {
|
||||||
this.setState({ visible: false, showSpinnerOverlay: false });
|
this.setState({ visible: false, showSpinnerOverlay: false });
|
||||||
} else if (!prevProps.visible && this.props.visible) {
|
} else if (!prevProps.visible && this.props.visible) {
|
||||||
this.setState({ render: true, visible: true });
|
this.setState({ render: true, visible: true });
|
||||||
}
|
}
|
||||||
if (!this.state.render) {
|
if (!this.state.render && !isEqual(prevState.propOverrides, this.state.propOverrides)) {
|
||||||
this.setState({ propOverrides: {} });
|
this.setState({ propOverrides: {} });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue