Skip to content

2.0.0: useLaravelErrors() for Vue 3 and vee-validate 4 - #2

Merged
pmochine merged 14 commits into
masterfrom
v2-2026-10
Oct 8, 2026
Merged

pmochine merged 14 commits into
masterfrom
v2-2026-10

Conversation

@pmochine

@pmochine pmochine commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Summary

Version 2.0.0 for Vue 3 and vee-validate 4. This branch builds on #1 (1.0.7), so this pull request also shows the commits of #1 until #1 is merged. Merge #1 first.

Why a version 2

vee-validate 4 has setErrors, but it replaces the errors of a field each time it validates the field. With the default configuration this happens on blur, so a server error such as "The email has already been taken." goes away when the user only leaves the field. This happens with field rules, without rules and with a zod schema. Users reported it in logaretm/vee-validate#4018, logaretm/vee-validate#4436 and logaretm/vee-validate#4865. The maintainer leaves the decision ("until when?") to the app. No package on npm connects vee-validate 4 with Laravel.

What is new

  • useLaravelErrors(form?) keeps each Laravel error until the user changes the value of its field, or until the next submit. The field stays invalid until then.
  • laravel.handleSubmit(callback) works like handleSubmit() of vee-validate and shows a Laravel 422 error that the callback throws. The errors belong to the values of the request. The response of an older submit is ignored. The callback gets setLaravelErrors() for Inertia and fetch.
  • laravel.set(source), laravel.clear() and the read-only laravel.errors.
  • The next submit and resetForm() remove all server errors of the previous response, also errors for keys without a field.
  • An error does not move to another row when the user removes or moves a row of an array.
  • getLaravelErrors(source) reads axios errors and responses, ofetch ($fetch) errors, the JSON body and { errors } from Inertia.
  • TypeScript types, an ES module and a UMD build, exports with types for import and require.

Breaking changes

  • The Vue 2 plugin and $addLaravelErrors are removed. The README has a migration table.
  • Peer dependencies: Vue 3.3 or newer, vee-validate 4.12 or newer.
  • Each field has a list of messages instead of a joined string.
  • Laravel keys such as users.0.name become vee-validate paths such as users[0].name.

Tooling

  • Vite 8 library build, Vitest 5 with jsdom 30, type tests with TypeScript 7, ESLint 9 with eslint-config-avidofood 4.
  • CI on Node 22, 24 and 26. .nvmrc selects Node 24.21.0.
  • .github/workflows/release.yml for npm trusted publishing, copied unchanged from vue-responsive-video-background-player.

Checks

  • 57 tests and the type tests pass with vee-validate 4.15.1 and Vue 3.5, and with vee-validate 4.12.0 and Vue 3.3.13.
  • Regression tests fail with the code before each fix. Mutation checks of each fix make at least one test fail.
  • npm pack: 7 files, identical to the build. Tarball tests in an empty folder: import, require, a test against dist, a Vite 8 build, and tsc as a consumer (node16 ES module and CommonJS, bundler) with TypeScript 5.9 and 7.
  • @arethetypeswrong/cli: no problems. publint: only the engines.node suggestion (browser library).
  • Independent review by Codex (gpt-6-astra): one full round (red, all findings fixed with tests), then two short rounds over the fixes. Final verdict green. The tooling commits and release.yml came later and have CI as their check.

Before the release

  1. Merge and publish 1.0.7: fix errors stored under key, restore the license, document setErrors #1 (1.0.7) first. Otherwise npm sets latest to 1.0.7.
  2. Create the branch 1x. The README of 2.0.0 links to it.
  3. Set up the environment npm-publish and the trusted publisher on npmjs.com, then push the tag 2.0.0.
  4. Deprecate the 1.x line: npm deprecate @pmochine/vee-validate-laravel@"<2.0.0" "...".

This pull request stays a draft until #1 is merged and released.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA

