Skip to content

feat: support validation in synchronous code paths - #158

Merged
thetutlage merged 2 commits into
4.xfrom
feat/synchronous-validation
Oct 16, 2026
Merged

thetutlage merged 2 commits into
4.xfrom
feat/synchronous-validation

Conversation

@RomainLanz

Copy link
Copy Markdown
Member

Vine currently always returns a Promise, which prevents its use in code paths that require a synchronous result.

This adds validateSync() and tryValidateSync() to validators and the vine shortcuts. Synchronous compilation happens on first use and is cached. Existing async APIs and Standard Schema behavior remain unchanged. Requires @vinejs/compiler@4.2.0.

Performance

This is not a performance optimization. Synchronous rules were already compiled into direct calls without await. The main benefit is using Vine where returning or awaiting a Promise is not possible.

A registration benchmark with email, username and password rules showed similar performance: 2.41–2.48 µs async versus 2.31–2.42 µs sync. Sample ranges overlap, so no substantial gain is established.

Checks

Runtime and type tests, lint, typecheck and build pass. Independent reviews by Sol 6.1 and Claude Code Opus found no runtime defects.

Use the published compiler, strengthen metadata and messages-provider coverage, and add a registration benchmark comparing async and sync validation.
@thetutlage

Copy link
Copy Markdown
Contributor

Looks good. Should we update the docs too?

@RomainLanz

Copy link
Copy Markdown
Member Author

Done: vinejs/vinejs.dev#55

@thetutlage
thetutlage merged commit 17f9ea9 into 4.x Oct 16, 2026
12 checks passed
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.

2 participants