Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add isHMR flag to loadUrl, and default off on isSSR #1372

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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