Skip to content

Conversation

tobigumo
Copy link
Contributor

Overview

This PR modifies our existing zod4Resolver to work with both standard zod/v4 and zod/v4-mini by implementing the approach recommended in the Zod documentation for library authors.

Changes

  • Changed import from zod/v4 to zod/v4/core to access the shared core API
  • Replaced safeParse with z.parse in try/catch block since safeParse is not available in the core API
  • Created a new test file zod-resolver-v4-mini.test.ts using zod/v4-mini schema style to verify compatibility

@tobigumo tobigumo force-pushed the feat/support-zod-v4-mini branch from c8325c1 to 99629f5 Compare May 27, 2025 12:10
@tobigumo tobigumo force-pushed the feat/support-zod-v4-mini branch from 99629f5 to 237239f Compare May 27, 2025 12:10
@rtivital rtivital requested a review from Copilot June 17, 2025 09:31
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the existing zod4Resolver to use Zod’s shared core API so it works with both zod/v4 and zod/v4-mini, adds compatibility tests, and bumps the GitHub Actions cache action version.

  • Switched imports in zod-resolver.ts to use zod/v4/core and rewrote zod4Resolver to use parse/$ZodError in a try/catch.
  • Added a new test file zod-resolver-v4-mini.test.ts to validate use with zod/v4-mini schemas.
  • Updated .github/workflows/pull_request.yml to use actions/cache@v4.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/zod-resolver.ts Changed import to core API, replaced safeParse logic with parse/catch
src/zod-resolver-v4-mini.test.ts New tests to verify zod4Resolver compatibility with zod/v4-mini
.github/workflows/pull_request.yml Bumped cache action from v2 to v4
Comments suppressed due to low confidence (3)

src/zod-resolver.ts:51

  • Add a unit test to verify that non-$ZodError exceptions are rethrown by zod4Resolver, ensuring unexpected errors aren’t swallowed by the resolver.
throw error; // rethrow if it's not a ZodError

.github/workflows/pull_request.yml:24

  • [nitpick] Consider adding a restore-keys fallback to the cache step (e.g., restore-keys: ${{ runner.os }}-yarn-) to improve cache hit rates when the primary key doesn’t match.
uses: actions/cache@v4

const results: FormErrors = {};

if (options?.errorPriority === 'first') {
error.issues.reverse();
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid mutating the original error.issues array. Instead, create a shallow copy before reversing (e.g. const issues = [...error.issues].reverse()) to prevent side effects on subsequent validations.

Suggested change
error.issues.reverse();
const reversedIssues = [...error.issues].reverse();
error.issues = reversedIssues;

Copilot uses AI. Check for mistakes.

@rtivital rtivital merged commit c961fe4 into mantinedev:master Jun 17, 2025
1 check passed
@rtivital
Copy link
Member

Thanks!

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