-
-
Notifications
You must be signed in to change notification settings - Fork 742
feat: dynamic data in defineRouteMeta v2 #3357
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
base: main
Are you sure you want to change the base?
Conversation
β¦alint/nitro into dynamic-defineRouteMeta-v2
|
+ one note, this implementation is not 100% side effect free, but I think it is reasonable to think of it that way. If there is a function call inside defineRouteMeta (or in one of the functions it references), then the whole referenced function is kept. This means that if that function have side effects, those will run. I really don't think this is a big issue, since imports can have side effects any way, so no implementation would be fully side-effect free. |
|
Thanks for PR. Idea of bundling is to remove those side-effects. Can you please rework PR to use |
@pi0 can you please give some more guidance on this? From my understanding bundling is generating a single output file from multiple inputs, while optionaly treeshaking the imports. |
|
Would now be a good time to consider maybe another way to accomplish this? We could accept ZOD (and other major validators) in definePageMeta instead of JSON Schema directly... maybe via a custom transformer function that runs at build time? |
π Linked issue
#2974
β Type of change
π Description
This is the successor of #3096. This time without side effects and build time evaluation!
There are a few things to resolve/check:
acorn: for the same reason as last time, rollups parse method has type mismatches with reality (range vs start/end). Update: I ended up extending estrees type, so acorn is not neededestree-toolbar: this one is more controversal. For achieving build time eval and side effect freeness we have to track the scopes while traversing the AST. Building an in-house scope tracker does not seem like a great idea (this is what nuxt did), so I went with this package which does not have a ton of downloads, but had all the functionality needed.Other than these, I think this works pretty nicely :) I will try to fix all of these before the v3 release if there is a chance for this to be included.
π Checklist