Skip to content

fix: cleanup _idmap of $ZodRegistry - #4837

Merged
colinhacks merged 2 commits into
colinhacks:mainfrom
safareli:patch-2
Jul 7, 2025
Merged

fix: cleanup _idmap of $ZodRegistry#4837
colinhacks merged 2 commits into
colinhacks:mainfrom
safareli:patch-2

Conversation

@safareli

@safareli safareli commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@safareli

safareli commented Jul 7, 2025

Copy link
Copy Markdown
Contributor Author

shouldn't _idmap: Map<string, Schema> = new Map(); be WeakMap too? otherwise presense of id in meta results in strong pointer of Schema to be created which means it will not be removed from the _map ever even if there are no strong pointers to Schema from outside of this class thus creating mem leak potential.

@colinhacks

Copy link
Copy Markdown
Owner

You're correct. Unfortunately registries need to be iterable for z.toJSONSchema() as implemented (this is why CI is failing), and the fact that it's using WeakRef for the schema map is a bit of a vestige of an older implementation. I think I'll be switching to a plain Map and adding a .clear() method. It's not ideal, but honestly I think a true WeakMap implementation would also cause a lot of mysterious issues for people who don't understand how they work. Regardless, merging this fix 👍 Thank you.

@colinhacks
colinhacks merged commit 91c9ca6 into colinhacks:main Jul 7, 2025
3 of 4 checks passed
vaernion pushed a commit to Arbeidstilsynet/brevgen2 that referenced this pull request Dec 3, 2025
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [zod](https://zod.dev) ([source](https://github.com/colinhacks/zod)) | [`3.24.4` -> `3.25.76`](https://renovatebot.com/diffs/npm/zod/3.24.4/3.25.76) | [![age](https://developer.mend.io/api/mc/badges/age/npm/zod/3.25.76?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/zod/3.25.76?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/zod/3.24.4/3.25.76?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/zod/3.24.4/3.25.76?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>colinhacks/zod (zod)</summary>

### [`v3.25.76`](https://github.com/colinhacks/zod/releases/tag/v3.25.76)

[Compare Source](colinhacks/zod@v3.25.75...v3.25.76)

##### Commits:

- [`91c9ca6`](colinhacks/zod@91c9ca6) fix: cleanup \_idmap of $ZodRegistry ([#&#8203;4837](colinhacks/zod#4837))
- [`9cce1c5`](colinhacks/zod@9cce1c5) docs: fix typo in flattenError example on error-formatting page ([#&#8203;4819](colinhacks/zod#4819)) ([#&#8203;4833](colinhacks/zod#4833))
- [`a3560ae`](colinhacks/zod@a3560ae) v3.25.76 ([#&#8203;4838](colinhacks/zod#4838))
- [`5060661`](colinhacks/zod@5060661) Release 3.25.76
- [`7baee4e`](colinhacks/zod@7baee4e) Update index.mdx ([#&#8203;4831](colinhacks/zod#4831))

### [`v3.25.75`](https://github.com/colinhacks/zod/releases/tag/v3.25.75)

[Compare Source](colinhacks/zod@v3.25.74...v3.25.75)

##### Commits:

- [`c5f349b`](colinhacks/zod@c5f349b) Fix z.undefined() behavior in toJSONSchema

### [`v3.25.74`](https://github.com/colinhacks/zod/releases/tag/v3.25.74)

[Compare Source](colinhacks/zod@v3.25.73...v3.25.74)

##### Commits:

- [`ae0dbe1`](colinhacks/zod@ae0dbe1) Partial record
- [`39c5f71`](colinhacks/zod@39c5f71) 3.25.74

### [`v3.25.73`](https://github.com/colinhacks/zod/releases/tag/v3.25.73)

[Compare Source](colinhacks/zod@v3.25.72...v3.25.73)

##### Commits:

- [`1021d3c`](colinhacks/zod@1021d3c230d41d600698...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants