<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jaroslav Barov</title>
    <description>The latest articles on DEV Community by Jaroslav Barov (@tanchu).</description>
    <link>https://dev.to/tanchu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4257728%2F87566b22-cf98-4031-af5a-e3103146e40c.png</url>
      <title>DEV Community: Jaroslav Barov</title>
      <link>https://dev.to/tanchu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tanchu"/>
    <language>en</language>
    <item>
      <title>Which component rendered this div? A build plugin that answers in one click</title>
      <dc:creator>Jaroslav Barov</dc:creator>
      <pubDate>Sat, 21 Nov 2026 17:38:25 +0000</pubDate>
      <link>https://dev.to/tanchu/which-component-rendered-this-div-a-build-plugin-that-answers-in-one-click-500n</link>
      <guid>https://dev.to/tanchu/which-component-rendered-this-div-a-build-plugin-that-answers-in-one-click-500n</guid>
      <description>&lt;h5&gt;
  
  
  Add &lt;code&gt;data-source="path:line"&lt;/code&gt; to every JSX element in development, for Vite, Next.js and Babel. Zero runtime, works in any DevTools, and great with AI coding agents.
&lt;/h5&gt;




&lt;p&gt;It's your first day on a new project. You don't know the codebase at all, and your first task is to fix a button on the checkout page. You open DevTools, click the button and see this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"MuiButtonBase-root MuiButton-root css-1x2y3z4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now find it in the code. You search for the class name: it's generated. You search for the text: it comes from translations. You search for the component name: it's used in 140 places. You follow imports from the router to the page, from the page to a layout, from the layout to a feature folder. Tens of minutes later, sometimes hours, you finally find the line you need.&lt;/p&gt;

&lt;p&gt;I did exactly this for years, on every new project. Then a small Babel plugin turned up, and my everyday development changed for good: I stopped searching and started opening the right line straight away.&lt;/p&gt;

&lt;p&gt;Since then it has moved with me from project to project. But projects moved on to Next.js and Vite, where a Babel plugin doesn't fit, and I didn't want to go back to searching. So I wrote an SWC plugin for Next.js and Rspack and a native Vite plugin, with the same options and the same output. Now it covers the three main React toolchains.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does
&lt;/h2&gt;

&lt;p&gt;The plugin adds a &lt;code&gt;data-source&lt;/code&gt; attribute with the file and line to every JSX element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/components/Example.tsx&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"wrapper"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Pencil&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Dialog&lt;/span&gt; &lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DialogContent&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;DialogContent&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Dialog&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;becomes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"wrapper"&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"src/components/Example.tsx:2"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Pencil&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"src/components/Example.tsx:3"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Dialog&lt;/span&gt; &lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"src/components/Example.tsx:4"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DialogContent&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"src/components/Example.tsx:5"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;DialogContent&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Dialog&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inspect any node in the browser and the file and line are right there in the Elements panel. No extension, no runtime, no editor integration needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not React DevTools or a click-to-component tool?
&lt;/h2&gt;

&lt;p&gt;Those are great, and I use them too. A plain attribute has a few properties they don't:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It's just HTML.&lt;/strong&gt; It works in any browser, in Safari's Web Inspector, in a remote session, in &lt;code&gt;document.querySelector('[data-source^="src/pages/checkout"]')&lt;/code&gt;, in a Playwright trace or a saved HTML snapshot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No runtime.&lt;/strong&gt; Nothing is injected into the bundle except the attribute strings, and you enable the plugin in development only, so production stays clean.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It doesn't depend on React internals.&lt;/strong&gt; React 19 stopped keeping the &lt;code&gt;__source&lt;/code&gt; location on elements and &lt;code&gt;_debugSource&lt;/code&gt; on fibers, which broke click-to-source tools; they had to switch to other mechanisms. An attribute added at build time doesn't care.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It's copyable.&lt;/strong&gt; QA can paste it into a bug report. You can paste it into a chat with an AI agent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The AI agent use case
&lt;/h2&gt;

