From 1bd5fcc9038e47fcc233543e32903b6e02aeb3a1 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Sun, 24 Jun 2018 22:03:53 -0700 Subject: [PATCH] Copy on write to fix writing hashed bundle names to the cache Fixes #1586. --- src/Asset.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Asset.js b/src/Asset.js index 0931a4fffe5..2191f15a2c5 100644 --- a/src/Asset.js +++ b/src/Asset.js @@ -231,15 +231,23 @@ class Asset { } replaceBundleNames(bundleNameMap) { + let copied = false; for (let key in this.generated) { let value = this.generated[key]; if (typeof value === 'string') { // Replace temporary bundle names in the output with the final content-hashed names. + let newValue = value; for (let [name, map] of bundleNameMap) { - value = value.split(name).join(map); + newValue = newValue.split(name).join(map); } - this.generated[key] = value; + // Copy `this.generated` on write so we don't end up writing the final names to the cache. + if (newValue !== value && !copied) { + this.generated = Object.assign({}, this.generated); + copied = true; + } + + this.generated[key] = newValue; } } }