[Glitch] Replace most unsafe React lifecycle methods

Port 8c772028ac to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
diondiondion
2025-11-25 14:49:45 +01:00
committed by Claire
parent 281d12d5d6
commit 18d46054b5
13 changed files with 35 additions and 34 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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