Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-4972-devtools-production.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vee-validate": patch
---

Fix Vue Devtools code being included in production builds (#4972)
60 changes: 35 additions & 25 deletions packages/vee-validate/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,49 @@ import { PathState, PrivateFieldContext, PrivateFormContext } from './types';
import { isClient, keysOf, setInPath, throttle } from './utils';
import { isObject } from '../../shared';

const DEVTOOLS_FORMS: Record<string, PrivateFormContext & { _vm?: ComponentInternalInstance | null }> = {};
const DEVTOOLS_FIELDS: Record<string, PrivateFieldContext & { _vm?: ComponentInternalInstance | null }> = {};

const INSPECTOR_ID = 'vee-validate-inspector';

const COLORS = {
error: 0xbd4b4b,
success: 0x06d77b,
unknown: 0x54436b,
white: 0xffffff,
black: 0x000000,
blue: 0x035397,
purple: 0xb980f0,
orange: 0xf5a962,
gray: 0xbbbfca,
};
let DEVTOOLS_FORMS: Record<string, PrivateFormContext & { _vm?: ComponentInternalInstance | null }>;
let DEVTOOLS_FIELDS: Record<string, PrivateFieldContext & { _vm?: ComponentInternalInstance | null }>;

let INSPECTOR_ID: string;

let COLORS: Record<string, number>;

let SELECTED_NODE:
| { type: 'pathState'; form: PrivateFormContext; state: PathState }
| { type: 'form'; form: PrivateFormContext & { _vm?: ComponentInternalInstance | null } }
| { type: 'field'; field: PrivateFieldContext & { _vm?: ComponentInternalInstance | null } }
| null = null;
| null;

/**
* Plugin API
*/
let API: any;

if (__DEV__) {
DEVTOOLS_FORMS = {};
DEVTOOLS_FIELDS = {};
INSPECTOR_ID = 'vee-validate-inspector';
COLORS = {
error: 0xbd4b4b,
success: 0x06d77b,
unknown: 0x54436b,
white: 0xffffff,
black: 0x000000,
blue: 0x035397,
purple: 0xb980f0,
orange: 0xf5a962,
gray: 0xbbbfca,
};
SELECTED_NODE = null;
}

async function installDevtoolsPlugin(app: App) {
if (__DEV__) {
if (!isClient) {
return;
}

const devtools = await import('@vue/devtools-api');
const devtools = await import(/* @vite-ignore */ '@vue/devtools-api');
devtools.setupDevtoolsPlugin(
{
id: 'vee-validate-devtools-plugin',
Expand Down Expand Up @@ -167,13 +175,15 @@ async function installDevtoolsPlugin(app: App) {
}
}

export const refreshInspector = throttle(() => {
setTimeout(async () => {
await nextTick();
API?.sendInspectorState(INSPECTOR_ID);
API?.sendInspectorTree(INSPECTOR_ID);
}, 100);
}, 100);
export const refreshInspector = __DEV__
? throttle(() => {
setTimeout(async () => {
await nextTick();
API?.sendInspectorState(INSPECTOR_ID);
API?.sendInspectorTree(INSPECTOR_ID);
}, 100);
}, 100)
: () => {};

export function registerFormWithDevTools(form: PrivateFormContext) {
if (!__DEV__ || !isClient) {
Expand Down
Loading