mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-04 17:04:59 +03:00
Cleared timeouts in App on unmount
no issue - Clears any timeout on unmount in main App and components to avoid unexpected unmount behaviors
This commit is contained in:
parent
5cb1f02109
commit
965959c964
@ -19,8 +19,11 @@ const DEV_MODE_DATA = {
|
||||
export default class App extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
// Setup custom trigger button handling
|
||||
this.setupCustomTriggerButton();
|
||||
|
||||
if (!props.testState) {
|
||||
// Setup custom trigger button handling
|
||||
this.setupCustomTriggerButton();
|
||||
}
|
||||
|
||||
// testState is used by App.test to pass custom default state for testing
|
||||
this.state = props.testState || {
|
||||
@ -35,7 +38,9 @@ export default class App extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.initSetup();
|
||||
if (!this.props.testState) {
|
||||
this.initSetup();
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
@ -45,7 +50,8 @@ export default class App extends React.Component {
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.customTriggerButtons.forEach((customTriggerButton) => {
|
||||
clearTimeout(this.timeoutId);
|
||||
this.customTriggerButtons && this.customTriggerButtons.forEach((customTriggerButton) => {
|
||||
customTriggerButton.removeEventListener('click', this.clickHandler);
|
||||
});
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import App from './App';
|
||||
const setup = (overrides) => {
|
||||
const testState = {
|
||||
site,
|
||||
member: member.free,
|
||||
member: null,
|
||||
action: 'init:success',
|
||||
brandColor: site.accent_color,
|
||||
page: 'signup',
|
||||
|
@ -76,6 +76,10 @@ class NotificationContent extends React.Component {
|
||||
};
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
clearTimeout(this.timeoutId);
|
||||
}
|
||||
|
||||
onNotificationClose() {
|
||||
this.props.onHideNotification();
|
||||
}
|
||||
@ -97,7 +101,7 @@ class NotificationContent extends React.Component {
|
||||
className: 'slideout'
|
||||
});
|
||||
} else if (autoHide) {
|
||||
setTimeout(() => {
|
||||
this.timeoutId = setTimeout(() => {
|
||||
this.setState({
|
||||
className: 'slideout'
|
||||
});
|
||||
|
@ -251,6 +251,10 @@ export default class AccountPlanPage extends React.Component {
|
||||
this.state = this.getInitialState();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
clearTimeout(this.timeoutId);
|
||||
}
|
||||
|
||||
getInitialState() {
|
||||
const {member, site} = this.context;
|
||||
this.plans = getSitePlans({site, includeFree: false});
|
||||
@ -309,7 +313,7 @@ export default class AccountPlanPage extends React.Component {
|
||||
// Work as checkboxes for free member plan selection and button for paid members
|
||||
if (!isPaidMember({member})) {
|
||||
// Hack: React checkbox gets out of sync with dom state with instant update
|
||||
setTimeout(() => {
|
||||
this.timeoutId = setTimeout(() => {
|
||||
this.setState((state) => {
|
||||
return {
|
||||
selectedPlan: name
|
||||
|
@ -148,6 +148,10 @@ class SignupPage extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
clearTimeout(this.timeoutId);
|
||||
}
|
||||
|
||||
handleSignup(e) {
|
||||
e.preventDefault();
|
||||
this.setState((state) => {
|
||||
@ -190,7 +194,7 @@ class SignupPage extends React.Component {
|
||||
handleSelectPlan(e, name) {
|
||||
e.preventDefault();
|
||||
// Hack: React checkbox gets out of sync with dom state with instant update
|
||||
setTimeout(() => {
|
||||
this.timeoutId = setTimeout(() => {
|
||||
this.setState((prevState) => {
|
||||
return {
|
||||
plan: name
|
||||
@ -414,7 +418,7 @@ class SignupPage extends React.Component {
|
||||
sectionClass = 'singleplan';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={'gh-portal-content signup ' + sectionClass}>
|
||||
|
Loading…
Reference in New Issue
Block a user