From cb9db479c9a2d53284150d5fdeabb51c1a99979d Mon Sep 17 00:00:00 2001 From: Vedant Pahune Date: Fri, 22 May 2026 11:42:15 +0530 Subject: [PATCH 1/2] fix(devtools-vite): preserve valid syntax when removing parenthesized devtools JSX --- packages/devtools-vite/src/ast-utils.ts | 10 ++++--- .../devtools-vite/src/remove-devtools.test.ts | 27 +++++++++++++++++++ packages/devtools-vite/src/remove-devtools.ts | 8 ++++-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/packages/devtools-vite/src/ast-utils.ts b/packages/devtools-vite/src/ast-utils.ts index e6a55f03..2ef0f1a2 100644 --- a/packages/devtools-vite/src/ast-utils.ts +++ b/packages/devtools-vite/src/ast-utils.ts @@ -48,7 +48,11 @@ export function forEachChild(node: Node, callback: (child: Node) => void) { /** * Recursively walk AST nodes, calling `visitor` for each node with a `type`. */ -export function walk(node: Node, visitor: (node: Node) => void) { - visitor(node) - forEachChild(node, (child) => walk(child, visitor)) +export function walk( + node: Node, + visitor: (node: Node, parentNode?: Node) => void, + parentNode?: Node, +) { + visitor(node, parentNode) + forEachChild(node, (child) => walk(child, visitor, node)) } diff --git a/packages/devtools-vite/src/remove-devtools.test.ts b/packages/devtools-vite/src/remove-devtools.test.ts index de87e223..297fc444 100644 --- a/packages/devtools-vite/src/remove-devtools.test.ts +++ b/packages/devtools-vite/src/remove-devtools.test.ts @@ -577,4 +577,31 @@ export default function App() { expect(output!.code).not.toContain('TanStackDevtools') }) }) + + test('preserves valid syntax when removing parenthesized devtools return', () => { + const output = removeEmptySpace( + removeDevtools( + ` +import { TanStackDevtools } from '@tanstack/react-devtools' + +export function DevtoolsProvider() { + return ( + + ) +} +`, + 'test.tsx', + )!.code, + ) + + expect(output).toBe( + removeEmptySpace(` +export function DevtoolsProvider() { + return ( + null + ) +} +`), + ) + }) }) diff --git a/packages/devtools-vite/src/remove-devtools.ts b/packages/devtools-vite/src/remove-devtools.ts index 05c6234c..26af2972 100644 --- a/packages/devtools-vite/src/remove-devtools.ts +++ b/packages/devtools-vite/src/remove-devtools.ts @@ -105,7 +105,7 @@ export function removeDevtools(code: string, id: string) { if (devtoolsNames.size === 0) return // Pass 2: Find and remove devtools JSX elements, collect plugin references - walk(result.program, (node) => { + walk(result.program, (node, parentNode) => { if (node.type !== 'JSXElement') return const opening = node.openingElement @@ -130,7 +130,11 @@ export function removeDevtools(code: string, id: string) { let end = node.end if (code[end] === '\n') end++ - s.remove(node.start, end) + if (parentNode?.type === 'ParenthesizedExpression') { + s.overwrite(node.start, end, 'null') + } else { + s.remove(node.start, end) + } }) // Pass 3: Remove plugin imports that are no longer referenced From 7384598917593b097cb3c451babd5e6e58fd997e Mon Sep 17 00:00:00 2001 From: Vedant Pahune Date: Fri, 22 May 2026 11:54:00 +0530 Subject: [PATCH 2/2] add changeset --- .changeset/small-papers-wink.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/small-papers-wink.md diff --git a/.changeset/small-papers-wink.md b/.changeset/small-papers-wink.md new file mode 100644 index 00000000..3bb3b94c --- /dev/null +++ b/.changeset/small-papers-wink.md @@ -0,0 +1,5 @@ +--- +'@tanstack/devtools-vite': patch +--- + +Fix invalid syntax generated when removing parenthesized devtools JSX expressions.