jquense / yup

Dead simple Object schema validation
MIT License
22.93k stars 934 forks source link

Make it clear which values passed to the schema are not evaluated at validation time on the server #2166

Closed NASlR closed 9 months ago

NASlR commented 10 months ago

So it appears I've run into this issue https://stackoverflow.com/questions/63381887/yup-compares-min-max-date-with-build-date-instead-of-current-date

I was running my schema validation on the client and in the nextjs server side code which was

const schema = Yup.object().shape({
   date: Yup.date().max(addDays(new Date(), 13))
})

And it turns out that new Date() is when the code was built and deployed so when we had a code freeze over christmas we came back to a bunch of people getting errors haha

So now I know I should be using Yup.lazy() as it says

Creates a schema that is evaluated at validation/cast time

However it's not really made clear in the docs / getting started guide. Maybe a warning or something along those lines higher up the readme might be useful?

Or if it is actually obvious and I just didn't read the docs properly then a mention could maybe be added here https://github.com/jquense/yup/#date

Thanks!

jquense commented 9 months ago

I appreciate that this can be tricky but i'm not sure it belongs in the docs as its more of JS level language misunderstanding.