From 920eb83aa84de25b146bb8fc03ab45651cf6f7bf Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 23 May 2017 09:04:40 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20disappearing=20nav=20after?= =?UTF-8?q?=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Ghost/issues/8307 - Ember 2.13 has a behaviour change to `store.unloadAll` where the records aren't removed until later in the runloop resulting in errors if the store is used to find records before it's completed. See https://github.com/emberjs/data/issues/4963 --- app/controllers/settings/labs.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/settings/labs.js b/app/controllers/settings/labs.js index 8449f9eb1b..4b37d9cb78 100644 --- a/app/controllers/settings/labs.js +++ b/app/controllers/settings/labs.js @@ -6,6 +6,7 @@ import {isBlank} from 'ember-utils'; import {isEmberArray} from 'ember-array/utils'; import {task} from 'ember-concurrency'; import {UnsupportedMediaTypeError, isUnsupportedMediaTypeError} from 'ghost-admin/services/ajax'; +import run from 'ember-runloop'; const {Promise} = RSVP; @@ -102,10 +103,17 @@ export default Controller.extend({ // Clear the store, so that all the new data gets fetched correctly. store.unloadAll(); - // Reload currentUser and set session - this.set('session.user', store.findRecord('user', currentUserId)); - // TODO: keep as notification, add link to view content - notifications.showNotification('Import successful.', {key: 'import.upload.success'}); + + // NOTE: workaround for behaviour change in Ember 2.13 + // store.unloadAll has some async tendencies so we need to schedule + // the reload of the current user once the unload has finished + // https://github.com/emberjs/data/issues/4963 + run.schedule('destroy', this, () => { + // Reload currentUser and set session + this.set('session.user', store.findRecord('user', currentUserId)); + // TODO: keep as notification, add link to view content + notifications.showNotification('Import successful.', {key: 'import.upload.success'}); + }); }).catch((response) => { if (isUnsupportedMediaTypeError(response)) { this.set('importErrors', [response]);