Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ethanniser
Copy link
Owner

@ethanniser ethanniser commented Mar 9, 2024

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!

  • Decide on how to name / where to put this function

  • Make sure it works (@adamkangas @jac0bbennett if you could test this out its live on 4.0.7-beta.3 now)

  • Update docs

  • (if ready to be merged) Yes I have made a changeset
    (still work todo)

Sorry, something went wrong.

@adamkangas
Copy link

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
Copy link

Looks good! Thanks for fixing that.

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

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.

Support for higher order function wrapping Next's generateMetadata()
3 participants