Skip to content

fix(typeschema): preserve path-less validation issues - #898

Open
clean99 wants to merge 1 commit into
react-hook-form:masterfrom
clean99:contrib/resolvers-typeschema-pathless-errors
Open

clean99 wants to merge 1 commit into
react-hook-form:masterfrom
clean99:contrib/resolvers-typeschema-pathless-errors

Conversation

@clean99

@clean99 clean99 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

  • Preserve issues whose optional path is absent. Valibot object-level checks emit these through Standard Schema; typeschemaResolver currently drops them, so trigger() returns true and handleSubmit calls the success handler with {} for invalid input.
  • Use the empty key, matching this adapter's existing behavior for path: [] and the fixes in fix(valibot): report object-level issues on the empty path #893 and fix(arktype): report object-level issues on the empty path #895. Nonempty path conversion is unchanged. Using errors.root instead would not block submission because react-hook-form clears it before checking for errors.
  • Add a real-provider regression covering the resolver result, registered fields, rejected submission and recovery after correcting the value.

Reproduction against parent commit e02dcd623ca915f35e5c418f5384f4732bafa925, using the built checkout with Valibot 1.0.0-beta.12 and react-hook-form 7.83.0 from its lockfile:

import { typeschemaResolver } from '@hookform/resolvers/typeschema';
import * as v from 'valibot';

const schema = v.pipe(
  v.object({ list: v.array(v.string()), length: v.number() }),
  v.check(input => input.list.length === input.length, 'The list does not match the length.'),
);
const result = await typeschemaResolver(schema)(
  { list: ['one'], length: 2 }, undefined,
  { fields: {}, shouldUseNativeValidation: false },
);
console.log(result.errors); // Before: {}. After: { '': { message: 'The list does not match the length.', type: '', ref: undefined } }.

bun run test typeschema/src/__tests__/typeschema.ts fails without the source fix and passes with it. bun lint, bun lint:types, bun run test (364 tests) and bun run build pass. Also checked repeated validation, reset, sync/async providers, criteriaMode, raw/transformed output and packed CommonJS/ESM consumers.

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