Skip to content

Commit 56663aa

Browse files
committed
fix: use ssr safe file check
1 parent d6fe4ba commit 56663aa

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

packages/vee-validate/src/utils/assertions.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Locator, YupValidator } from '../types';
22
import { isCallable, isObject } from '../../../shared';
33
import { IS_ABSENT } from '../symbols';
44

5+
export const isClient = typeof window !== 'undefined';
6+
57
export function isLocator(value: unknown): value is Locator {
68
return isCallable(value) && !!(value as Locator).__locatorRef;
79
}
@@ -142,7 +144,7 @@ export function isEqual(a: any, b: any) {
142144

143145
// We added this part for file comparison, arguably a little naive but should work for most cases.
144146
// #3911
145-
if (a instanceof File && b instanceof File) {
147+
if (isFile(a) && isFile(b)) {
146148
if (a.size !== b.size) return false;
147149
if (a.name !== b.name) return false;
148150
if (a.lastModified !== b.lastModified) return false;
@@ -189,3 +191,11 @@ export function isEqual(a: any, b: any) {
189191
// eslint-disable-next-line no-self-compare
190192
return a !== a && b !== b;
191193
}
194+
195+
export function isFile(a: unknown): a is File {
196+
if (!isClient) {
197+
return false;
198+
}
199+
200+
return a instanceof File;
201+
}

0 commit comments

Comments
 (0)