Skip to content

annotateSourceFile accepted but data-astro-source-file/-loc attributes not emitted in dev (parity regression vs @astrojs/compiler) #96

Description

@janjcwebtech

Summary

In dev mode the WASM @astrojs/compiler annotates every rendered element with
data-astro-source-file and data-astro-source-loc attributes when
annotateSourceFile is enabled. @astrojs/compiler-rs accepts the
annotateSourceFile / annotate_source_file option but does not emit those
HTML attributes
, so on Astro 7 (which defaults to the Rust compiler) the
source annotations are simply absent from the served HTML.

This is a dev-tooling parity regression versus @astrojs/compiler.

Environment

  • @astrojs/compiler-rs: 0.3.1
  • astro: 7.1.1 (Rust compiler is the default)
  • Repro also implied on any Astro 7.x dev server

Expected

With the dev toolbar enabled, a dev-mode render annotates elements, e.g.:

<h1 data-astro-source-file="/abs/path/src/pages/index.astro" data-astro-source-loc="12:1"></h1>

(This is what Astro 5.x / 6.x produce via @astrojs/compiler.)

Actual

On Astro 7 dev, the served HTML contains zero data-astro-source-*
attributes on any element, across all pages.

Evidence

  • Astro still requests annotation: packages/astro/src/core/compile/compile.ts
    on main sets
    annotateSourceFile: viteConfig.command === 'serve' && astroConfig.devToolbar?.enabled && toolbarEnabled.
  • compiler-rs accepts the option — it is present in
    crates/astro_codegen/src/options.rs (annotate_source_file),
    crates/astro_napi (annotateSourceFile), and
    packages/compiler/src/shared.ts — so the flag is plumbed through to codegen.
  • But the attribute strings are never produced: a repo code search for
    data-astro-source returns no matches in the Rust sources, and the published
    native binary (@astrojs/compiler-binding-*/*.node) contains 0
    occurrences of data-astro-source. By contrast the WASM @astrojs/compiler
    emits data-astro-source-file and data-astro-source-loc.
  • Empirically: a fresh Astro 6.4.8 dev server emits these attributes
    (100+ per page); an Astro 7.1.1 dev server emits none, with the dev toolbar
    enabled in both.

Impact

These attributes are the source-location channel for dev tooling:

  • Astro's own Audit dev-toolbar app reads [data-astro-source-file],
    copies the values into a WeakMap, then strips the attributes (see
    Remove data-astro-source-file and data-astro-source-loc attributes in dev mode astro#13602). Without emission, its source-backed features
    (e.g. "open in editor" from an audit) have nothing to read.
  • Third-party dev tools built on the same channel break on Astro 7, e.g.
    astro-text-edit (in-browser visual content editing) and
    astro-click-to-source (Alt-click to open the source file in $EDITOR).
    Both locate elements via data-astro-source-file / -loc.

Repro

  1. npm create astro@latest on Astro 7, keep the dev toolbar enabled.
  2. astro dev.
  3. curl any page (or View Source) and grep for data-astro-source — no matches.

Ask

Implement dev-mode emission of data-astro-source-file and
data-astro-source-loc when annotateSourceFile is true, restoring parity with
@astrojs/compiler. If the intent is instead to move source-location exposure
to a different API (per the note on withastro/astro#13602 about a public API for
element annotations), it would help to document that migration path for
third-party dev tools.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions