Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove data-astro-source-file and data-astro-source-loc attributes in dev mode #13602

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

natemoo-re
Copy link
Member

@natemoo-re natemoo-re commented Apr 11, 2025

Changes

  • To support the Audit dev toolbar app, Astro's compiler injects data-astro-source-file and data-astro-source-loc attributes on every element in dev mode.
  • In this PR, the Audit app has been updated to extract the data from these attributes, store them in a WeakMap that is keyed by each Element, and then remove the attributes.
  • This should improve the dev mode experience by simplifying the markup when inspecting the page.
  • Changeset added.

Impact

This admittedly might break some third-party dev toolbar apps that rely on these annotations. Ideally we would expose a public API to get the annotation info for an element.

Searching all of GitHub for data-astro-source-file yields a decent number of repos, but the vast majority of uses are workarounds to remove the attributes.

Testing

Tested manually because it involves dev mode-specific client-side script behavior, which would be flaky to run in CI.

Docs

As far as I can tell, this is an internal API that we've never documented!

These attributes were added in #9016 and first released in astro@3.5.0 in November 2023. I assume users have gotten used to ignoring them, but they're still visual noise. Since this approach allows us to reduce noise without removing functionality, I think we should.

Copy link

changeset-bot bot commented Apr 11, 2025

🦋 Changeset detected

Latest commit: 99f6bca

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Apr 11, 2025
@natemoo-re natemoo-re added the pr preview This PR has a preview release label Apr 11, 2025
@natemoo-re natemoo-re requested a review from Princesseuh April 11, 2025 05:06
@github-actions github-actions bot removed the pr preview This PR has a preview release label Apr 11, 2025
Copy link

pkg-pr-new bot commented Apr 11, 2025

astro

npm i https://pkg.pr.new/astro@13602

@astrojs/cloudflare

npm i https://pkg.pr.new/@astrojs/cloudflare@13602

@astrojs/netlify

npm i https://pkg.pr.new/@astrojs/netlify@13602

@astrojs/node

npm i https://pkg.pr.new/@astrojs/node@13602

@astrojs/vercel

npm i https://pkg.pr.new/@astrojs/vercel@13602

commit: 99f6bca

Copy link

codspeed-hq bot commented Apr 11, 2025

CodSpeed Performance Report

Merging #13602 will not alter performance

Comparing fix/audit-annotations (99f6bca) with main (a0774b3)

Summary

✅ 6 untouched benchmarks

Copy link
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, awesome work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants