Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiIcon] Fix setState errors when in React.StrictMode #5899

Merged
merged 5 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -588,23 +588,31 @@ export class EuiIcon extends PureComponent<EuiIconProps, State> {

const { type } = props;
const initialIcon = getInitialIcon(type);
let isLoading = false;

if (isEuiIconType(type) && initialIcon == null) {
isLoading = true;
this.loadIconComponent(type);
} else {
this.onIconLoad();
}

this.state = {
icon: initialIcon,
iconTitle: undefined,
isLoading,
neededLoading: isLoading,
isLoading: false,
neededLoading: false,
};
}

componentDidMount() {
const { type } = this.props;

if (isEuiIconType(type) && this.state.icon == null) {
//eslint-disable-next-line react/no-did-mount-set-state
this.setState({
neededLoading: true,
isLoading: true,
});

this.loadIconComponent(type);
} else {
this.onIconLoad();
}
}

componentDidUpdate(prevProps: EuiIconProps) {
const { type } = this.props;
if (type !== prevProps.type) {
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/5899.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Fixed `EuiIcon` from producing console warning in `React.StrictMode`