feat: improve vercel query param handling
๐ Linked issue
#1880
โ Type of change
- [ ] ๐ Documentation (updates to the documentation, readme, or JSdoc annotations)
- [ ] ๐ Bug fix (a non-breaking change that fixes an issue)
- [ ] ๐ Enhancement (improving an existing functionality like performance)
- [x] โจ New feature (a non-breaking change that adds functionality)
- [ ] ๐งน Chore (updates to the build process or auxiliary tools and libraries)
- [ ] โ ๏ธ Breaking change (fix or feature that would cause existing functionality to change)
๐ Description
When using ISR on Vercel, you can define which query params should be considered for the cache using the allowQuery key in the .prerender-config.json files. This is documented in the Build API docs:
List of query string parameter names that will be cached independently. If an empty array, query values are not considered for caching. If undefined each unique query value is cached independently
Nitro by default sets this to ["url"] for catch-all routes (/**). This PR allows defining a custom allowQuery configuration for each routeRule. It ensures that "url" is always allowed for catch-all routes, except when the route explicitly sets allowQuery to undefined to allow all params.
Additionally, we add support for Vercel's passQuery param.
When true, the query string will be present on the request argument passed to the invoked function. The allowQuery filter still applies.
This is especially useful for cacheable server routes that need to access the request's query params.
As an example, this configuration would ensure that each query parameter is cached independently on all routes, and allows the API endpoint to access the query params.
routeRules: {
'/**': {
isr: true,
allowQuery: undefined
},
'/api/test-endpoint': {
isr: true,
passQuery: true
}
},
If you consider merging this change, I will happily add some documentation for it in the vercel section. Let me know what you think.
๐ Checklist
- [x] I have linked an issue or discussion.
- [ ] I have updated the documentation accordingly.