Skip to content

Improve Next.js tree shaking #4569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 30, 2025
Merged

Improve Next.js tree shaking #4569

merged 3 commits into from
May 30, 2025

Conversation

colinhacks
Copy link
Owner

@colinhacks colinhacks commented May 30, 2025

Closes #4433

Notes on the fixes:

  • Pieces of each locale were getting loaded. Not the whole error map though, just some top-level objects used for word mapping. In fact all top-level objects in the codebase (exported or not) would always get bundled. In the case of locales this was fixed by declaring these as intermediates inside an "error function factory".
  • Various constructed regexes were not marked with @__PURE__.
  • The z.stringbool APIs were bound versions of the Zod Core _stringbool factory, which apparently wasn't shaking. This pulled in the implementations of $ZodUnknown, $ZodBoolean, and $ZodPipe.
  • The fact that $ZodFunction class has methods that return instances of itself threw Webpack for a loop. Dodged this with new inst.constructor().

@colinhacks colinhacks changed the title Fix package.json Improve Next.js tree shaking May 30, 2025
@colinhacks colinhacks merged commit 670a6d2 into main May 30, 2025
4 checks passed
@colinhacks colinhacks deleted the improve-treeshaking-next branch May 30, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v4: Next.js treeshaking
1 participant