Update Zod from v3 to v4 and refactor validation schemas#433
Conversation
🦋 Changeset detectedLatest commit: 7161c86 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughMigrates fdm-app to Zod v4 and updates many Zod schemas to use the v4 error API (replacing Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@fdm-app/app/components/blocks/harvest/schema.tsx`:
- Around line 25-163: The numeric harvest/yield fields (b_lu_yield,
b_lu_yield_fresh, b_lu_yield_bruto, b_lu_dm, b_lu_tarra, b_lu_uww, b_lu_moist
and b_lu_cp) currently use z.int() which fails on string inputs from FormData;
update each schema block to use z.coerce.number().int() (keeping the existing
z.preprocess((val)=> val===""? undefined: val) and the same chained validators
like .positive(), .max(), .min(), .finite(), .optional()) so strings are coerced
to numbers before integer validation—follow the pattern used by
b_lu_n_harvestable for guidance.
In `@fdm-app/app/routes/welcome.tsx`:
- Around line 49-65: The firstname and surname schema entries in FormSchema use
z.coerce.string(), which coerces undefined to "undefined" and bypasses your
undefined checks; change both to use z.string() instead (preserve the existing
custom error callbacks and .min(1) validators) so the undefined-checking error
functions for firstname and surname run correctly and values like "undefined"
are not accepted.
In `@fdm-app/package.json`:
- Line 90: You added "zod": "^4.3.6" in package.json; validate and adapt code
for Zod v4 compatibility: run the zod-v3-to-v4 codemod across the repo, update
any schema usages that rely on deprecated options (e.g.,
message/required_error), adjust places handling ZodError formatted output,
verify .default() semantics and string validators (e.g., z.ip() → z.ipv4()), and
confirm TypeScript types with `@hookform/resolvers` (ensure you’re on v5.2.2 and
fix any type mismatches in form schemas and error handling like useForm resolver
integrations). After changes, run full typecheck and form-related tests/manual
flows to confirm validation and inference remain correct.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## development #433 +/- ##
============================================
Coverage 88.07% 88.07%
============================================
Files 91 91
Lines 4621 4621
Branches 1492 1492
============================================
Hits 4070 4070
Misses 551 551
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…c yield and parameter fields
BoraIneviNMI
left a comment
There was a problem hiding this comment.
It looks good. I see all the necessary required_error and invalid_type_error keys in the Zod 3 code are taken care of. I have one small suggestion.
Summary by CodeRabbit
Chores
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.
Closes #432