Skip to content

Commit

Permalink
Force async-ness in template rendering methods
Browse files Browse the repository at this point in the history
There is a long-standing open bug in consolidate - tj/consolidate.js#143 - which causes errors in the callback functions passed to rendering methods to propogate back into the try/catch contained in consolidate and cause the callback to be fired twice. Since this bug has been open in consolidate for over two years, not much hope should be held of having it resolved there.

As such, add protection in Sails against errors in the callback functions being caught inside consolidate and the callback fired twice by forcing the callback to be called asynchronously.
  • Loading branch information
lennym committed Mar 10, 2016
1 parent 8b506a2 commit cd413e1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/hooks/views/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ module.exports = function configure ( sails ) {
}

// Save reference to view rendering function
sails.config.views.engine.fn = fn;
// munge callback to protect against https://github.com/tj/consolidate.js/issues/143
sails.config.views.engine.fn = function (str, options, cb) {
fn(str, options, function (e, result) { setImmediate(function () { cb(e, result); }); });
}
sails.log.silly('Configured view engine, `' + engineName + '`');
}

Expand Down

0 comments on commit cd413e1

Please sign in to comment.