From ab0281aee419e58c6079ca393987fe1ff0541dd5 Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:20:08 +0100 Subject: [PATCH] Adds source file properties to HTML elements only if devToolbar is enabled (#9343) --- .changeset/famous-bobcats-vanish.md | 5 +++++ packages/astro/src/core/compile/compile.ts | 8 +++++++- packages/astro/src/vite-plugin-astro/index.ts | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/famous-bobcats-vanish.md 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, });