Disable linker cache when we need to link for HMR

This commit is contained in:
zodern
2020-06-24 09:04:05 -05:00
parent 9dea37dd5a
commit 31959a4626

View File

@@ -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;
}
}