&lt;p&gt;This turned out to be the main reason I use it today. When I work with Claude Code, Cursor or Copilot on UI, the hardest part of a prompt is often "which element do I mean". Now I inspect it, copy &lt;code&gt;data-source="src/features/cart/Summary.tsx:58"&lt;/code&gt;, and the agent opens the exact file and line. No guessing between three components with similar names, no "I've updated the wrong Button".&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Vite
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install -D vite-plugin-react-source-string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// vite.config.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"vite"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;react&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@vitejs/plugin-react"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;reactSourceString&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"vite-plugin-react-source-string"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"serve"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;reactSourceString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;react&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's a native Vite plugin written in TypeScript: it parses with oxc-parser, rewrites with magic-string (with source maps) and runs with &lt;code&gt;enforce: "pre"&lt;/code&gt;. No Babel, no WASM. It works with Vite 5 and later, including Rolldown-based Vite. Every Monday CI builds a test app with the plugin on Vite 5, 6, 7, the latest release and the current beta, so a breaking Vite release shows up before it reaches you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Next.js (SWC)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install -D swc-plugin-react-source-string@next-16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// next.config.ts&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;nextConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;experimental&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;swcPlugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"development"&lt;/span&gt;
      &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"swc-plugin-react-source-string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cwd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="n"&gt;nextConfig&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SWC plugins are WASM and tied to the &lt;code&gt;swc_core&lt;/code&gt; version inside the bundler, so the package has dist-tags per bundler: &lt;code&gt;next-16&lt;/code&gt;, &lt;code&gt;next-15&lt;/code&gt; and &lt;code&gt;rspack&lt;/code&gt;. The README has the table. Every Monday a CI job checks for new Next.js and Rspack releases. When one ships with a new &lt;code&gt;swc_core&lt;/code&gt;, the job rebuilds the plugin, runs a real &lt;code&gt;next build&lt;/code&gt; with it and opens a pull request.&lt;/p&gt;

&lt;h3&gt;
  
  
  Babel and Webpack
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install -D babel-plugin-react-source-string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// babel.config.js&lt;/span&gt;
&lt;span class="kd"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"development"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"babel-plugin-react-source-string"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Babel 7 and Babel 8 are supported. CI runs the tests against both, and against the newest &lt;code&gt;@babel/core&lt;/code&gt;, every week.&lt;/p&gt;

&lt;h2&gt;
  
  
  Options
&lt;/h2&gt;

&lt;p&gt;All three plugins share the same options and produce the same output:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;excluded&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Names to skip, e.g. &lt;code&gt;["Slot"]&lt;/code&gt;. Case-insensitive.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;root&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Project root for relative paths.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;libraries&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Tag HTML elements plus only the components imported from these packages, e.g. &lt;code&gt;["@mui/material"]&lt;/code&gt;. Less noise in the props of your own components.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;preferCallSite&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;For wrappers: point to where a component is used, not to the wrapper. More below.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  A reader's question that became a feature
&lt;/h2&gt;

&lt;p&gt;After my LinkedIn post about the plugins, a reader asked:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Does the Vite plugin handle components that pass props down to a UI library element, so the attribute points at your own file and not at node_modules?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The short answer was yes: the plugin never transforms &lt;code&gt;node_modules&lt;/code&gt;, so the attribute always points to your code. By default it points to the &lt;em&gt;innermost&lt;/em&gt; file in your code that renders the DOM node. Take a typical design-system wrapper:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/components/MyButton.tsx&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;MyButton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="n"&gt;variant&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"contained"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// line 2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// src/pages/Checkout.tsx&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyButton&lt;/span&gt; &lt;span class="n"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Pay&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;MyButton&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;                &lt;span class="c1"&gt;// line 42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both elements are tagged. &lt;code&gt;&amp;lt;MyButton&amp;gt;&lt;/code&gt; gets &lt;code&gt;Checkout.tsx:42&lt;/code&gt; and passes it down through &lt;code&gt;{...props}&lt;/code&gt;, but inside the wrapper the plugin adds its own attribute &lt;em&gt;after&lt;/em&gt; the spread, so it wins. The DOM says &lt;code&gt;MyButton.tsx:2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That's right when you're working on &lt;code&gt;MyButton&lt;/code&gt;. But the question made me think about the other case: &lt;code&gt;MyButton&lt;/code&gt; is used 300 times, and what you actually want to know is &lt;em&gt;which page&lt;/em&gt; rendered this particular button.&lt;/p&gt;

