Skip to content

Commit

Permalink
perf: track context lifecycle hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-drexler authored and dmbch committed Mar 12, 2018
1 parent 31ee6ad commit a4d7dec
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/react/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,31 @@ var cloneContext = mixinable.replicate(function(initialArgs, newArgs) {
var renderWithContext = function(reactElement, _context) {
return function(req, res, next) {
var renderContext = cloneContext(_context, { request: req, response: res });

var timings = res.locals.timings;
timings.start('hops.react.bootstrap');
renderContext
.bootstrap()
.then(function() {
timings.end('hops.react.bootstrap');
timings.start('hops.react.enhanceElement');
return renderContext.enhanceElement(reactElement);
})
.then(function(rootElement) {
timings.end('hops.react.enhanceElement');
timings.start('hops.react.getTemplateData');

return renderContext
.getTemplateData({}, rootElement)
.then(function(templateData) {
timings.end('hops.react.getTemplateData');

return { templateData: templateData, rootElement: rootElement };
});
})
.then(function(result) {
timings.start('hops.react.renderTemplate');

var templateData = result.templateData;
var rootElement = result.rootElement;
var markup = renderContext.renderTemplate(
Expand All @@ -91,6 +103,8 @@ var renderWithContext = function(reactElement, _context) {
templateData
)
);
timings.end('hops.react.renderTemplate');

var routerContext = templateData.routerContext;
if (routerContext.miss) {
next();
Expand Down

0 comments on commit a4d7dec

Please sign in to comment.