Replace most unsafe React lifecycle methods (#36970)

This commit is contained in:
diondiondion 2025-11-25 14:49:45 +01:00 committed by GitHub
parent 861625fdca
commit 8c772028ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 35 additions and 32 deletions

View File

@ -159,8 +159,8 @@ export default class AutosuggestInput extends ImmutablePureComponent {
this.input.focus();
};
UNSAFE_componentWillReceiveProps (nextProps) {
if (nextProps.suggestions !== this.props.suggestions && nextProps.suggestions.size > 0 && this.state.suggestionsHidden && this.state.focused) {
componentDidUpdate (prevProps) {
if (prevProps.suggestions !== this.props.suggestions && this.props.suggestions.size > 0 && this.state.suggestionsHidden && this.state.focused) {
this.setState({ suggestionsHidden: false });
}
}

View File

@ -242,11 +242,11 @@ class MediaGallery extends PureComponent {
window.removeEventListener('resize', this.handleResize);
}
UNSAFE_componentWillReceiveProps (nextProps) {
if (!is(nextProps.media, this.props.media) && nextProps.visible === undefined) {
this.setState({ visible: displayMedia !== 'hide_all' && !nextProps.sensitive || displayMedia === 'show_all' });
} else if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) {
this.setState({ visible: nextProps.visible });
componentDidUpdate (prevProps) {
if (!is(prevProps.media, this.props.media) && this.props.visible === undefined) {
this.setState({ visible: displayMedia !== 'hide_all' && !this.props.sensitive || displayMedia === 'show_all' });
} else if (!is(prevProps.visible, this.props.visible) && this.props.visible !== undefined) {
this.setState({ visible: this.props.visible });
}
}

View File

@ -61,14 +61,6 @@ class ModalRoot extends PureComponent {
this.history = this.props.history || createBrowserHistory();
}
UNSAFE_componentWillReceiveProps (nextProps) {
if (!!nextProps.children && !this.props.children) {
this.activeElement = document.activeElement;
this.getSiblings().forEach(sibling => sibling.setAttribute('inert', true));
}
}
componentDidUpdate (prevProps) {
if (!this.props.children && !!prevProps.children) {
this.getSiblings().forEach(sibling => sibling.removeAttribute('inert'));
@ -85,9 +77,15 @@ class ModalRoot extends PureComponent {
this._handleModalClose();
}
if (this.props.children && !prevProps.children) {
this.activeElement = document.activeElement;
this.getSiblings().forEach(sibling => sibling.setAttribute('inert', true));
this._handleModalOpen();
}
if (this.props.children) {
this._ensureHistoryBuffer();
}

View File

@ -38,7 +38,7 @@ class Blocks extends ImmutablePureComponent {
multiColumn: PropTypes.bool,
};
UNSAFE_componentWillMount () {
componentDidMount () {
this.props.dispatch(fetchBlocks());
}

View File

@ -61,8 +61,14 @@ class ModifierPickerMenu extends PureComponent {
this.props.onSelect(e.currentTarget.getAttribute('data-index') * 1);
};
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.active) {
componentDidMount() {
if (this.props.active) {
this.attachListeners();
}
}
componentDidUpdate() {
if (this.props.active) {
this.attachListeners();
} else {
this.removeListeners();

View File

@ -41,7 +41,7 @@ class Favourites extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};
UNSAFE_componentWillMount () {
componentDidMount () {
if (!this.props.accountIds) {
this.props.dispatch(fetchFavourites(this.props.params.statusId));
}

View File

@ -45,7 +45,7 @@ class FollowRequests extends ImmutablePureComponent {
multiColumn: PropTypes.bool,
};
UNSAFE_componentWillMount () {
componentDidMount () {
this.props.dispatch(fetchFollowRequests());
}

View File

@ -73,11 +73,10 @@ class ListTimeline extends PureComponent {
this.disconnect = dispatch(connectListStream(id));
}
UNSAFE_componentWillReceiveProps (nextProps) {
const { dispatch } = this.props;
const { id } = nextProps.params;
componentDidUpdate (prevProps) {
const { dispatch, params: {id} } = this.props;
if (id !== this.props.params.id) {
if (id !== prevProps.params.id) {
if (this.disconnect) {
this.disconnect();
this.disconnect = null;

View File

@ -40,7 +40,7 @@ class Mutes extends ImmutablePureComponent {
multiColumn: PropTypes.bool,
};
UNSAFE_componentWillMount () {
componentDidMount () {
this.props.dispatch(fetchMutes());
}

View File

@ -34,7 +34,7 @@ class PinnedStatuses extends ImmutablePureComponent {
multiColumn: PropTypes.bool,
};
UNSAFE_componentWillMount () {
componentDidMount () {
this.props.dispatch(fetchPinnedStatuses());
}

View File

@ -42,7 +42,7 @@ class Reblogs extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};
UNSAFE_componentWillMount () {
componentDidMount () {
if (!this.props.accountIds) {
this.props.dispatch(fetchReblogs(this.props.params.statusId));
}

View File

@ -33,13 +33,13 @@ class Bundle extends PureComponent {
forceRender: false,
};
UNSAFE_componentWillMount() {
componentDidMount() {
this.load(this.props);
}
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.fetchComponent !== this.props.fetchComponent) {
this.load(nextProps);
componentDidUpdate(prevProps) {
if (prevProps.fetchComponent !== this.props.fetchComponent) {
this.load(this.props);
}
}

View File

@ -108,7 +108,7 @@ class SwitchingColumnsArea extends PureComponent {
forceOnboarding: PropTypes.bool,
};
UNSAFE_componentWillMount () {
componentDidMount () {
document.body.classList.toggle('layout-single-column', this.props.singleColumn);
document.body.classList.toggle('layout-multiple-columns', !this.props.singleColumn);
}