Skip to content

Commit

Permalink
fix: ignore HMR logs for monorepo files
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Jul 19, 2022
1 parent c9fa608 commit eaaa94d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/astro/src/vite-plugin-astro/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { PluginContext as RollupPluginContext, ResolvedId } from 'rollup';
import type { HmrContext, ModuleNode, ViteDevServer } from 'vite';
import type { AstroConfig } from '../@types/astro';
import type { LogOptions } from '../core/logger/core.js';
import { fileURLToPath } from 'node:url';
import { info } from '../core/logger/core.js';
import * as msg from '../core/messages.js';
import { invalidateCompilation, isCached } from './compile.js';
Expand Down Expand Up @@ -49,21 +50,31 @@ export async function trackCSSDependencies(
}
}

const PKG_PREFIX = new URL('../../', import.meta.url)
const isPkgFile = (id: string|null) => {
return id?.startsWith(fileURLToPath(PKG_PREFIX)) || id?.startsWith(PKG_PREFIX.pathname)
}

export async function handleHotUpdate(ctx: HmrContext, config: AstroConfig, logging: LogOptions) {
// Invalidate the compilation cache so it recompiles
invalidateCompilation(config, ctx.file);

// Skip monorepo files to avoid console spam
if (isPkgFile(ctx.file)) {
return;
}

// go through each of these modules importers and invalidate any .astro compilation
// that needs to be rerun.
const filtered = new Set<ModuleNode>(ctx.modules);
const files = new Set<string>();
for (const mod of ctx.modules) {
// This is always the HMR script, we skip it to avoid spamming
// the browser console with HMR updates about this file
if (mod.id?.endsWith('/astro/dist/runtime/client/hmr.js')) {
// Skip monorepo files to avoid console spam
if (isPkgFile(mod.id ?? mod.file)) {
filtered.delete(mod);
continue;
}

if (mod.file && isCached(config, mod.file)) {
filtered.add(mod);
files.add(mod.file);
Expand Down

0 comments on commit eaaa94d

Please sign in to comment.