diff --git a/tools/isobuild/compiler-plugin.js b/tools/isobuild/compiler-plugin.js index 7a62748f5a..9b76c0e089 100644 --- a/tools/isobuild/compiler-plugin.js +++ b/tools/isobuild/compiler-plugin.js @@ -82,6 +82,13 @@ const LINKER_CACHE = new LRU({ } }); +// For HMR to work, we have to do a full link during the initial +// build and each time the bundle changes. Here we store +// the previous cache key for the app's web.browser arch +// to check if it was modified or if we can use the cache +// TODO: support HMR when using the linker cache +let previousLinkKey = null; + const serverLibPackages = { // Make sure fibers is defined, if nothing else. fibers: true @@ -1688,7 +1695,10 @@ export class PackageSourceBatch { })); const cacheKey = `${cacheKeyPrefix}_${cacheKeySuffix}`; - if (LINKER_CACHE.has(cacheKey)) { + const canUseHMR = isApp && bundleArch === 'web.browser'; + const canUseCache = !canUseHMR || previousLinkKey === cacheKey; + + if (canUseCache && LINKER_CACHE.has(cacheKey)) { if (CACHE_DEBUG) { console.log('LINKER IN-MEMORY CACHE HIT:', linkerOptions.name, bundleArch); @@ -1711,7 +1721,7 @@ export class PackageSourceBatch { }); } - if (cacheFilename) { + if (canUseCache && cacheFilename) { let diskCached = null; try { diskCached = optimisticReadJsonOrNull(cacheFilename); @@ -1786,6 +1796,10 @@ export class PackageSourceBatch { } } + if (canUseHMR) { + previousLinkKey = cacheKey; + } + return ret; } }