Fix EntryPage showing double confirmations if changes not saved.
Change suggested by @aquibm, thank you! This is changed as of React 16: When replacing `<A />` with `<B />`, `B.componentWillMount` now always happens before `A.componentWillUnmount`. Previously, `A.componentWillUnmount` could fire first in some cases.
This commit is contained in:
parent
5efa384684
commit
43a44743c8
@ -56,11 +56,18 @@ class EntryPage extends React.Component {
|
||||
loadEntry(collection, slug);
|
||||
}
|
||||
|
||||
this.unblock = history.block((location) => {
|
||||
const unblock = history.block((location) => {
|
||||
if (this.props.entryDraft.get('hasChanged')) {
|
||||
return "Are you sure you want to leave this page?";
|
||||
}
|
||||
});
|
||||
|
||||
// This will run as soon as the location actually changes.
|
||||
// (The confirmation above will run first.)
|
||||
this.unlisten = history.listen(() => {
|
||||
unblock();
|
||||
this.unlisten();
|
||||
});
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
@ -83,7 +90,6 @@ class EntryPage extends React.Component {
|
||||
|
||||
componentWillUnmount() {
|
||||
this.props.discardDraft();
|
||||
this.unblock();
|
||||
}
|
||||
|
||||
createDraft = (entry) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user