pmochine and others added 14 commits October 7, 2026 16:26
vee-validate 4 has setErrors, but it replaces the errors of a field
each time it validates the field, for example on blur. So a server
error goes away although the value did not change (vee-validate
issues #4018, #4436, #4865). Errors for keys without a field stay
after a submit and after resetForm().

useLaravelErrors(form?) sets the errors of a Laravel 422 response and
keeps each one until the user changes the value of its field. The
next submit, or resetForm() after a submit, removes all of them. A
value that changed while the request ran gets no error. A watcher with
the default flush puts the messages back after vee-validate validated
and before the component renders, so nothing flickers.

getLaravelErrors(source) reads the errors from an axios error or
response, an ofetch error, the JSON body or an object with an errors
key, and turns users.0.name into users[0].name.

This replaces the Vue 2 plugin. The build follows the pattern of
vue-responsive-video-background-player: Vite 8 library mode (ES module
and UMD), hand-written types, exports with types, prepack. Tests with
Vitest pass with vee-validate 4.15.1 and with 4.12.0 on Vue 3.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
The README explains the problem with setErrors alone, shows the use
with axios, $fetch, Inertia, fetch and <Form>, describes when a server
error goes away, and has a migration table from 1.x. It also says
when setErrors alone is enough. The CHANGELOG lists the additions and
the breaking changes of 2.0.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
Version 2 has a new API for Vue 3 and vee-validate 4 and removes the
Vue 2 plugin, so it is a major version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
vee-validate ships ES module types only. With "module": "node16" and
skipLibCheck off, TypeScript rejected the type import in index.d.ts for
CommonJS projects (TS1541). LaravelErrorsForm is now a structural
interface, and useForm() results still match it.

The package has no side effects, so "sideEffects": false lets bundlers
drop unused exports (publint suggestion).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
Fixes the findings of the Codex Astra review of 2.0.0:

- laravel.handleSubmit() wraps handleSubmit() of vee-validate. It
  takes a snapshot of the values when the callback starts, shows a
  Laravel 422 error that the callback throws, and ignores the response
  of an older submit. The callback gets setLaravelErrors() for Inertia
  and fetch. set() now uses the current values (1).
- After a silent validation, for example from useFieldArray().push(),
  the field stays invalid while its server error shows (2).
- The package owns the error list it wrote, checked by identity, not
  by text. A client error with the same text stays on clear() (3).
- Errors of array rows also compare the identity of the row object, so
  an error does not move to another row after remove() (4).
- resetForm() always removes the server errors. vee-validate assigns
  new initial values only in resetForm() (5).
- All calls for one form share one state. When the last component
  that uses it unmounts, its server errors go away (6).
- Dates in the snapshot are copies (7).
- The watcher reads only the paths with an active server error (8).
- getLaravelErrors() rejects a list as errors and keeps a key named
  __proto__ as a normal key (10).
- The tests wait for the 5 ms debounce of vee-validate (11).
- The types make the message lists read-only (13).

Each fix has a test. 13 of the new tests fail with the old code, the
other one guards against dropping errors too often. Mutation checks of
each fix make at least one test fail. 51 tests pass with vee-validate
4.15.1 and with 4.12.0 on Vue 3.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
- The README uses laravel.handleSubmit() in all examples and explains
  setLaravelErrors() for Inertia and fetch, and set() for other code.
- It says when a server error goes away, also on unmount, and what
  set() and setLaravelErrors() return (finding 12).
- The baseline is described exactly: vee-validate alone keeps errors
  of keys without a field only without a validation schema, and blur
  removes server errors also with a zod schema.
- Things to know: replace Date values, and pass the form when an app
  mixes ES modules and require() (finding 9).
- The CHANGELOG lists the new parts of 2.0.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
matchAll() is ES2020, but the build targets ES2019, and Vite does not
add missing functions. In a browser without matchAll(), set() threw a
TypeError for an indexed path such as users.0.name. rowPaths() now
uses replace() with a callback. A test removes matchAll() and fails
with the previous code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
…once

Fixes the two findings of the short Codex review of the fixes:

- laravel.handleSubmit() took the request generation when the
  callback started. Two submits whose client validations overlapped
  got the same generation, so the late response of the older one
  showed stale errors, and clear() during the validation had no
  effect. Each call now creates its own vee-validate handler and
  takes the generation right after vee-validate counted up the
  submit, before the validation. The value snapshot still comes from
  the start of the callback.
- The reset watcher ran one tick late, so set() right after
  resetForm() lost its errors. It now watches the initialValues ref
  synchronously.

Five new tests: an older submit in the same tick, overlapping client
validations, clear() during the validation, set() after resetForm()
in the same tick, and onInvalid. The first four fail with the
previous code. 57 tests pass with vee-validate 4.15.1 and 4.12.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
Copied unchanged from vue-responsive-video-background-player (master,
commits 810fc8f and 8763249). A version tag such as 2.0.0 on master
starts the workflow: the verify job runs npm ci, lint, the tests and
npm pack --dry-run without an OIDC token. The publish job in the
environment npm-publish checks the tag again, installs with
npm ci --ignore-scripts and runs npm publish, which builds dist/ in
prepack. A manual run on master only checks the trusted publisher.

Checked in a fresh clone: npm ci --ignore-scripts, then npm pack
--dry-run builds dist/ and packs the same 7 files. The package was
public before, and npm publish keeps the access of an existing
package, so package.json needs no publishConfig.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
jsdom 30 needs Node.js ^22.22.2, ^24.15.0 or >=26. .nvmrc selects
Node 24.21.0, and CI adds Node 26. setup-node takes the newest
release of each line, so 22 and 24 meet the minimum. The CHANGELOG
lists the new requirement of the development tools. The published
files do not change.

Lint, 57 tests, the type checks and npm pack pass on Node 24.21.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
TypeScript 7.0.2 runs the type tests in tests/types without changes.
A removed @ts-expect-error makes tsc fail, so the checks still work.
The published types also pass with TypeScript 7 as a consumer, with
node16 (ES module and CommonJS) and bundler resolution. The build
uses Vite and no TypeScript, and the package uses no vue-tsc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
eslint-config-avidofood 5 needs ESLint 10 and uses
eslint-plugin-import-x, with the same import/ rule names.
package.json did not list eslint-plugin-import itself, and
eslint.config.mjs stays the same. ESLint 10 needs Node.js ^20.19,
^22.13 or >=24, which the CI versions 22, 24 and 26 meet.

The lint result does not change: 5 files, no errors, no warnings,
as with ESLint 9. The CHANGELOG names the new lint tools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
master has the merge commit of pull request #1. Its tree equals
1.0.7 (a4e193f), which this branch already contains, so no file
changes. After this merge, pull request #2 only shows 2.0.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEDv3tsdEL7sjLdisXuVHA
@pmochine
pmochine marked this pull request as ready for review October 8, 2026 08:25
@pmochine
pmochine merged commit 3d74e0e into master Oct 8, 2026
3 checks passed
@pmochine
pmochine deleted the v2-2026-10 branch October 8, 2026 11:31
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.

1 participant