Skip to content

Commit 299e19d

Browse files
committed
Make promise-based titles work with FastBoot
Following up from #55, this makes FastBoot wait for our async code to complete before rendering the page. The code checks that FastBoot exists and that we’re running on FastBoot before using [fastboot.deferRendering](https://ember-fastboot.com/docs/user-guide#deferring-response-rendering) to tell FastBoot about our Promise.
1 parent 26673eb commit 299e19d

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

vendor/document-title/document-title.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ routeProps[mergedActionPropertyName] = {
5656
var self = this;
5757

5858
// Wrap in promise in case some tokens are asynchronous.
59-
Promise.resolve()
59+
var completion = Promise.resolve()
6060
.then(function() {
6161
if (typeof title === 'function') {
6262
// Wait for all tokens to resolve. It resolves immediately if all tokens are plain values (not promises).
@@ -74,6 +74,13 @@ routeProps[mergedActionPropertyName] = {
7474
// Stubbable fn that sets document.title
7575
self.router.setTitle(finalTitle);
7676
});
77+
78+
// Tell FastBoot about our async code
79+
var fastboot = lookupFastBoot(this);
80+
if (fastboot && fastboot.isFastBoot) {
81+
fastboot.deferRendering(completion);
82+
}
83+
7784
} else {
7885
// Continue bubbling.
7986
return true;
@@ -103,3 +110,8 @@ Ember.Router.reopen({
103110
}
104111
}
105112
});
113+
114+
function lookupFastBoot(context) {
115+
var container = getOwner ? getOwner(context) : context.container;
116+
return container.lookup('service:fastboot');
117+
}

0 commit comments

Comments
 (0)