Skip to content

Commit d5f7c37

Browse files
authored
Merge pull request #146 from bekzod/avoid-lookup
avoid extra lookup when `fastbootInfo` reference already exist
2 parents 257cc5e + 765afb9 commit d5f7c37

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/ember-app.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ class EmberApp {
215215
* the app instance and then visits the given route and destroys the app instance
216216
* when the route is finished its render cycle.
217217
*
218+
* Ember apps can manually defer rendering in FastBoot mode if they're waiting
219+
* on something async the router doesn't know about. This function fetches
220+
* that promise for deferred rendering from the app.
221+
*
218222
* @param {string} path the URL path to render, like `/photos/1`
219223
* @param {Object} fastbootInfo An object holding per request info
220224
* @param {Object} bootOptions An object containing the boot options that are used by
@@ -235,7 +239,7 @@ class EmberApp {
235239
})
236240
.then(() => result.instanceBooted = true)
237241
.then(() => instance.visit(path, bootOptions))
238-
.then(() => waitForApp(instance))
242+
.then(() => fastbootInfo.deferredPromise)
239243
.then(() => instance);
240244
}
241245

@@ -410,16 +414,6 @@ function buildBootOptions(shouldRender) {
410414
};
411415
}
412416

413-
/*
414-
* Ember apps can manually defer rendering in FastBoot mode if they're waiting
415-
* on something async the router doesn't know about. This function fetches
416-
* that promise for deferred rendering from the app.
417-
*/
418-
function waitForApp(instance) {
419-
let fastbootInfo = instance.lookup('info:-fastboot');
420-
return fastbootInfo.deferredPromise;
421-
}
422-
423417
/*
424418
* Writes the shoebox into the DOM for the browser rendered app to consume.
425419
* Uses a script tag with custom type so that the browser will treat as plain

test/fastboot-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,16 @@ describe("FastBoot", function() {
353353
.catch((e) => expect(e).to.be.an('error'));
354354
});
355355

356+
it("matches app's fastboot-info and result's fastboot-info", function() {
357+
var fastboot = new FastBoot({
358+
distPath: fixture('basic-app')
359+
});
360+
361+
return fastboot.visit('/')
362+
.then((r) => {
363+
let lookupFastboot = r.instance.lookup('info:-fastboot');
364+
expect(r._fastbootInfo).to.deep.equal(lookupFastboot);
365+
});
366+
});
367+
356368
});

0 commit comments

Comments
 (0)