diff --git a/addon/initializers/prefetch.js b/addon/initializers/prefetch.js index eff4112..634942e 100644 --- a/addon/initializers/prefetch.js +++ b/addon/initializers/prefetch.js @@ -1,13 +1,12 @@ import Route from '@ember/routing/route'; import RouteMixin from 'ember-prefetch/mixins/route'; +import { gte } from 'ember-compatibility-helpers'; -let hasInitialized = false; +Route.reopen(RouteMixin); -export function initialize() { - if (!hasInitialized) { - hasInitialized = true; - - Route.reopen(RouteMixin); +export function initialize(application) { + if (gte('3.6.0')) { + application.inject('route:application', '__prefetch', 'service:prefetch'); } } diff --git a/addon/instance-initializers/prefetch.js b/addon/instance-initializers/prefetch.js index 59170da..5ee5aa6 100644 --- a/addon/instance-initializers/prefetch.js +++ b/addon/instance-initializers/prefetch.js @@ -3,9 +3,7 @@ import { resolve } from 'rsvp'; import { gte } from 'ember-compatibility-helpers'; export function initialize(instance) { - if (gte('3.6.0')) { - instance.inject('route:application', '__prefetch', 'service:prefetch'); - } else { + if (!gte('3.6.0')) { // Delete all of this in the Ember 3.8 LTS and rev major const ROUTER_NAME = 'router:main'; const router = instance.lookup(ROUTER_NAME); diff --git a/addon/services/prefetch.js b/addon/services/prefetch.js index 372350e..9486d5c 100644 --- a/addon/services/prefetch.js +++ b/addon/services/prefetch.js @@ -1,7 +1,6 @@ import Service, { inject as service } from '@ember/service'; -import { schedule } from '@ember/runloop'; import { createPrefetchChangeSet } from '../-private/diff-route-info'; -import RSVP from 'rsvp'; +import { Promise, all } from 'rsvp'; import { gte } from 'ember-compatibility-helpers'; let PrefetchService; @@ -13,7 +12,6 @@ if (gte('3.6.0')) { router: service('router'), init() { this._super(...arguments); - let privateRouter = this.router._router._routerMicrolib; let seenRoutes = new WeakMap(); this.router.on('routeWillChange', transition => { @@ -21,15 +19,17 @@ if (gte('3.6.0')) { return; } - schedule('actions', () => { + let routePromises = transition.routeInfos.map((info) => info._routePromise); + all(routePromises).then(() => { if (!this.isDestroying && !this.isDestroyed) { + let privateRouter = this.router._router._routerMicrolib; let changeSet = createPrefetchChangeSet(privateRouter, transition); if (changeSet.shouldCall) { for (let i = 0; i < changeSet.for.length; i++) { let { route, fullParams } = changeSet.for[i]; if (seenRoutes.has(route)) continue; - route._prefetched = new RSVP.Promise(r => { + route._prefetched = new Promise(r => { return r(route.prefetch(fullParams, transition)); }); seenRoutes.set(route, true); diff --git a/testem.js b/testem.js index b060477..4d4cfe7 100644 --- a/testem.js +++ b/testem.js @@ -9,7 +9,6 @@ module.exports = { // --no-sandbox is needed when running Chrome inside a container process.env.CI ? '--no-sandbox' : null, '--headless', - '--disable-gpu', '--disable-dev-shm-usage', '--disable-software-rasterizer', '--mute-audio', diff --git a/tests/acceptance/engine-test.js b/tests/acceptance/engine-test.js index 3cb1739..6ab9fdd 100644 --- a/tests/acceptance/engine-test.js +++ b/tests/acceptance/engine-test.js @@ -23,7 +23,6 @@ module('lazy engine loading', function(hooks) { ); this.owner.register('template:application', hbs`{{outlet}}`); this.owner.register('controller:application', Controller.extend()); - debugger; AppRouter.map(function() { this.mount('blog'); });