Skip to content

Commit

Permalink
🐛 fix disappearing nav after import
Browse files Browse the repository at this point in the history
closes TryGhost/Ghost#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 emberjs/data#4963
  • Loading branch information
kevinansfield committed May 23, 2017
1 parent 88f13b6 commit 920eb83
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/controllers/settings/labs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 920eb83

Please sign in to comment.