feat(schema)!: replace zod with valibot - #8
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4
Why
parseDemo()runs in the host app on every demo load, so the schema library's size and parse cost are paid by every site that embeds a demo.Evaluation
The same schema was written in each library. All four were checked against 24 cases (20 invalid inputs and 4 valid ones, including a real
steps.json) and give the same results, except that ArkType acceptsInfinity. Measured on the realsteps.json(6 steps):zod/miniLoad and first parse are medians of 30 fresh processes. Warm parse doesn't matter here: the demo is parsed once per page.
player-coreitself is 29 KB, so the total download for an embed drops by about 40%.new Function("")probe for its JIT, which fires asecuritypolicyviolationreport on sites with a strict CSP. Valibot uses no eval.Changes
packages/schema/src/index.ts: schemas rewritten with Valibot, with the same rules.v.finite()keeps rejectingInfinity, as Zod did.DemoParseError, thrown byparseDemo()instead of the library's error. It's anErrorwithissues: { path, message }[](e.g.path: "steps.1.hotspot.x"), so the validator can change again without breaking the public API.parse-demo.test.ts, 27 tests). The validation rules were pinned against Zod first, then the suite stayed green through the switch unchanged.tsconfig.build.jsonkeeps tests out ofdist/, as inexporter.zod@4.6.5→valibot@1.5.0. Configs, comments, READMEs andCLAUDE.mdfiles updated.Breaking changes
parseDemo()throwsDemoParseErrorinstead ofZodError.*Schemavalues are Valibot schemas instead of Zod schemas. Nothing in the repo uses them.Demo,Step, …) andparseDemo()'s signature are unchanged.No changeset in this PR: it will be added later together with the other pending changes.
Checks
biome ci, build,check-types,sizeand the tests of every package pass.