Title: Expose template source locations in dev mode to jump from the DOM to the template · Issue #70927 · angular/angular · GitHub
Open Graph Title: Expose template source locations in dev mode to jump from the DOM to the template · Issue #70927 · angular/angular
X Title: Expose template source locations in dev mode to jump from the DOM to the template · Issue #70927 · angular/angular
Description: Which @angular/* package(s) are relevant/related to the feature request? compiler, compiler-cli, core Description When I want to change something I see on the page, the slowest part isn't the edit itself (template/style HMR is great), it...
Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? compiler, compiler-cli, core Description When I want to change something I see on the page, the slowest part isn't the edit ...
X Description: Which @angular/* package(s) are relevant/related to the feature request? compiler, compiler-cli, core Description When I want to change something I see on the page, the slowest part isn't the e...
Opengraph URL: https://github.com/angular/angular/issues/70927
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Expose template source locations in dev mode to jump from the DOM to the template","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\n\ncompiler, compiler-cli, core\n\n### Description\n\nWhen I want to change something I see on the page, the slowest part isn't the edit itself (template/style HMR is great), it's finding where that element lives. I open the browser inspector, look at markup full of `_ngcontent-*` attributes, guess which component it belongs to, and then search for the file and the line in my editor.\n\nOther ecosystems solve this with a \"click an element, open it in your editor\" tool (Svelte's inspector, Vue DevTools' open-in-editor, click-to-component for React). Angular doesn't have one, but most of the pieces are already in the framework:\n\n- #58982 added `ɵɵattachSourceLocations`, which puts a `data-ng-source-location=\"src/app/foo.html@o:…,l:…,c:…\"` attribute on every template element. The PR description says it's aimed at internal tools but that \"we may consider exposing this in dev mode in the future\".\n- #70303 added the `enableTemplateSourceLocations` compiler option (under the internal Bazel/g3 options).\n- `ng serve` runs on Vite, which already exposes `/__open-in-editor` (the `launch-editor` middleware used by Vite, Vue and Nuxt). It detects the running editor (VS Code, Cursor, WebStorm, Zed…) or uses the `LAUNCH_EDITOR` env variable, so Angular doesn't need to know anything about editors.\n\nI wanted to see how far these get us, so I built a small prototype on a fresh `ng new` app (v22.2.0). I enabled the option in a `tsconfig.dev.json` used only by the `development` configuration. Then I added a ~120 line dev-only script: hold Alt and hover to see the component and `file:line:col`, Alt+click calls `/__open-in-editor?file=\u003cpath>:\u003cline>:\u003ccol>` and the editor opens on that line.\n\nPrototype: https://github.com/aminesbdev/angular-source-inspector (see `src/dev/source-inspector.ts` and `tsconfig.dev.json`).\n\nIt worked better than I expected. I checked the locations in headless Chrome, and each one lands on the exact tag: external templates (`product-card.html:6:3` → `\u003cbutton class=\"buy\">`), inline templates (`price-tag.ts:7:7` → the `\u003cstrong>` inside the `template` string), and projected content. The compiler's project-relative paths work as-is with `/__open-in-editor`, since it resolves them from the directory where `ng serve` runs. With a real click, my editor opened on the right line. I did have to set `LAUNCH_EDITOR` because `launch-editor` doesn't detect my editor yet, but that's a one-line fix on their side.\n\nA few things I noticed along the way:\n\n- **Paths end up in production if you just turn it on.** Putting `enableTemplateSourceLocations` in `tsconfig.app.json` ships every template path in the production bundle (about 450 bytes on a three-component app). I only avoided it with a separate tsconfig for the development configuration, which isn't something most people would think to do.\n- A component's host element points to the template where it's *used*, not to its own template. That's probably right for this use case, but a tool would likely want both. The component's own class location is already available through its debug info, but only via `ɵcmp`.\n- I only tried a single-project workspace. In a multi-project workspace, the compiler's paths and the directory `/__open-in-editor` resolves from might not match.\n- `/__open-in-editor` comes from Vite and isn't something the Angular CLI documents, so tooling built on it would want the CLI to keep it around.\n\n### Proposed solution\n\nRoughly in this order:\n\n1. Make source locations safe to enable in dev: either the emitted instruction is dev-mode only, or the option is documented as a dev-only one. Then make the option public.\n2. Have `ng serve` turn it on by default for development builds (that part would be an angular-cli issue, I can open it there).\n3. Build tooling on top: an \"Open in editor\" action in Angular DevTools and/or an Alt+click overlay like the prototype. This could also start as a community package once the attribute is available.\n\nI'm happy to help with any of this if you think it's worth doing. I'm especially interested in steps 1 and 3.\n\n### Alternatives considered\n\n- **Component debug info only** (`ClassDebugInfo`, already emitted in dev mode). This gives the component class file and line, which is useful as a fallback, but not the template or the specific element. Reading it also requires `ɵcmp`.\n- **Chrome DevTools workspaces.** They let you save edits back to files, but they don't tell you which component template an element comes from.\n- **Third-party tools** could do this today by reading private fields, but that breaks easily. A dev-mode attribute emitted by the compiler is a much more stable base to build on.\n","author":{"url":"https://github.com/aminesbdev","@type":"Person","name":"aminesbdev"},"datePublished":"2026-09-24T18:02:46Z","url":"https://github.com/angular/angular/issues/70927"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7c27dc4a-a8df-5427-94af-a97ea0c55a3c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC6A:35F933:10ED12:186B82:6AFDCD33 |
| html-safe-nonce | b6ed0f9346e0e9c1afa42b796a809a7c340580f07f33cb7a458bfb22c63ce6bb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzZBOjM1RjkzMzoxMEVEMTI6MTg2QjgyOjZBRkRDRDMzIiwidmlzaXRvcl9pZCI6IjYxMjk4NTQzNTY4ODQ2NzE3OTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c38fc4c7fa2761a6284c78483ffdf1cec8fa14634988a325b5e8be259fafa24b |
| hovercard-subject-tag | issue:5572471956 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/70927/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6417d5527e364be84ad7446513987ea672722649fde7034730ba2f9f854de142/angular/angular/issues/70927 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6417d5527e364be84ad7446513987ea672722649fde7034730ba2f9f854de142/angular/angular/issues/70927 |
| og:image:alt | Which @angular/* package(s) are relevant/related to the feature request? compiler, compiler-cli, core Description When I want to change something I see on the page, the slowest part isn't the edit ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aminesbdev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 26886a40b582b821a7a76351e0a2f42b6d6160854b6e2520db24f31fd7be5da7 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 68ebaa631a1d248d69ebde4b9c5defd3a19aeb2f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width