Skip to content

Commit b1ac893

Browse files
feat(event-client): strip the root EventClient export from production by default (#471)
* feat(event-client): add shared types module, /production entry, and package wiring * feat(event-client): add standalone no-op client and share event types * feat(event-client): no-op the root export outside development * docs(event-client): document dev-only root export and /production subpath * chore(event-client): add changeset for production stripping * test(event-client): guard no-op/real public-surface parity and cover the dev resolver branch * docs(event-client): clarify unset NODE_ENV behavior and fix stale stripping guidance * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent ea3c674 commit b1ac893

20 files changed

Lines changed: 431 additions & 28 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@tanstack/devtools-event-client': minor
3+
---
4+
5+
The root export of `@tanstack/devtools-event-client` now resolves to a no-op
6+
outside development (`process.env.NODE_ENV !== 'development'`), so the real
7+
`EventClient` is tree-shaken out of production bundles by default.
8+
9+
If you want devtools events to keep working in production, import the real
10+
client from the new `@tanstack/devtools-event-client/production` subpath, which
11+
always ships the real implementation. The public API is identical between the
12+
two imports.

docs/building-custom-plugins.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,27 @@ For usage details, see the [Using devtools-utils](./devtools-utils) guide.
209209
Once your plugin is working, you can share it with the community by publishing it to npm and submitting it to the TanStack Devtools Marketplace. The marketplace is a registry of third-party plugins that users can discover and install directly from the devtools UI.
210210

211211
For submission instructions and the registry format, see [Third-party Plugins](./third-party-plugins).
212+
213+
## Production builds
214+
215+
By default the **root import** of `@tanstack/devtools-event-client` no-ops
216+
outside development. When your bundler sets `process.env.NODE_ENV` to anything
217+
other than `'development'`, the real client is replaced by a no-op and
218+
tree-shaken out of your production bundle:
219+
220+
```ts
221+
// dev: real client — production: no-op (tree-shaken away)
222+
import { EventClient } from '@tanstack/devtools-event-client'
223+
```
224+
225+
If you are an open-source author who deliberately wants devtools events in
226+
production, import the real client from the `/production` subpath instead. It is
227+
never stripped:
228+
229+
```ts
230+
// always the real client, in every environment
231+
import { EventClient } from '@tanstack/devtools-event-client/production'
232+
```
233+
234+
The public API is identical between the two imports — only the production
235+
runtime behavior differs.

docs/framework/angular/guides/custom-plugins.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,27 @@ Heres an example of both:
215215
216216
[tanstack-devtools:custom-devtools-plugin] Registered event to bus custom-devtools:counter-state
217217
```
218+
219+
## Production builds
220+
221+
By default the **root import** of `@tanstack/devtools-event-client` no-ops
222+
outside development. When your bundler sets `process.env.NODE_ENV` to anything
223+
other than `'development'`, the real client is replaced by a no-op and
224+
tree-shaken out of your production bundle:
225+
226+
```ts
227+
// dev: real client — production: no-op (tree-shaken away)
228+
import { EventClient } from '@tanstack/devtools-event-client'
229+
```
230+
231+
If you are an open-source author who deliberately wants devtools events in
232+
production, import the real client from the `/production` subpath instead. It is
233+
never stripped:
234+
235+
```ts
236+
// always the real client, in every environment
237+
import { EventClient } from '@tanstack/devtools-event-client/production'
238+
```
239+
240+
The public API is identical between the two imports — only the production
241+
runtime behavior differs.

docs/framework/preact/guides/custom-plugins.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,27 @@ Heres an example of both:
202202
203203
🌴 [tanstack-devtools:custom-devtools-plugin] Registered event to bus custom-devtools:counter-state
204204
```
205+
206+
## Production builds
207+
208+
By default the **root import** of `@tanstack/devtools-event-client` no-ops
209+
outside development. When your bundler sets `process.env.NODE_ENV` to anything
210+
other than `'development'`, the real client is replaced by a no-op and
211+
tree-shaken out of your production bundle:
212+
213+
```ts
214+
// dev: real client — production: no-op (tree-shaken away)
215+
import { EventClient } from '@tanstack/devtools-event-client'
216+
```
217+
218+
If you are an open-source author who deliberately wants devtools events in
219+
production, import the real client from the `/production` subpath instead. It is
220+
never stripped:
221+
222+
```ts
223+
// always the real client, in every environment
224+
import { EventClient } from '@tanstack/devtools-event-client/production'
225+
```
226+
227+
The public API is identical between the two imports — only the production
228+
runtime behavior differs.

docs/framework/react/guides/custom-plugins.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,27 @@ Heres an example of both:
199199
200200
🌴 [tanstack-devtools:custom-devtools-plugin] Registered event to bus custom-devtools:counter-state
201201
```
202+
203+
## Production builds
204+
205+
By default the **root import** of `@tanstack/devtools-event-client` no-ops
206+
outside development. When your bundler sets `process.env.NODE_ENV` to anything
207+
other than `'development'`, the real client is replaced by a no-op and
208+
tree-shaken out of your production bundle:
209+
210+
```ts
211+
// dev: real client — production: no-op (tree-shaken away)
212+
import { EventClient } from '@tanstack/devtools-event-client'
213+
```
214+
215+
If you are an open-source author who deliberately wants devtools events in
216+
production, import the real client from the `/production` subpath instead. It is
217+
never stripped:
218+
219+
```ts
220+
// always the real client, in every environment
221+
import { EventClient } from '@tanstack/devtools-event-client/production'
222+
```
223+
224+
The public API is identical between the two imports — only the production
225+
runtime behavior differs.

docs/framework/solid/guides/custom-plugins.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,27 @@ Heres an example of both:
195195
196196
[tanstack-devtools:custom-devtools-plugin] Registered event to bus custom-devtools:counter-state
197197
```
198+
199+
## Production builds
200+
201+
By default the **root import** of `@tanstack/devtools-event-client` no-ops
202+
outside development. When your bundler sets `process.env.NODE_ENV` to anything
203+
other than `'development'`, the real client is replaced by a no-op and
204+
tree-shaken out of your production bundle:
205+
206+
```ts
207+
// dev: real client — production: no-op (tree-shaken away)
208+
import { EventClient } from '@tanstack/devtools-event-client'
209+
```
210+
211+
If you are an open-source author who deliberately wants devtools events in
212+
production, import the real client from the `/production` subpath instead. It is
213+
never stripped:
214+
215+
```ts
216+
// always the real client, in every environment
217+
import { EventClient } from '@tanstack/devtools-event-client/production'
218+
```
219+
220+
The public API is identical between the two imports — only the production
221+
runtime behavior differs.

docs/framework/vue/guides/custom-plugins.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,27 @@ Heres an example of both:
202202
203203
[tanstack-devtools:custom-devtools-plugin] Registered event to bus custom-devtools:counter-state
204204
```
205+
206+
## Production builds
207+
208+
By default the **root import** of `@tanstack/devtools-event-client` no-ops
209+
outside development. When your bundler sets `process.env.NODE_ENV` to anything
210+
other than `'development'`, the real client is replaced by a no-op and
211+
tree-shaken out of your production bundle:
212+
213+
```ts
214+
// dev: real client — production: no-op (tree-shaken away)
215+
import { EventClient } from '@tanstack/devtools-event-client'
216+
```
217+
218+
If you are an open-source author who deliberately wants devtools events in
219+
production, import the real client from the `/production` subpath instead. It is
220+
never stripped:
221+
222+
```ts
223+
// always the real client, in every environment
224+
import { EventClient } from '@tanstack/devtools-event-client/production'
225+
```
226+
227+
The public API is identical between the two imports — only the production
228+
runtime behavior differs.

docs/production.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@ function App() {
5757
}
5858
```
5959

60+
## Event client in production
61+
62+
By default the **root import** of `@tanstack/devtools-event-client` no-ops
63+
outside development. When your bundler sets `process.env.NODE_ENV` to anything
64+
other than `'development'`, the real client is replaced by a no-op and
65+
tree-shaken out of your production bundle:
66+
67+
```ts
68+
// dev: real client — production: no-op (tree-shaken away)
69+
import { EventClient } from '@tanstack/devtools-event-client'
70+
```
71+
72+
If you are an open-source author who deliberately wants devtools events in
73+
production, import the real client from the `/production` subpath instead. It is
74+
never stripped:
75+
76+
```ts
77+
// always the real client, in every environment
78+
import { EventClient } from '@tanstack/devtools-event-client/production'
79+
```
80+
81+
The public API is identical between the two imports — only the production
82+
runtime behavior differs.
83+
84+
This is independent of the Vite plugin's `removeDevtoolsOnBuild` option — the event client strips itself based on `NODE_ENV`, whether or not you use the Vite plugin.
85+
6086
## Where to install the Devtools
6187

6288
If you are using the devtools in development only, you can install them as a development dependency and only import them in development builds. This is the default recommended way to use the devtools.

packages/event-bus-client/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,29 @@ plugin.on('b', (e) => {
3737
The `EventClient` class is a base class for creating plugins that can subscribe to events in the TanStack Devtools event bus. It allows you to define a set of events and their corresponding data schemas using a standard-schema based schemas.
3838

3939
It will work on both the client/server side and all you have to worry about is emitting/listening to events.
40+
41+
## Production builds
42+
43+
By default the **root import** of `@tanstack/devtools-event-client` no-ops
44+
outside development. When your bundler sets `process.env.NODE_ENV` to anything
45+
other than `'development'`, the real client is replaced by a no-op and
46+
tree-shaken out of your production bundle:
47+
48+
```ts
49+
// dev: real client — production: no-op (tree-shaken away)
50+
import { EventClient } from '@tanstack/devtools-event-client'
51+
```
52+
53+
If you are an open-source author who deliberately wants devtools events in
54+
production, import the real client from the `/production` subpath instead. It is
55+
never stripped:
56+
57+
```ts
58+
// always the real client, in every environment
59+
import { EventClient } from '@tanstack/devtools-event-client/production'
60+
```
61+
62+
The public API is identical between the two imports — only the production
63+
runtime behavior differs.
64+
65+
"Outside development" includes when `NODE_ENV` is unset — common in plain Node scripts, some SSR dev servers, and test runners — so the root import resolves to the no-op there too. Set `NODE_ENV=development`, or use the `/production` subpath, to get the real client in those contexts.

packages/event-bus-client/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
"default": "./dist/cjs/index.cjs"
3636
}
3737
},
38+
"./production": {
39+
"import": {
40+
"types": "./dist/esm/production.d.ts",
41+
"default": "./dist/esm/production.js"
42+
},
43+
"require": {
44+
"types": "./dist/cjs/production.d.cts",
45+
"default": "./dist/cjs/production.cjs"
46+
}
47+
},
3848
"./package.json": "./package.json"
3949
},
4050
"bin": {

0 commit comments

Comments
 (0)