diff --git a/.changeset/famous-bobcats-vanish.md b/.changeset/famous-bobcats-vanish.md new file mode 100644 index 000000000000..873cea592eb8 --- /dev/null +++ b/.changeset/famous-bobcats-vanish.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Adds source file properties to HTML elements only if devToolbar is enabled diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index c2f58fb9f859..97625f021a55 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -10,10 +10,12 @@ import { AggregateError, CompilerError } from '../errors/errors.js'; import { AstroErrorData } from '../errors/index.js'; import { resolvePath } from '../util.js'; import { createStylePreprocessor } from './style.js'; +import type { AstroPreferences } from '../../preferences/index.js'; export interface CompileProps { astroConfig: AstroConfig; viteConfig: ResolvedConfig; + preferences: AstroPreferences; filename: string; source: string; } @@ -26,6 +28,7 @@ export interface CompileResult extends TransformResult { export async function compile({ astroConfig, viteConfig, + preferences, filename, source, }: CompileProps): Promise { @@ -48,7 +51,10 @@ export async function compile({ resultScopedSlot: true, transitionsAnimationURL: 'astro/components/viewtransitions.css', annotateSourceFile: - viteConfig.command === 'serve' && astroConfig.devToolbar && astroConfig.devToolbar.enabled, + viteConfig.command === 'serve' && + astroConfig.devToolbar && + astroConfig.devToolbar.enabled && + (await preferences.get('devToolbar.enabled')), preprocessStyle: createStylePreprocessor({ filename, viteConfig, diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index 2aa6236ffe95..d02d78d6ae6a 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -139,6 +139,7 @@ export default function astro({ settings, logger }: AstroPluginOptions): vite.Pl const compileProps: CompileProps = { astroConfig: config, viteConfig: resolvedConfig, + preferences: settings.preferences, filename: normalizePath(parsedId.filename), source, }; @@ -179,6 +180,7 @@ export default function astro({ settings, logger }: AstroPluginOptions): vite.Pl cachedCompilation({ astroConfig: config, viteConfig: resolvedConfig, + preferences: settings.preferences, filename, source, });