Skip to content

Commit 0d87aa4

Browse files
committed
Make id lazy
1 parent ed933d9 commit 0d87aa4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/zod/src/v4/core/schemas.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ export interface _$ZodType<T extends $ZodTypeInternals = $ZodTypeInternals>
171171

172172
export const $ZodType: core.$constructor<$ZodType> = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def) => {
173173
inst ??= {} as any;
174-
inst._zod.id = def.type + "_" + util.randomString(10);
174+
// avoids issues with using Math.random() in Next.js caching
175+
util.defineLazy(inst._zod, "id", () => def.type + "_" + util.randomString(10));
175176
inst._zod.def = def; // set _def property
176177
inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
177178
inst._zod.version = version;

0 commit comments

Comments
 (0)