diff --git a/packages/astro/src/runtime/client/hmr.ts b/packages/astro/src/runtime/client/hmr.ts index 98153f4b2..ba17fc526 100644 --- a/packages/astro/src/runtime/client/hmr.ts +++ b/packages/astro/src/runtime/client/hmr.ts @@ -2,7 +2,10 @@ if (import.meta.hot) { import.meta.hot.on('vite:beforeUpdate', async (payload) => { for (const file of payload.updates) { - if (file.acceptedPath.includes('svelte&type=style') || file.acceptedPath.includes('astro&type=style')) { + if ( + file.acceptedPath.includes('svelte&type=style') || + file.acceptedPath.includes('astro&type=style') + ) { // This will only be called after the svelte component has hydrated in the browser. // At this point Vite is tracking component style updates, we need to remove // styles injected by Astro for the component in favor of Vite's internal HMR. diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index e06325bc3..d4b72a061 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -1,8 +1,8 @@ +import { fileURLToPath } from 'node:url'; 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'; @@ -50,15 +50,15 @@ 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) -} +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;