From 01fb71d033bd478bf303684b4bd775d42f72b135 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Sun, 6 Dec 2020 02:51:49 -0600 Subject: [PATCH] Fix HMR Regression (#1642) * Fix HMR Regression Previously changed dependencies will not be regressed when their dependent changes * Allow HMR accepted nodes to reload as before * Fix snapshot --- snowpack/src/commands/dev.ts | 14 +++++++++++--- snowpack/src/hmr-server-engine.ts | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/snowpack/src/commands/dev.ts b/snowpack/src/commands/dev.ts index 9a9cfeb775..983f738f2e 100644 --- a/snowpack/src/commands/dev.ts +++ b/snowpack/src/commands/dev.ts @@ -443,6 +443,7 @@ export async function startDevServer(commandOptions: CommandOptions): Promise { const importUrl = path.posix.resolve(path.posix.dirname(reqPath), imp); const node = hmrEngine.getEntry(importUrl); - if (node && node.needsReplacement) { + if (node == null) return imp; + if (node.needsReplacement) { hmrEngine.markEntryForReplacement(node, false); - return `${imp}?${reqUrlHmrParam}`; + node.mtime = mtime; + } + if (node.mtime && !node.isHmrAccepted) { + return `${imp}?mtime=${node.mtime}`; + } + if (node.needsReplacement) { + return `${imp}?mtime=${mtime}`; } return imp; }); diff --git a/snowpack/src/hmr-server-engine.ts b/snowpack/src/hmr-server-engine.ts index a22352fb9a..ff0e614bd0 100644 --- a/snowpack/src/hmr-server-engine.ts +++ b/snowpack/src/hmr-server-engine.ts @@ -10,6 +10,7 @@ interface Dependency { isHmrAccepted: boolean; needsReplacement: boolean; needsReplacementCount: number; + mtime: string | null; } type HMRMessage = @@ -103,6 +104,7 @@ export class EsmHmrEngine { needsReplacementCount: 0, isHmrEnabled: false, isHmrAccepted: false, + mtime: null, }; this.dependencyTree.set(sourceUrl, newEntry); return newEntry;