Skip to content

Commit

Permalink
revert fix for hmr regression, breaks svelte and vue
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Dec 7, 2020
1 parent bbcfa95 commit 7826f53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 6 additions & 12 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import * as colors from 'kleur/colors';
import mime from 'mime-types';
import os from 'os';
import path from 'path';
import querystring from 'querystring';
import {performance} from 'perf_hooks';
import onProcessExit from 'signal-exit';
import stream from 'stream';
Expand Down Expand Up @@ -443,7 +442,7 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
const isHMR = _isHMR ?? ((config.devOptions.hmr ?? true) && !isSSR);
const allowStale = _allowStale ?? false;
const encoding = _encoding ?? null;
const reqQuery = querystring.parse(reqUrl.split('?')[1]) as {mtime?: string};
const reqUrlHmrParam = reqUrl.includes('?mtime=') && reqUrl.split('?')[1];
let reqPath = decodeURI(url.parse(reqUrl).pathname!);
const originalReqPath = reqPath;
let isProxyModule = false;
Expand Down Expand Up @@ -805,21 +804,16 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
}

let code = wrappedResponse;
if (responseFileExt === '.js' && reqQuery.mtime) {
if (responseFileExt === '.js' && reqUrlHmrParam)
code = await transformEsmImports(code as string, (imp) => {
const importUrl = path.posix.resolve(path.posix.dirname(reqPath), imp);
const node = hmrEngine.getEntry(importUrl);
if (!node || !node.needsReplacement) {
return imp;
if (node && node.needsReplacement) {
hmrEngine.markEntryForReplacement(node, false);
return `${imp}?${reqUrlHmrParam}`;
}
hmrEngine.markEntryForReplacement(node, false);
if (node.isHmrAccepted) {
return imp;
}
node.mtime = reqQuery.mtime;
return `${imp}?mtime=${reqQuery.mtime}`;
return imp;
});
}

if (responseFileExt === '.js') {
const isHmrEnabled = code.includes('import.meta.hot');
Expand Down
2 changes: 0 additions & 2 deletions snowpack/src/hmr-server-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type http from 'http';
import type http2 from 'http2';

interface Dependency {
mtime: string | undefined;
dependents: Set<string>;
dependencies: Set<string>;
isHmrEnabled: boolean;
Expand Down Expand Up @@ -98,7 +97,6 @@ export class EsmHmrEngine {

createEntry(sourceUrl: string) {
const newEntry: Dependency = {
mtime: undefined,
dependencies: new Set(),
dependents: new Set(),
needsReplacement: false,
Expand Down

1 comment on commit 7826f53

@vercel
Copy link

@vercel vercel bot commented on 7826f53 Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.