-
Notifications
You must be signed in to change notification settings - Fork 460
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
feat: improve vercel query param handling #2375
base: main
Are you sure you want to change the base?
Conversation
@@ -208,6 +208,8 @@ export interface NitroRouteRules | |||
extends Omit<NitroRouteConfig, "redirect" | "cors" | "swr" | "static"> { | |||
redirect?: { to: string; statusCode: HTTPStatusCode }; | |||
proxy?: { to: string } & ProxyOptions; | |||
allowQuery?: string[]; | |||
passQuery?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a vercel-specific route rule, we might need to namespace them to as vercel?: {}
@@ -67,11 +67,22 @@ export const vercel = defineNitroPreset({ | |||
funcPrefix + ".func", | |||
"junction" | |||
); | |||
|
|||
let allowQuery = key.includes("/**") ? ["url"] : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any docs that mention url
is conventional or has a specific use case to be supported by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand (the url
default was there before my change and I'm pretty new to this Vercel stuff), this is necessary for catch-all routes to work at all. Otherwise each route that ends up in the catch-all would return the same cached html. The url
param is set here:
Line 238 in 3a69dd7
: generateEndpoint(key) + "?url=$url", |
In that sense I would say that this is not "conventional", but rather a nitro-specific thing to make catch-all routes work.
π Linked issue
#1880
β Type of 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:Nitro by default sets this to
["url"]
for catch-all routes (/**
). This PR allows defining a customallowQuery
configuration for each routeRule. It ensures that "url" is always allowed for catch-all routes, except when the route explicitly setsallowQuery
toundefined
to allow all params.Additionally, we add support for Vercel's
passQuery
param.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.
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