fix(devtools-kit): support JSX/TSX components in component inspector#1102
fix(devtools-kit): support JSX/TSX components in component inspector#1102NikhilVerma wants to merge 1 commit into
Conversation
Two bugs prevented the click-to-inspect picker from working with JSX/TSX components: 1. `inspectFn` only checked `e.target.__vueParentComponent` on the exact clicked element. JSX and functional components often only set this property on their root element, not on every inner child, so clicking a child element produced no match. Fixed by walking up the DOM tree until a component instance is found. 2. `getComponentFileName` only stripped the `.vue` extension when deriving a display name from `__file`. Components in `.jsx`/`.tsx` files showed up with the raw filename (e.g. `MyButton.jsx` instead of `MyButton`). Fixed by handling all three extensions. Also suppresses the `index` name for `index.jsx` and `index.tsx` barrel files, matching the existing behaviour for `index.vue`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
✅ Deploy Preview for vue-devtools-docs canceled.
|
|
I've been struggling to reproduce the original problem that this PR fixes. In my testing it seems that JSX/TSX and functional components all work as expected. Could you give some guidance on how to reproduce the problem? I probably just need an example of a component that fails.
I've not been able to observe this myself.
There is an edge case involving
I'm unclear how this would happen. For what it's worth, I was testing with a project created using Hopefully this will become clear once you've shared an example. Thanks. |
Summary
The "Click on a component to select it" picker did not work for JSX/TSX components. Two separate bugs caused this:
Bug 1 — DOM tree walking (
component-highlighter/index.ts)inspectFnonly checkede.target.__vueParentComponenton the exact element the cursor was over. JSX and functional components typically only set__vueParentComponenton their root DOM element, not every descendant. Hovering over a child element found nothing and the highlight never appeared.Fixed by walking up the DOM tree until an element with
__vueParentComponentis found.Bug 2 — Component name resolution (
component/utils/index.ts)getComponentFileNameusedbasename(file, '.vue')unconditionally, so components whose__filepointed to a.jsxor.tsxpath kept the raw extension in their display name (e.g.MyButton.jsxinstead ofMyButton).Fixed by handling
.jsxand.tsxalongside.vue. Also extends the existingindex.vuesuppression toindex.jsx/index.tsxbarrel files.Changes
packages/devtools-kit/src/core/component-highlighter/index.ts— walk up the DOM tree ininspectFnpackages/devtools-kit/src/core/component/utils/index.ts— strip.jsx/.tsxextensions ingetComponentFileName; suppressindexname for JSX/TSX barrel filesTests
__tests__/component/utils.test.ts— unit tests forgetComponentName/getInstanceNamewith.jsxand.tsxfiles__tests__/component/highlighter.test.ts— DOM-level tests verifying the highlight overlay is created when__vueParentComponentis only on a parent element (the JSX case)Test plan
pnpm test— all existing tests pass, 18 new tests added