From de9e4b822795dff9722ab4d7b1a299cefc944585 Mon Sep 17 00:00:00 2001 From: Mitar Date: Wed, 3 Aug 2016 19:52:20 -0700 Subject: [PATCH] Correctly cache tag. Our workaround for https://github.com/meteor/meteor/issues/5913 was breaking the cache because it made empty head to be cached even for the client target. --- patch-compiling.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/patch-compiling.js b/patch-compiling.js index dc9118e..a088188 100644 --- a/patch-compiling.js +++ b/patch-compiling.js @@ -86,10 +86,19 @@ var matches = function (host, program) { // See: https://github.com/meteor/meteor/issues/5913 var originalAddCompileResult = CachingHtmlCompiler.prototype.addCompileResult; CachingHtmlCompiler.prototype.addCompileResult = function (inputFile, compileResult) { + var head = compileResult.head; + if (compileResult.head && !matches(inputFile.getArch(), 'web')) { // Head can only be emitted to web targets. - delete compileResult.head; + compileResult.head = ''; } - originalAddCompileResult.call(this, inputFile, compileResult); + try { + originalAddCompileResult.call(this, inputFile, compileResult); + } + finally { + // Restore whatever was initially stored for head. We have to restore because + // the cache is shared between targets and an empty head is cached otherwise. + compileResult.head = head; + } };