Client bundle size increase 4.5kb from 1.3.34 to 1.4.0 #2361

Closed
opened 2026-03-13 09:47:04 -05:00 by GiteaMirror · 12 comments
Owner

Originally created by @kevinmarrec on GitHub (Nov 22, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  • Vite build with 1.3.34
Image
  • Vite build with 1.4.0
Image

No code change between, only dependency upgrade.

Current vs. Expected behavior

4.5kb bundle size growth for minor version upgrade is kind of expensive.

I'm not using the new features, so I'm expecting things to be tree-shakable, somehow.

There is guidelines in the Better Auth documentation about server optimizations (https://www.better-auth.com/docs/guides/optimizing-for-performance#bundle-size-optimization) , but none for client side.

What version of Better Auth are you using?

1.4.0

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025",
    "release": "6.6.87.2-microsoft-standard-WSL2",
    "cpuCount": 24,
    "cpuModel": "13th Gen Intel(R) Core(TM) i7-13700K",
    "totalMemory": "15.49 GB",
    "freeMemory": "12.91 GB"
  },
  "node": {
    "version": "v24.11.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.1"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

import { createAuthClient } from 'better-auth/vue'

const authClient = createAuthClient({
  baseURL: `${import.meta.env.VITE_API_URL}/auth`,
  fetchOptions: {
    credentials: 'include',
  },
})

Additional context

No response

Originally created by @kevinmarrec on GitHub (Nov 22, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce - Vite build with 1.3.34 <img width="533" height="260" alt="Image" src="https://github.com/user-attachments/assets/e33f2676-ef49-4892-ae65-461bf2f2b00c" /> - Vite build with 1.4.0 <img width="546" height="278" alt="Image" src="https://github.com/user-attachments/assets/37ba40d1-571f-4977-bfea-0276964c63fa" /> No code change between, only dependency upgrade. ### Current vs. Expected behavior 4.5kb bundle size growth for minor version upgrade is kind of expensive. I'm not using the new features, so I'm expecting things to be tree-shakable, somehow. There is guidelines in the Better Auth documentation about server optimizations (https://www.better-auth.com/docs/guides/optimizing-for-performance#bundle-size-optimization) , but none for client side. ### What version of Better Auth are you using? 1.4.0 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025", "release": "6.6.87.2-microsoft-standard-WSL2", "cpuCount": 24, "cpuModel": "13th Gen Intel(R) Core(TM) i7-13700K", "totalMemory": "15.49 GB", "freeMemory": "12.91 GB" }, "node": { "version": "v24.11.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.1" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { createAuthClient } from 'better-auth/vue' const authClient = createAuthClient({ baseURL: `${import.meta.env.VITE_API_URL}/auth`, fetchOptions: { credentials: 'include', }, }) ``` ### Additional context _No response_
GiteaMirror added the javascript label 2026-03-13 09:47:04 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 22, 2025):

Hi there, thanks for opening this issue. We’re aware that version 1.4.0 shows an approximate 4.5kb increase compared to 1.3.34, and while we strive to keep the client bundle as lean as possible, some new internal dependencies and improvements have contributed to the growth. If you’re not using the new features, you might want to ensure you’re importing only what you need to maximize tree-shaking. Although our documentation currently covers server optimizations, we appreciate your feedback regarding client-side guidelines and will look into providing more explicit advice in future updates.

Could you let us know if you’re experiencing any specific issues related to performance or if there are particular parts of the bundle you suspect might be optimized further? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 22, 2025): Hi there, thanks for opening this issue. We’re aware that version 1.4.0 shows an approximate 4.5kb increase compared to 1.3.34, and while we strive to keep the client bundle as lean as possible, some new internal dependencies and improvements have contributed to the growth. If you’re not using the new features, you might want to ensure you’re importing only what you need to maximize tree-shaking. Although our documentation currently covers server optimizations, we appreciate your feedback regarding client-side guidelines and will look into providing more explicit advice in future updates. Could you let us know if you’re experiencing any specific issues related to performance or if there are particular parts of the bundle you suspect might be optimized further? Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@Bekacru commented on GitHub (Nov 22, 2025):

You're not using any plugins right?

@Bekacru commented on GitHub (Nov 22, 2025): You're not using any plugins right?
Author
Owner

@kevinmarrec commented on GitHub (Nov 22, 2025):

@Bekacru No plugins indeed

@kevinmarrec commented on GitHub (Nov 22, 2025): @Bekacru No plugins indeed
Author
Owner

@jcramb commented on GitHub (Jan 2, 2026):

BetterAuth seems to bundle in all of the zod locales from zod/v4/locales/index.js - could that be the issue here? Found this while investigating BetterAuth as a noticeable contributor to my bundle size also.

@jcramb commented on GitHub (Jan 2, 2026): BetterAuth seems to bundle in all of the zod locales from zod/v4/locales/index.js - could that be the issue here? Found this while investigating BetterAuth as a noticeable contributor to my bundle size also.
Author
Owner

@miikka-laakso-dh commented on GitHub (Feb 13, 2026):

yes, zod locales increase bundle size significantly (nextjs, turbopack) Image

@miikka-laakso-dh commented on GitHub (Feb 13, 2026): yes, zod locales increase bundle size significantly (nextjs, turbopack) <img width="1003" height="463" alt="Image" src="https://github.com/user-attachments/assets/074e0104-beaa-4cc5-8d63-75fd22f78c06" />
Author
Owner

@Escapado commented on GitHub (Feb 14, 2026):

Got the same problem as @jcramb and @miikka-laakso-dh . Bundle Analyzer shows this:

498.97 KB uncompressed
About 168.71 KBcompressed
67 modules

Just from using the useSession Hook from my auth client:

import { createAuthClient } from "better-auth/react";
import { anonymousClient } from "better-auth/client/plugins";
import { creemClient } from "@creem_io/better-auth/client";

export const authClient = createAuthClient({
  plugins: [anonymousClient(), creemClient()],
});

export const { signIn, signOut, useSession } = authClient;

type BaseSession = typeof authClient.$Infer.Session;

export type Session = {
  session: BaseSession["session"];
  user: BaseSession["user"] & {
    creemCustomerId?: string | null;
  };
};
@Escapado commented on GitHub (Feb 14, 2026): Got the same problem as @jcramb and @miikka-laakso-dh . Bundle Analyzer shows this: ``` 498.97 KB uncompressed About 168.71 KBcompressed 67 modules ``` Just from using the useSession Hook from my auth client: ``` import { createAuthClient } from "better-auth/react"; import { anonymousClient } from "better-auth/client/plugins"; import { creemClient } from "@creem_io/better-auth/client"; export const authClient = createAuthClient({ plugins: [anonymousClient(), creemClient()], }); export const { signIn, signOut, useSession } = authClient; type BaseSession = typeof authClient.$Infer.Session; export type Session = { session: BaseSession["session"]; user: BaseSession["user"] & { creemCustomerId?: string | null; }; }; ```
Author
Owner

@jcramb commented on GitHub (Feb 14, 2026):

If there's a willingness to use valibot as your validation library (which tree shakes far better in my experience) I'd be happy to contribute to the PR's to migrate.

@jcramb commented on GitHub (Feb 14, 2026): If there's a willingness to use valibot as your validation library (which tree shakes far better in my experience) I'd be happy to contribute to the PR's to migrate.
Author
Owner

@Bekacru commented on GitHub (Feb 14, 2026):

We'll take a look into migrating from zod to valibot or arktype

@Bekacru commented on GitHub (Feb 14, 2026): We'll take a look into migrating from zod to valibot or arktype
Author
Owner

@heiwen commented on GitHub (Feb 15, 2026):

@Bekacru I looked into alternative validation libraries for my own project before. In practice, the bundle size savings are marginal (~2%, a few hundred lines). And while switching sounds nice on paper, it often backfires: Zod is so widely used that some dependency usually pulls it in anyway — so you end up with two validators, which actually increases overall bundle size.

What matters more IMO is runtime performance, and Zod is currently faster than Valibot in recent benchmarks: https://moltar.github.io/typescript-runtime-type-benchmarks/

That said, locales being bundled definitely sounds like a bug — just unclear whether it’s coming from better-auth, Next.js, or Zod.

@heiwen commented on GitHub (Feb 15, 2026): @Bekacru I looked into alternative validation libraries for my own project before. In practice, the bundle size savings are marginal (~2%, a few hundred lines). And while switching sounds nice on paper, it often backfires: Zod is so widely used that some dependency usually pulls it in anyway — so you end up with two validators, which actually increases overall bundle size. What matters more IMO is runtime performance, and Zod is currently faster than Valibot in recent benchmarks: https://moltar.github.io/typescript-runtime-type-benchmarks/ That said, locales being bundled definitely sounds like a bug — just unclear whether it’s coming from better-auth, Next.js, or Zod.
Author
Owner

@himself65 commented on GitHub (Feb 15, 2026):

I didn't see that in 1.5 beta🤔

@himself65 commented on GitHub (Feb 15, 2026): I didn't see that in 1.5 beta🤔
Author
Owner

@himself65 commented on GitHub (Feb 15, 2026):

We shouldn't have any validate library on the client side. It seems like a bug or sth

@himself65 commented on GitHub (Feb 15, 2026): We shouldn't have any validate library on the client side. It seems like a bug or sth
Author
Owner

@kevinmarrec commented on GitHub (Mar 1, 2026):

@himself65 Is this released in 1.5.0 ?

Better Auth from 1.4.18 to 1.5.0 just added 3kb more frontend side :(

Check https://github.com/kevinmarrec/create-app/pull/146 bundle size diff, I tried to upgrade only Better Auth and it was responsible for 90% of the rise.

@kevinmarrec commented on GitHub (Mar 1, 2026): @himself65 Is this released in 1.5.0 ? Better Auth from **1.4.18** to **1.5.0** just added 3kb more frontend side :( Check https://github.com/kevinmarrec/create-app/pull/146 bundle size diff, I tried to upgrade only Better Auth and it was responsible for 90% of the rise.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2361