Skip to content

Commit bc6ead5

Browse files
feat: exclude devtools from production by default (#45)
Uses /production subpath now --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent d02877e commit bc6ead5

File tree

17 files changed

+115
-25
lines changed

17 files changed

+115
-25
lines changed

.changeset/cuddly-mammals-cough.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@tanstack/devtools-event-client': patch
3+
'@tanstack/react-devtools': patch
4+
'@tanstack/solid-devtools': patch
5+
---
6+
7+
exclude from production by default

examples/react/start/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"start": "node .output/server/index.mjs",
88
"serve": "vite preview",
99
"test": "vitest run",
10+
"preview": "vite preview",
1011
"db:migrate": "prisma migrate dev --name init",
1112
"db:reset": " prisma migrate reset",
1213
"db:gen": "prisma generate",
@@ -35,7 +36,6 @@
3536
"zod": "^4.0.14"
3637
},
3738
"devDependencies": {
38-
"@tanstack/devtools": "^0.4.0",
3939
"@testing-library/dom": "^10.4.0",
4040
"@testing-library/react": "^16.2.0",
4141
"@types/react": "^19.1.2",

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
{
5050
"path": "packages/devtools/dist/esm/index.js",
5151
"limit": "30 KB"
52+
},
53+
{
54+
"path": "packages/event-bus-client/dist/esm/plugin.js",
55+
"limit": "1 KB"
5256
}
5357
],
5458
"devDependencies": {

packages/event-bus-client/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
"default": "./dist/cjs/index.cjs"
3333
}
3434
},
35+
"./production": {
36+
"import": {
37+
"types": "./dist/esm/production.d.ts",
38+
"default": "./dist/esm/production.js"
39+
},
40+
"require": {
41+
"types": "./dist/cjs/production.d.cts",
42+
"default": "./dist/cjs/production.cjs"
43+
}
44+
},
3545
"./package.json": "./package.json"
3646
},
3747
"sideEffects": false,
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
export { EventClient } from './plugin'
1+
import * as Client from './plugin'
2+
3+
class MockClass {
4+
on(_: string, __: (...args: Array<any>) => void) {
5+
// No-op in production
6+
}
7+
onAll(_: (...args: Array<any>) => void) {
8+
// No-op in production
9+
}
10+
onAllPluginEvents(_: (...args: Array<any>) => void) {
11+
// No-op in production
12+
}
13+
emit(_: string, ...__: Array<any>) {
14+
// No-op in production
15+
}
16+
getPluginId() {
17+
// No-op in production
18+
}
19+
}
20+
21+
export const EventClient: (typeof Client)['EventClient'] =
22+
process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test'
23+
? (MockClass as any)
24+
: Client.EventClient
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { EventClient } from './plugin'

packages/event-bus-client/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const config = defineConfig({
1717
export default mergeConfig(
1818
config,
1919
tanstackViteConfig({
20-
entry: ['./src/index.ts'],
20+
entry: ['./src/index.ts', './src/production.ts'],
2121
srcDir: './src',
2222
}),
2323
)

packages/react-devtools/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
"default": "./dist/cjs/index.cjs"
3434
}
3535
},
36+
"./production": {
37+
"import": {
38+
"types": "./dist/esm/production.d.ts",
39+
"default": "./dist/esm/production.js"
40+
},
41+
"require": {
42+
"types": "./dist/cjs/production.d.cts",
43+
"default": "./dist/cjs/production.cjs"
44+
}
45+
},
3646
"./package.json": "./package.json"
3747
},
3848
"sideEffects": false,

packages/react-devtools/src/devtools.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
TanStackDevtoolsCore,
66
} from '@tanstack/devtools'
77
import { createPortal } from 'react-dom'
8-
import type { JSX } from 'react'
8+
import type { JSX, ReactElement } from 'react'
99
import type {
1010
ClientEventBusConfig,
1111
TanStackDevtoolsConfig,
@@ -101,7 +101,7 @@ export const TanStackDevtools = ({
101101
plugins,
102102
config,
103103
eventBusConfig,
104-
}: TanStackDevtoolsReactInit) => {
104+
}: TanStackDevtoolsReactInit): ReactElement | null => {
105105
const devToolRef = useRef<HTMLDivElement>(null)
106106
const [pluginContainer, setPluginContainer] = useState<HTMLElement | null>(
107107
null,
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
// re-export everything from the core devtools package
2-
export * from '@tanstack/devtools'
3-
/**
4-
* Export every hook individually - DON'T export from barrel files
5-
*/
1+
'use client'
62

7-
export * from './devtools'
8-
export type { TanStackDevtoolsReactPlugin } from './devtools'
3+
import * as Devtools from './devtools'
4+
5+
export const TanStackDevtools: (typeof Devtools)['TanStackDevtools'] =
6+
process.env.NODE_ENV !== 'development'
7+
? function () {
8+
return null
9+
}
10+
: Devtools.TanStackDevtools
11+
12+
export type {
13+
TanStackDevtoolsReactPlugin,
14+
TanStackDevtoolsReactInit,
15+
} from './devtools'

0 commit comments

Comments
 (0)