ethanniser / next-typesafe-url

Fully typesafe, JSON serializable, and zod validated URL search params, dynamic route params, and routing for NextJS.
https://next-typesafe-url.dev
MIT License
362 stars 16 forks source link

add support for typed search/route params in `generateMetadata` #94

Open ethanniser opened 5 months ago

ethanniser commented 5 months ago

closes #92

This PR: Adds support for a new higher order function wrapping Next's generateMetadata() to add the same parsing for route/search params as in the normal page component

the function is basically identical to the existing withParamValidation but without the react stuff required for higher order components (check out the example!)

right now ive named it also withParamValidation and put it in next-typesafe-url/app but this leads to a name conflict in its intended usecase (again see example)

TODO!

adamkangas commented 5 months ago

Thanks a lot for the speedy assist @ethanniser , it seems to work great.

The naming is certainly tricky as import { withParamValidation as withParamValidation2 } feels bad and lacks auto-import. I expect it will be common to importing both of these higher order functions in dynamic pages, so some clarity around naming feels important for DX.

I imagine you want to prevent breaking changes to the original withParamValidation by renaming that in the short term – but that name may be a bit ambiguous when using both of these simultaneously. Long-term that might become hocWithParamValidation or withParamValidationHoc?

And perhaps this becomes generateMetadataWithParamValidation or withParamValidationGenerateMetadata?

Just some ideas, for the time being this is good enough to work with so thanks again.

jac0bbennett commented 5 months ago

Looks good! Thanks for fixing that.

I think either of Adam's naming suggestions would be just fine.