From 8b5eaca284a983e91ccdb7ba1c2725f4b579454a Mon Sep 17 00:00:00 2001 From: "factory[bot]" Date: Mon, 28 Sep 2026 21:32:41 +0000 Subject: [PATCH] Skip dev toolbar source annotations when compiling in Vite test mode (#18162) --- .changeset/young-teeth-draw.md | 5 + packages/astro/package.json | 2 +- packages/astro/src/core/compile/compile.ts | 4 + .../compile/annotate-source-file.test.ts | 36 +++++++ pnpm-lock.yaml | 102 +++++++++--------- 5 files changed, 97 insertions(+), 52 deletions(-) create mode 100644 .changeset/young-teeth-draw.md create mode 100644 packages/astro/test/units/compile/annotate-source-file.test.ts diff --git a/.changeset/young-teeth-draw.md b/.changeset/young-teeth-draw.md new file mode 100644 index 000000000000..b68aeac582cf --- /dev/null +++ b/.changeset/young-teeth-draw.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes `experimental_AstroContainer` output including dev toolbar `data-astro-source-file` and `data-astro-source-loc` attributes when rendering components under Vitest diff --git a/packages/astro/package.json b/packages/astro/package.json index 1a4e19661ac5..6bcc9fa3ee6b 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -124,7 +124,7 @@ "test:integration": "astro-scripts test \"test/*.test.ts\" --parallel --strip-types" }, "dependencies": { - "@astrojs/compiler-rs": "^0.5.0", + "@astrojs/compiler-rs": "^0.5.1", "@astrojs/internal-helpers": "workspace:*", "@astrojs/markdown-satteri": "workspace:*", "@astrojs/telemetry": "workspace:*", diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index 39aba5eb0315..ff1566c6035a 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -63,8 +63,12 @@ export async function compile({ scopedStyleStrategy: astroConfig.scopedStyleStrategy, resultScopedSlot: true, transitionsAnimationURL: 'astro/components/viewtransitions.css', + // Source annotations only serve the dev toolbar. Vitest also runs Vite in `serve`, + // so skip them in `test` mode to keep rendered markup (e.g. from the Container API) + // free of machine-specific paths. See https://github.com/withastro/astro/issues/18162 annotateSourceFile: viteConfig.command === 'serve' && + viteConfig.mode !== 'test' && astroConfig.devToolbar && astroConfig.devToolbar.enabled && toolbarEnabled, diff --git a/packages/astro/test/units/compile/annotate-source-file.test.ts b/packages/astro/test/units/compile/annotate-source-file.test.ts new file mode 100644 index 000000000000..87fe29be860c --- /dev/null +++ b/packages/astro/test/units/compile/annotate-source-file.test.ts @@ -0,0 +1,36 @@ +import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import { pathToFileURL } from 'node:url'; +import { resolveConfig } from 'vite'; +import { compile } from '../../../dist/core/compile/index.js'; +import type { AstroConfig } from '../../../dist/types/public/config.js'; + +async function compileInMode(mode: string) { + const result = await compile({ + astroConfig: { + root: pathToFileURL('/'), + experimental: {}, + devToolbar: { enabled: true }, + } as AstroConfig, + viteConfig: await resolveConfig({ configFile: false, mode }, 'serve'), + toolbarEnabled: true, + filename: '/src/components/Hello.astro', + source: ``, + }); + return result.code; +} + +describe('astro/src/core/compile', () => { + describe('annotateSourceFile', () => { + it('adds source annotations in dev', async () => { + const code = await compileInMode('development'); + assert.match(code, /data-astro-source-file=/); + }); + + it('does not add source annotations in Vitest (test mode)', async () => { + const code = await compileInMode('test'); + assert.doesNotMatch(code, /data-astro-source-file=/); + assert.doesNotMatch(code, /data-astro-source-loc=/); + }); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dcce91762f05..85d16f135289 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -529,8 +529,8 @@ importers: packages/astro: dependencies: '@astrojs/compiler-rs': - specifier: ^0.5.0 - version: 0.5.0 + specifier: ^0.5.1 + version: 0.5.1 '@astrojs/internal-helpers': specifier: workspace:* version: link:../internal-helpers @@ -7268,75 +7268,75 @@ packages: resolution: {integrity: sha512-bVzyKzEpIwqjihBU/aUzt1LQckJuHK0agd3/ITdXhPUYculrc6K1/K7H+XG4rwjXtg+ikT3PM05V1MVYWiIvQw==} engines: {node: '>=18.14.1'} - '@astrojs/compiler-binding-android-arm64@0.5.0': - resolution: {integrity: sha512-wVviC/1KaBqGVF0DbTZ8UtAE3c8TN84CCe7w4ju3SGzo/ByWKn8HCqSU/+1wdltGCCSa30pjVk3H8DQUgnfhRQ==} + '@astrojs/compiler-binding-android-arm64@0.5.1': + resolution: {integrity: sha512-nMb2nMIJtcWLNH+fV75Enmi+jp4tIOYOfsv4XtpgdOWkqc9P4uSSdK5u1xb340AzrXo5V18SxLl/nc3vcqtamQ==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [android] - '@astrojs/compiler-binding-darwin-arm64@0.5.0': - resolution: {integrity: sha512-5NNIkaGeiztD9QQfhOy+nNrBCZVeHqVZPlfJVjTKq4yJiiSsxAhuBzmVlmK3BDhbSgUT8dai4JV5m6t4/BIQaw==} + '@astrojs/compiler-binding-darwin-arm64@0.5.1': + resolution: {integrity: sha512-5k4+nZ/WRt+dcVow4z7rBuI7iv9A58h/uQ91YJe1PrTivbcCkq3u2Ynx/AZJwII4CsZawBCeGpojkFjutZBhBQ==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [darwin] - '@astrojs/compiler-binding-darwin-x64@0.5.0': - resolution: {integrity: sha512-HU/waaccOQDXpvjoWA/9xzadNZIcWKblJoaw19lCxfVs6AHQYdZZOzZUQjY8HaLYGerTXjdADbra2XU+kXk9Og==} + '@astrojs/compiler-binding-darwin-x64@0.5.1': + resolution: {integrity: sha512-0Buw+YST9Ff2EqQyhRMQujuFq/dijLw3zXWhsvI0dJ2pGrT38iVoxTEca2eBX/PfhlwkVWSRJEKO5gMqKHyeHg==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [darwin] - '@astrojs/compiler-binding-linux-arm64-gnu@0.5.0': - resolution: {integrity: sha512-a21petBJRi0mNBf+gkRZFoWdGH+VOo0zRQSzM4Nuez5RL5rFFkmbondMejkaRZzvE3LVYU2NVD5MGRgAs4V+nQ==} + '@astrojs/compiler-binding-linux-arm64-gnu@0.5.1': + resolution: {integrity: sha512-x5LRpyCoMKuu3INr18cn42YhwSOaRpp9b5Ny3eJJ/sWVeejC16Zeshu1JlvlSmEZACLeWxU5JM0RX6T6nI+YyA==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [linux] libc: [glibc] - '@astrojs/compiler-binding-linux-arm64-musl@0.5.0': - resolution: {integrity: sha512-t5rmu23b/6e6v0bhPibCtwPdABXMRL+bUaJXdkJwTpkINp4zCgH6fNa5Z6+RgkgFSCpmg9uf1MtRIqx1gdmBaA==} + '@astrojs/compiler-binding-linux-arm64-musl@0.5.1': + resolution: {integrity: sha512-mL7tQEuDk3rGfaKmrO63nw6WBy1TPVioQGmVyjcAr+C+a/k3SVMYBytNSMqH9mZPT/Swj30JaZ2N842Z1NnOEQ==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [linux] libc: [musl] - '@astrojs/compiler-binding-linux-x64-gnu@0.5.0': - resolution: {integrity: sha512-JWtouuxSiDb2OKKFsxOwfqlpJuZHo1ExirlBGfDgoJVG5zeJWwcd2tU2w4UaJA4suT/tAFSLk/vFhM5fLjWV4A==} + '@astrojs/compiler-binding-linux-x64-gnu@0.5.1': + resolution: {integrity: sha512-uLGc9jtxwiDe4cQyhNPQim4ECiB/YzbWlXssfLAv8r374kArfTwBHjwR2+j+XVyF71yCx5mF9YNRclRqdNBgeg==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [linux] libc: [glibc] - '@astrojs/compiler-binding-linux-x64-musl@0.5.0': - resolution: {integrity: sha512-LlaSO5v3UC6IxuTKXDViWV/fFHYhLKSO9Of118lNBXv/sjIWwziU+jjENxPgxfq/4oUeOu+613y6H93LBPNTOA==} + '@astrojs/compiler-binding-linux-x64-musl@0.5.1': + resolution: {integrity: sha512-G0cywinaQUc8v1MrytvYKUX7svTDMmYtOCZfxjwKPbJi59zIqM+Ll0rWgO0GQWLZH3XoPYo19ZwlP3Xt9ep9YA==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [linux] libc: [musl] - '@astrojs/compiler-binding-wasm32-wasi@0.5.0': - resolution: {integrity: sha512-IP+Cp0m9yKg/AUT47077vHEaAOh/oT/iUZx1PDnV2GJzUxLSEotdQy5Hhv+ycvEadO/DbETSJfAWeV7kte4etQ==} + '@astrojs/compiler-binding-wasm32-wasi@0.5.1': + resolution: {integrity: sha512-yMhLL8asmLydoAdnEZxAw6eLfNDs3YJl6jqn0pjPt6zrb2U5qIDLnii4/twThpIFODKkQ6YDpBRTOz/vSfZCxw==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [wasm32] - '@astrojs/compiler-binding-win32-arm64-msvc@0.5.0': - resolution: {integrity: sha512-v6plwy5GQBGvfv4QgiGhy/qkkQvYKW7Zh2vBArOnsGEDNHyUS43CWYwIQdw4ZdVVmLsFyhwTiueDZEP6zejddQ==} + '@astrojs/compiler-binding-win32-arm64-msvc@0.5.1': + resolution: {integrity: sha512-aClIG6poFt3Wf/bZykrEAX2nAnKvBHW6RXiKUa69QjBtWH0/FOlOAjnFcxRNlhej2AMWNYFx0o+LGjwMcH8P7Q==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [win32] - '@astrojs/compiler-binding-win32-x64-msvc@0.5.0': - resolution: {integrity: sha512-SgM158cSCJ248UIXaCCW2WqSTjOoFlDv93ed/ATguJqYpZNNVMlOdcPlgNH7WYj/OYeD0rIQr7XyRAYhB7+G1A==} + '@astrojs/compiler-binding-win32-x64-msvc@0.5.1': + resolution: {integrity: sha512-/E6uBCagY70YpWqssBC+/FuniNSloeQPRgj7l3LDWiqjxIyTLnIgX1sTt18FU7jrigetpSnC9cHAM6b6IxSgPw==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [win32] - '@astrojs/compiler-binding@0.5.0': - resolution: {integrity: sha512-PxFTx3WoxQnbgUvvwmF6LRQwhHO77a4pewOtJvzxlrYtQ90tLgomLKvks/akrd2iix2ngGlOhxQonKNd8YoBHg==} + '@astrojs/compiler-binding@0.5.1': + resolution: {integrity: sha512-oczyolLUl9mNrtuBuNjuvn5thpHrFLXAHAWGTRg0JDHQ8cGVsVeFekOu2uSoQGgainJIi+A3/9m0DyYwz3Nlnw==} engines: {node: ^20.19.0 || >=22.12.0} - '@astrojs/compiler-rs@0.5.0': - resolution: {integrity: sha512-2xIypn5R33FRWCXXXv0sfbDj8xcOvc2VmIbteytxMjOzP9LiGfvqaAFJjhdAjzhs6+ZKzYzbSE79rrPObYW5mg==} + '@astrojs/compiler-rs@0.5.1': + resolution: {integrity: sha512-1k1acnX7DepIiea9U9/Y+d1hdAFfylu1ZQQkkYgRSwBOBAsXInolyZuh/2tax+83vu/A+hOYP6P3+265RvMTvw==} engines: {node: '>=22.12.0'} '@astrojs/compiler@2.13.1': @@ -17204,56 +17204,56 @@ snapshots: log-update: 5.0.1 sisteransi: 1.0.5 - '@astrojs/compiler-binding-android-arm64@0.5.0': + '@astrojs/compiler-binding-android-arm64@0.5.1': optional: true - '@astrojs/compiler-binding-darwin-arm64@0.5.0': + '@astrojs/compiler-binding-darwin-arm64@0.5.1': optional: true - '@astrojs/compiler-binding-darwin-x64@0.5.0': + '@astrojs/compiler-binding-darwin-x64@0.5.1': optional: true - '@astrojs/compiler-binding-linux-arm64-gnu@0.5.0': + '@astrojs/compiler-binding-linux-arm64-gnu@0.5.1': optional: true - '@astrojs/compiler-binding-linux-arm64-musl@0.5.0': + '@astrojs/compiler-binding-linux-arm64-musl@0.5.1': optional: true - '@astrojs/compiler-binding-linux-x64-gnu@0.5.0': + '@astrojs/compiler-binding-linux-x64-gnu@0.5.1': optional: true - '@astrojs/compiler-binding-linux-x64-musl@0.5.0': + '@astrojs/compiler-binding-linux-x64-musl@0.5.1': optional: true - '@astrojs/compiler-binding-wasm32-wasi@0.5.0': + '@astrojs/compiler-binding-wasm32-wasi@0.5.1': dependencies: '@emnapi/core': 1.11.3 '@emnapi/runtime': 1.11.3 '@napi-rs/wasm-runtime': 1.2.4(@emnapi/core@1.11.3)(@emnapi/runtime@1.11.3) optional: true - '@astrojs/compiler-binding-win32-arm64-msvc@0.5.0': + '@astrojs/compiler-binding-win32-arm64-msvc@0.5.1': optional: true - '@astrojs/compiler-binding-win32-x64-msvc@0.5.0': + '@astrojs/compiler-binding-win32-x64-msvc@0.5.1': optional: true - '@astrojs/compiler-binding@0.5.0': + '@astrojs/compiler-binding@0.5.1': optionalDependencies: - '@astrojs/compiler-binding-android-arm64': 0.5.0 - '@astrojs/compiler-binding-darwin-arm64': 0.5.0 - '@astrojs/compiler-binding-darwin-x64': 0.5.0 - '@astrojs/compiler-binding-linux-arm64-gnu': 0.5.0 - '@astrojs/compiler-binding-linux-arm64-musl': 0.5.0 - '@astrojs/compiler-binding-linux-x64-gnu': 0.5.0 - '@astrojs/compiler-binding-linux-x64-musl': 0.5.0 - '@astrojs/compiler-binding-wasm32-wasi': 0.5.0 - '@astrojs/compiler-binding-win32-arm64-msvc': 0.5.0 - '@astrojs/compiler-binding-win32-x64-msvc': 0.5.0 - - '@astrojs/compiler-rs@0.5.0': - dependencies: - '@astrojs/compiler-binding': 0.5.0 + '@astrojs/compiler-binding-android-arm64': 0.5.1 + '@astrojs/compiler-binding-darwin-arm64': 0.5.1 + '@astrojs/compiler-binding-darwin-x64': 0.5.1 + '@astrojs/compiler-binding-linux-arm64-gnu': 0.5.1 + '@astrojs/compiler-binding-linux-arm64-musl': 0.5.1 + '@astrojs/compiler-binding-linux-x64-gnu': 0.5.1 + '@astrojs/compiler-binding-linux-x64-musl': 0.5.1 + '@astrojs/compiler-binding-wasm32-wasi': 0.5.1 + '@astrojs/compiler-binding-win32-arm64-msvc': 0.5.1 + '@astrojs/compiler-binding-win32-x64-msvc': 0.5.1 + + '@astrojs/compiler-rs@0.5.1': + dependencies: + '@astrojs/compiler-binding': 0.5.1 '@astrojs/compiler@2.13.1': {}