Skip to content

Commit

Permalink
add isHMR flag to loadUrl, and default off on isSSR (#1372)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott authored Oct 21, 2020
1 parent e10e724 commit fcfa83f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions snowpack/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export async function command(commandOptions: CommandOptions) {
const runJob = runPlugin
.run({
isDev: isDev,
// @ts-ignore: deprecated
isHmrEnabled: getIsHmrEnabled(config),
// @ts-ignore: internal API only
log: (msg, data: {msg: string} = {}) => {
Expand Down
22 changes: 15 additions & 7 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn

const {cwd, config} = commandOptions;
const {port: defaultPort, hostname, open} = config.devOptions;
const isHmr = typeof config.devOptions.hmr !== 'undefined' ? config.devOptions.hmr : true;
const messageBus = new EventEmitter();
const port = await getPort(defaultPort);

Expand Down Expand Up @@ -434,7 +433,8 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
runPlugin
.run({
isDev: true,
isHmrEnabled: isHmr,
// @deprecated: no longer accurate when using the JS API
isHmrEnabled: (typeof config.devOptions.hmr !== 'undefined' ? config.devOptions.hmr : true),
// @ts-ignore: internal API only
log: (msg, data) => {
if (msg === 'CONSOLE_INFO') {
Expand Down Expand Up @@ -482,11 +482,19 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
reqUrl: string,
{
isSSR: _isSSR,
isHMR: _isHMR,
allowStale: _allowStale,
encoding: _encoding,
}: {isSSR?: boolean; allowStale?: boolean; encoding?: BufferEncoding | null} = {},
}: {
isSSR?: boolean;
isHMR?: boolean;
allowStale?: boolean;
encoding?: BufferEncoding | null;
} = {},
): Promise<LoadResult> {
const isSSR = _isSSR ?? false;
// Default to HMR on, but disable HMR if SSR mode is enabled.
const isHMR = _isHMR ?? ((config.devOptions.hmr ?? true) && !isSSR);
const allowStale = _allowStale ?? false;
const encoding = _encoding ?? null;
const reqUrlHmrParam = reqUrl.includes('?mtime=') && reqUrl.split('?')[1];
Expand Down Expand Up @@ -649,7 +657,7 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
plugins: config.plugins,
isDev: true,
isSSR,
isHmrEnabled: isHmr,
isHmrEnabled: isHMR,
sourceMaps: config.buildOptions.sourceMaps,
});
inMemoryBuildCache.set(
Expand Down Expand Up @@ -690,7 +698,7 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
if (isRoute) {
code = wrapHtmlResponse({
code: code as string,
hmr: isHmr,
hmr: isHMR,
hmrPort: hmrEngine.port !== port ? hmrEngine.port : undefined,
isDev: true,
config,
Expand All @@ -711,9 +719,9 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
}
case '.js': {
if (isProxyModule) {
code = await wrapImportProxy({url: reqPath, code, hmr: isHmr, config});
code = await wrapImportProxy({url: reqPath, code, hmr: isHMR, config});
} else {
code = wrapImportMeta({code: code as string, env: true, hmr: isHmr, config});
code = wrapImportMeta({code: code as string, env: true, hmr: isHMR, config});
}

if (hasCssResource)
Expand Down
1 change: 1 addition & 0 deletions snowpack/src/types/snowpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface PluginTransformOptions {

export interface PluginRunOptions {
isDev: boolean;
/* @deprecated */
isHmrEnabled: boolean;
}

Expand Down

1 comment on commit fcfa83f

@vercel
Copy link

@vercel vercel bot commented on fcfa83f Oct 21, 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.