Skip to content

Commit 30c2070

Browse files
logaretmclaude
andcommitted
fix: exclude devtools code from production builds (#4972)
Three changes to prevent Vue Devtools integration from leaking into production bundles: 1. Wrap module-level variable initializations in __DEV__ guard so they are eliminated as dead code in production builds. 2. Make refreshInspector a no-op in production by wrapping the throttle() call in a __DEV__ ternary, removing the module-level side effect that prevented tree-shaking. 3. Add /* @vite-ignore */ to the dynamic import('@vue/devtools-api') to prevent Vite from creating a separate chunk for it in library mode builds. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7d8cc52 commit 30c2070

2 files changed

Lines changed: 40 additions & 25 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"vee-validate": patch
3+
---
4+
5+
Fix Vue Devtools code being included in production builds (#4972)

packages/vee-validate/src/devtools.ts

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,49 @@ import { PathState, PrivateFieldContext, PrivateFormContext } from './types';
44
import { isClient, keysOf, setInPath, throttle } from './utils';
55
import { isObject } from '../../shared';
66

7-
const DEVTOOLS_FORMS: Record<string, PrivateFormContext & { _vm?: ComponentInternalInstance | null }> = {};
8-
const DEVTOOLS_FIELDS: Record<string, PrivateFieldContext & { _vm?: ComponentInternalInstance | null }> = {};
9-
10-
const INSPECTOR_ID = 'vee-validate-inspector';
11-
12-
const COLORS = {
13-
error: 0xbd4b4b,
14-
success: 0x06d77b,
15-
unknown: 0x54436b,
16-
white: 0xffffff,
17-
black: 0x000000,
18-
blue: 0x035397,
19-
purple: 0xb980f0,
20-
orange: 0xf5a962,
21-
gray: 0xbbbfca,
22-
};
7+
let DEVTOOLS_FORMS: Record<string, PrivateFormContext & { _vm?: ComponentInternalInstance | null }>;
8+
let DEVTOOLS_FIELDS: Record<string, PrivateFieldContext & { _vm?: ComponentInternalInstance | null }>;
9+
10+
let INSPECTOR_ID: string;
11+
12+
let COLORS: Record<string, number>;
2313

2414
let SELECTED_NODE:
2515
| { type: 'pathState'; form: PrivateFormContext; state: PathState }
2616
| { type: 'form'; form: PrivateFormContext & { _vm?: ComponentInternalInstance | null } }
2717
| { type: 'field'; field: PrivateFieldContext & { _vm?: ComponentInternalInstance | null } }
28-
| null = null;
18+
| null;
2919

3020
/**
3121
* Plugin API
3222
*/
3323
let API: any;
3424

25+
if (__DEV__) {
26+
DEVTOOLS_FORMS = {};
27+
DEVTOOLS_FIELDS = {};
28+
INSPECTOR_ID = 'vee-validate-inspector';
29+
COLORS = {
30+
error: 0xbd4b4b,
31+
success: 0x06d77b,
32+
unknown: 0x54436b,
33+
white: 0xffffff,
34+
black: 0x000000,
35+
blue: 0x035397,
36+
purple: 0xb980f0,
37+
orange: 0xf5a962,
38+
gray: 0xbbbfca,
39+
};
40+
SELECTED_NODE = null;
41+
}
42+
3543
async function installDevtoolsPlugin(app: App) {
3644
if (__DEV__) {
3745
if (!isClient) {
3846
return;
3947
}
4048

41-
const devtools = await import('@vue/devtools-api');
49+
const devtools = await import(/* @vite-ignore */ '@vue/devtools-api');
4250
devtools.setupDevtoolsPlugin(
4351
{
4452
id: 'vee-validate-devtools-plugin',
@@ -167,13 +175,15 @@ async function installDevtoolsPlugin(app: App) {
167175
}
168176
}
169177

170-
export const refreshInspector = throttle(() => {
171-
setTimeout(async () => {
172-
await nextTick();
173-
API?.sendInspectorState(INSPECTOR_ID);
174-
API?.sendInspectorTree(INSPECTOR_ID);
175-
}, 100);
176-
}, 100);
178+
export const refreshInspector = __DEV__
179+
? throttle(() => {
180+
setTimeout(async () => {
181+
await nextTick();
182+
API?.sendInspectorState(INSPECTOR_ID);
183+
API?.sendInspectorTree(INSPECTOR_ID);
184+
}, 100);
185+
}, 100)
186+
: () => {};
177187

178188
export function registerFormWithDevTools(form: PrivateFormContext) {
179189
if (!__DEV__ || !isClient) {

0 commit comments

Comments
 (0)