Skip to content
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

Misleading example in docs / readme #952

Closed
thoughtspile opened this issue Dec 2, 2024 · 5 comments
Closed

Misleading example in docs / readme #952

thoughtspile opened this issue Dec 2, 2024 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@thoughtspile
Copy link

thoughtspile commented Dec 2, 2024

Hi there, and thanks for the wonderful library! I noticed a few issues with the first code example as seen in readme and the docs:

import * as v from 'valibot'; // 1.24 kB

const LoginSchema = v.object({
  email: v.pipe(v.string(), v.email()),
  password: v.pipe(v.string(), v.minLength(8)),
});
  1. The total bundle size is closer to 10 kB, not 1.24: https://bundlejs.com/?q=valibot&treeshake=%5B*%5D
  2. The practcal size for most use cases would be under 2 kB, but to get there you'd need to use named imports.

I think it'd be best to write the example with named imports to encourage optimal usage:

import { object, pipe, string, email, minLength } from 'valibot'; // 1.17 kB

Alternatively, we could update the example with the current full-bundle size, or remove the kB size altogether.

Which option would you prefer?

@fabian-hiller
Copy link
Owner

Hey 👋 thank you for reaching out!

The total bundle size is closer to 10 kB, not 1.24

This is not true. Please paste the entire code into bundlejs.com and click build to verify.

The practcal size for most use cases would be under 2 kB, but to get there you'd need to use named imports.

No, there is no difference between wildcard and named imports when it comes to tree shaking.

@fabian-hiller fabian-hiller self-assigned this Dec 2, 2024
@fabian-hiller fabian-hiller added the question Further information is requested label Dec 2, 2024
@fabian-hiller
Copy link
Owner

Should I close this issue?

@HugeLetters
Copy link

HugeLetters commented Dec 6, 2024

These are the results I get
image

I think there's a misunderstanding - it's a bit ambiguous if the initial example implies library total bundle size (it's around ~10kb gzipped) or only size of the actually used functions(around ~1.25kb).

In practice this specific code example with most modern bundlers would result in ~1.25kb bundle - it's just that the phrasing is unclear if using more validators would increase this value and it's not the size of the whole library.

@fabian-hiller
Copy link
Owner

What exactly should I change?

@thoughtspile
Copy link
Author

OK @fabian-hiller my bad, import syntax does not indeed affect bundle size (unless you materialize the namespace object by doing this.validation = valibot etc). Sorry for bothering =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants