Skip to content

Repository files navigation

πŸš€ vite-react-locator

Instantly jump from your browser to the exact source location of any JSX element.

Default: Ctrl + Click β€’ Fully configurable

npm version npm downloads License Vite React TypeScript

A lightweight Vite plugin that lets you hover any JSX element, inspect its source location, and jump directly to the exact line in your editor.

If React renders it, Locator can locate it.


🎬 Demo

vite-react-locator demo


✨ Features

  • ⚑ Single Babel AST traversal per file β€” fast, deterministic, stable SHA1-based ids
  • βš›οΈ Every HTML element, every SVG element, and every React component
  • 🧩 Function components, arrow components, memo(), forwardRef(), lazy(), Suspense, Portals (createPortal)
  • 🌳 Full parent/child DOM hierarchy and component ownership per element
  • πŸ” Understands how an element was rendered β€” .map() / .filter().map() / flatMap(), nested arrays, &&, ternaries, and switch cases
  • πŸͺ Tracks all React hooks (including custom useXxx hooks) used by each component
  • 🟦 Hover overlay with component name, file, and line
  • πŸ–±οΈ Ctrl + Click (fully configurable) opens the exact source location in your editor
  • 🧠 VS Code, Cursor, and Windsurf supported out of the box
  • πŸ“¦ Development only β€” the transform, registry, and runtime never ship to production
  • πŸ“ Strict TypeScript, zero any, zero runtime dependency on Node internals in the browser bundle

πŸ’‘ Works only in development mode (apply: "serve"). Nothing is included in your production build.


πŸ“Έ Demo

Hover any JSX element


Ctrl + Click


πŸ“¦ Installation

npm install -D vite-react-locator

or

pnpm add -D vite-react-locator

or

yarn add -D vite-react-locator

βœ… Compatibility

Tool Version / Status
Vite ^6.0.0 || ^7.0.0
React 17+
TypeScript βœ… Supported
JavaScript βœ… Supported (.jsx)
Development Mode βœ… Supported
Production Build Not included

πŸš€ Usage

1. Add the plugin

// vite.config.ts

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import locator from "vite-react-locator";

export default defineConfig({
  plugins: [
    react(),
    locator(),
  ],
});

2. Import the runtime

Import the runtime once in your application entry file (for example main.tsx, main.jsx, index.tsx, or index.jsx).

import "vite-react-locator/runtime";

Example:

// main.tsx

import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";

import "vite-react-locator/runtime";

ReactDOM.createRoot(document.getElementById("root")!).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
);

3. Start the development server

npm run dev

πŸ’‘ The runtime import is required only during development. It has no effect on your production build.


🎯 How to Use

  1. Hold the configured activation key (default: Ctrl).
  2. Hover over any JSX element β€” HTML, SVG, or a component.
  3. A blue overlay and tooltip appear showing the component, file, and line.
  4. Click the highlighted element.
  5. It opens instantly in VS Code, Cursor, or Windsurf.

βš™οΈ How It Works

React/TSX source
        β”‚
        β–Ό
Single Babel traversal (transform/)
        β”‚  component detection Β· JSX classification
        β”‚  hierarchy tracking Β· hook tracking
        β–Ό
Stable SHA1 locator ids injected as data-locator-id
        β”‚
        β–Ό
Registry served over /__locator + /__locator-options
        β”‚
        β–Ό
Runtime (browser) hovers via data-locator-id, shows overlay
        β”‚
        β–Ό
Ctrl + Click β†’ POST /__open { file, line, column }
        β”‚
        β–Ό
Dev server opens the file in VS Code / Cursor / Windsurf

🧩 Architecture

src/
  index.ts          β€” Vite plugin: transform hook, HTML injection, dev-server wiring
  shared/            β€” constants, hashing, tag classification, shared types
  transform/         β€” single-pass Babel visitor: components, JSX, hierarchy, hooks, injection
  runtime/           β€” browser code: hover overlay, activation-key handling, open requests
  server/            β€” dev-server routes (/__locator, /__locator-options, /__open) + editors
  tests/             β€” vitest suite

The transform runs once per file (enforce: "pre", before @vitejs/plugin-react), tags every JSX element with a content-addressed id, and records its metadata β€” tag, kind (html / svg / component / fragment / portal), owning component, parent/child hierarchy, hooks, and how it was rendered (normal / map / array / logical / ternary / conditional).


πŸ›  Supported Editors

Editor Status
VS Code βœ…
Cursor βœ…
Windsurf βœ…

The editor is auto-detected from TERM_PROGRAM, falling back to trying cursor, windsurf, then code on the $PATH.


πŸ§ͺ Development

npm install
npm run build   # tsup β€” bundles src/index.ts and src/runtime/index.ts
npm run test    # vitest
npm run lint    # eslint

The example/ app is a working Vite + React project wired to consume the local plugin as a real file: dependency, useful for end-to-end verification against a real dev server.


🀝 Contributing

Contributions are welcome.

  1. Fork the repository
  2. Create your feature branch
git checkout -b feature/amazing-feature
  1. Commit your changes
git commit -m "feat: add amazing feature"
  1. Push and open a Pull Request.

🐞 Found a Bug?

Please open an issue on GitHub and include:

  • Vite version
  • React version
  • Operating system
  • Steps to reproduce

πŸ“„ License

MIT License Β© Shivam Singh


Made with ❀️ by Shivam Singh

About

A Vite plugin for React that lets you Ctrl+Click any Jsx element in the browser to instantly open its source file in VS Code. Built for React 18/19 and Vite 6/7.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages