Repository navigation
2.0.0: useLaravelErrors() for Vue 3 and vee-validate 4 - #2
Merged
Merged
Conversation
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
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.
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 onblur, 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 likehandleSubmit()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 getssetLaravelErrors()for Inertia andfetch.laravel.set(source),laravel.clear()and the read-onlylaravel.errors.resetForm()remove all server errors of the previous response, also errors for keys without a field.getLaravelErrors(source)reads axios errors and responses, ofetch ($fetch) errors, the JSON body and{ errors }from Inertia.exportswith types forimportandrequire.Breaking changes
$addLaravelErrorsare removed. The README has a migration table.users.0.namebecome vee-validate paths such asusers[0].name.Tooling
.nvmrcselects Node 24.21.0..github/workflows/release.ymlfor npm trusted publishing, copied unchanged from vue-responsive-video-background-player.Checks
npm pack: 7 files, identical to the build. Tarball tests in an empty folder:import,require, a test againstdist, a Vite 8 build, andtscas a consumer (node16 ES module and CommonJS, bundler) with TypeScript 5.9 and 7.@arethetypeswrong/cli: no problems. publint: only theengines.nodesuggestion (browser library).release.ymlcame later and have CI as their check.Before the release
latestto 1.0.7.1x. The README of 2.0.0 links to it.npm-publishand the trusted publisher on npmjs.com, then push the tag2.0.0.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