&lt;p&gt;So all three plugins now have an opt-in flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;reactSourceString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;preferCallSite&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With it, the plugin puts its attribute &lt;em&gt;before&lt;/em&gt; spread props, so a value coming from the parent wins and the DOM says &lt;code&gt;Checkout.tsx:42&lt;/code&gt;. It works through nested wrappers too: in &lt;code&gt;Page → Toolbar → MyButton → Button&lt;/code&gt;, where each one spreads its props, the outermost call site wins.&lt;/p&gt;

&lt;p&gt;Where it helps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Design systems and UI kits.&lt;/strong&gt; "This is MyButton" tells you little. "This is the Pay button on the checkout page" tells you everything.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bug reports and QA.&lt;/strong&gt; The attribute leads to the page code that configures the element: its props, text and handlers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AI agents.&lt;/strong&gt; The agent edits that one usage instead of changing a wrapper the whole app depends on.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's off by default, because when you work on the wrappers themselves you want to land in the wrapper. One limitation: a wrapper that picks props explicitly (&lt;code&gt;className&lt;/code&gt;, &lt;code&gt;onClick&lt;/code&gt;) and doesn't spread them still points to itself, since the call-site value never reaches the DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  A few implementation notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The line is the line of the opening &lt;code&gt;&amp;lt;&lt;/code&gt;, so multi-line elements point to their start.&lt;/li&gt;
&lt;li&gt;An element that already has &lt;code&gt;data-source&lt;/code&gt; is left alone. That's exactly what makes &lt;code&gt;preferCallSite&lt;/code&gt; possible.&lt;/li&gt;
&lt;li&gt;Fragments are never tagged: &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;Fragment&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;React.Fragment&amp;gt;&lt;/code&gt; accept only &lt;code&gt;key&lt;/code&gt; and &lt;code&gt;children&lt;/code&gt;, and React warns about any other prop.&lt;/li&gt;
&lt;li&gt;Turbopack-style virtual paths like &lt;code&gt;[project]/src/a.tsx&lt;/code&gt; are normalized, so the output is the same across bundlers.&lt;/li&gt;
&lt;li&gt;Releases go through release-please and npm trusted publishing with provenance. No long-lived npm tokens.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Vite: &lt;a href="https://www.npmjs.com/package/vite-plugin-react-source-string" rel="noopener noreferrer"&gt;npm&lt;/a&gt; · &lt;a href="https://github.com/tanchu/vite-plugin-react-source" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Next.js / Rspack (SWC): &lt;a href="https://www.npmjs.com/package/swc-plugin-react-source-string" rel="noopener noreferrer"&gt;npm&lt;/a&gt; · &lt;a href="https://github.com/tanchu/swc-plugin-react-source" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Babel / Webpack: &lt;a href="https://www.npmjs.com/package/babel-plugin-react-source-string" rel="noopener noreferrer"&gt;npm&lt;/a&gt; · &lt;a href="https://github.com/tanchu/babel-plugin-react-source-string" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;preferCallSite&lt;/code&gt; came from a single comment, so feedback really does shape these plugins. Issues and PRs are welcome, and if a plugin saves you time, a ⭐ on GitHub helps other people find it.&lt;/p&gt;

</description>
      <category>react</category>
      <category>nextjs</category>
      <category>vite</category>
      <category>swc</category>
    </item>
  </channel>
</rss>
