From 43a44743c849a544c4e470c3c2624c077db92af4 Mon Sep 17 00:00:00 2001 From: Caleb Date: Mon, 23 Oct 2017 18:37:57 -0600 Subject: [PATCH] Fix EntryPage showing double confirmations if changes not saved. Change suggested by @aquibm, thank you! This is changed as of React 16: When replacing `` with ``, `B.componentWillMount` now always happens before `A.componentWillUnmount`. Previously, `A.componentWillUnmount` could fire first in some cases. --- src/containers/EntryPage.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/containers/EntryPage.js b/src/containers/EntryPage.js index 35337978..c0a2d805 100644 --- a/src/containers/EntryPage.js +++ b/src/containers/EntryPage.js @@ -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) => {