[routing-utils] add respectOriginCacheControl to schema#14506
[routing-utils] add respectOriginCacheControl to schema#14506MatthewStanciu merged 5 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 3f96b09 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🧪 Test StrategyComparing: Strategy: Affected packages only ✅ Only testing packages that have been modified or depend on modified packages. Affected packages - 39 (100%)
Results
This comment is automatically generated based on the affected testing strategy |
There was a problem hiding this comment.
Additional Suggestion:
The convertRewrites function in superstatic.ts didn't transfer the respectOriginCacheControl property to generated Route objects, and the RouteWithSrc type was missing this property.
View Details
📝 Patch Details
diff --git a/packages/routing-utils/src/superstatic.ts b/packages/routing-utils/src/superstatic.ts
index eb0522223..8f10490bf 100644
--- a/packages/routing-utils/src/superstatic.ts
+++ b/packages/routing-utils/src/superstatic.ts
@@ -197,6 +197,9 @@ export function convertRewrites(
if (r.statusCode) {
route.status = r.statusCode;
}
+ if (typeof r.respectOriginCacheControl !== 'undefined') {
+ route.respectOriginCacheControl = r.respectOriginCacheControl;
+ }
return route;
} catch (e) {
throw new Error(`Failed to parse rewrite: ${JSON.stringify(r)}`);
diff --git a/packages/routing-utils/src/types.ts b/packages/routing-utils/src/types.ts
index 7c3320591..03eb62448 100644
--- a/packages/routing-utils/src/types.ts
+++ b/packages/routing-utils/src/types.ts
@@ -98,6 +98,11 @@ export type RouteWithSrc = {
* A middleware index in the `middleware` key under the build result
*/
middleware?: number;
+ /**
+ * When true (default), external rewrites will respect the Cache-Control header from the origin.
+ * When false, caching is disabled for this rewrite.
+ */
+ respectOriginCacheControl?: boolean;
};
export type RouteWithHandle = {
Analysis
The issue was that while the Rewrite interface in types.ts and the rewritesSchema in schemas.ts both properly defined the respectOriginCacheControl property, the convertRewrites function at line 168-203 in superstatic.ts was not transferring this property to the Route object. Additionally, the RouteWithSrc type definition was missing this property, which meant Route objects couldn't even carry this value.
The fix involved:
- Adding respectOriginCacheControl?: boolean to the RouteWithSrc type definition in types.ts (line 85-88)
- Adding property transfer logic in convertRewrites function in superstatic.ts (lines 201-203) following the same pattern used for other optional properties like env, has, missing, and statusCode
This ensures the property is properly preserved during the Rewrite → Route conversion pipeline, maintaining consistency with how it's handled in packages/config/src/router.ts.
There was a problem hiding this comment.
Additional Suggestion:
The convertRewrites function in superstatic.ts didn't transfer the respectOriginCacheControl property to generated Route objects, and the RouteWithSrc type was missing this property.
View Details
📝 Patch Details
diff --git a/packages/routing-utils/src/superstatic.ts b/packages/routing-utils/src/superstatic.ts
index eb0522223..8f10490bf 100644
--- a/packages/routing-utils/src/superstatic.ts
+++ b/packages/routing-utils/src/superstatic.ts
@@ -197,6 +197,9 @@ export function convertRewrites(
if (r.statusCode) {
route.status = r.statusCode;
}
+ if (typeof r.respectOriginCacheControl !== 'undefined') {
+ route.respectOriginCacheControl = r.respectOriginCacheControl;
+ }
return route;
} catch (e) {
throw new Error(`Failed to parse rewrite: ${JSON.stringify(r)}`);
diff --git a/packages/routing-utils/src/types.ts b/packages/routing-utils/src/types.ts
index 7c3320591..03eb62448 100644
--- a/packages/routing-utils/src/types.ts
+++ b/packages/routing-utils/src/types.ts
@@ -98,6 +98,11 @@ export type RouteWithSrc = {
* A middleware index in the `middleware` key under the build result
*/
middleware?: number;
+ /**
+ * When true (default), external rewrites will respect the Cache-Control header from the origin.
+ * When false, caching is disabled for this rewrite.
+ */
+ respectOriginCacheControl?: boolean;
};
export type RouteWithHandle = {
Analysis
The issue was that while the Rewrite interface in types.ts and the rewritesSchema in schemas.ts both properly defined the respectOriginCacheControl property, the convertRewrites function at line 168-203 in superstatic.ts was not transferring this property to the Route object. Additionally, the RouteWithSrc type definition was missing this property, which meant Route objects couldn't even carry this value.
The fix involved:
- Adding respectOriginCacheControl?: boolean to the RouteWithSrc type definition in types.ts (line 85-88)
- Adding property transfer logic in convertRewrites function in superstatic.ts (lines 201-203) following the same pattern used for other optional properties like env, has, missing, and statusCode
This ensures the property is properly preserved during the Rewrite → Route conversion pipeline, maintaining consistency with how it's handled in packages/config/src/router.ts.
) #14506 Added `respectOriginCacheControl` to the rewrites schema. #14518 copies this property over to `routes` when merging. This causes a schema validation error that will break the upcoming release. These two PRs didn't know about each other which is why this wasn't caught. Although `routes` is deprecated, it is actively used for transforms in vercel.ts. So this new property needs to be on the routes schema in addition to the rewrites schema. --------- Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## vercel@50.2.0 ### Minor Changes - Add `vercel env run` command to run commands with environment variables from the linked Vercel project without writing them to the filesystem ([#14582](#14582)) - Merge computed rewrites/redirects to routes in Vercel config ([#14518](#14518)) ### Patch Changes - Adding in user configured deploymentId to build output type ([#14497](#14497)) - skip secondary installation for vercel.ts ([#14471](#14471)) - Updated dependencies \[[`2eb1b7678bece13e442f8404d519bd07891eb500`](2eb1b76), [`39c95ff6b643a63509571818e67a792df09fd71f`](39c95ff), [`d63084dac296ccb2077ed742bc2ade0264da851d`](d63084d)]: - @vercel/next@4.15.11 - @vercel/build-utils@13.2.5 - @vercel/redwood@2.4.6 - @vercel/rust@1.0.4 - @vercel/static-build@2.8.16 - @vercel/backends@0.0.18 - @vercel/elysia@0.1.16 - @vercel/express@0.1.23 - @vercel/fastify@0.1.19 - @vercel/go@3.3.0 - @vercel/h3@0.1.25 - @vercel/hono@0.2.19 - @vercel/hydrogen@1.3.3 - @vercel/nestjs@0.2.20 - @vercel/node@5.5.17 - @vercel/python@6.1.6 - @vercel/remix-builder@5.5.6 - @vercel/ruby@2.2.4 ## @vercel/build-utils@13.2.5 ### Patch Changes - Adding in user configured deploymentId to build output type ([#14497](#14497)) - skip secondary installation for vercel.ts ([#14471](#14471)) ## @vercel/client@17.2.19 ### Patch Changes - Updated dependencies \[[`e725853a6c41bed634d1e3e2382596f17a18f342`](e725853), [`39c95ff6b643a63509571818e67a792df09fd71f`](39c95ff), [`d63084dac296ccb2077ed742bc2ade0264da851d`](d63084d), [`567d2d41e685cd949274411ce0e60e61a3dc3942`](567d2d4)]: - @vercel/routing-utils@5.3.2 - @vercel/build-utils@13.2.5 ## @vercel/elysia@0.1.16 ### Patch Changes - Updated dependencies \[]: - @vercel/node@5.5.17 ## @vercel/express@0.1.23 ### Patch Changes - Updated dependencies \[]: - @vercel/node@5.5.17 ## @vercel/fastify@0.1.19 ### Patch Changes - Updated dependencies \[]: - @vercel/node@5.5.17 ## @vercel/fs-detectors@5.7.12 ### Patch Changes - Updated dependencies \[[`e725853a6c41bed634d1e3e2382596f17a18f342`](e725853), [`567d2d41e685cd949274411ce0e60e61a3dc3942`](567d2d4)]: - @vercel/routing-utils@5.3.2 - @vercel/frameworks@3.15.4 ## @vercel/gatsby-plugin-vercel-builder@2.0.115 ### Patch Changes - Updated dependencies \[[`39c95ff6b643a63509571818e67a792df09fd71f`](39c95ff), [`d63084dac296ccb2077ed742bc2ade0264da851d`](d63084d)]: - @vercel/build-utils@13.2.5 ## @vercel/h3@0.1.25 ### Patch Changes - Updated dependencies \[]: - @vercel/node@5.5.17 ## @vercel/hono@0.2.19 ### Patch Changes - Updated dependencies \[]: - @vercel/node@5.5.17 ## @vercel/nestjs@0.2.20 ### Patch Changes - Updated dependencies \[]: - @vercel/node@5.5.17 ## @vercel/next@4.15.11 ### Patch Changes - Add early validation for Next.js output directory and improve error messages to guide users when the output directory is missing, empty, or misconfigured. Introduces new error codes `NEXT_OUTPUT_DIR_MISSING` and `NEXT_OUTPUT_DIR_EMPTY` with actionable guidance for common issues like Turborepo cache misconfiguration. ([#14542](#14542)) ## @vercel/node@5.5.17 ### Patch Changes - Updated dependencies \[[`39c95ff6b643a63509571818e67a792df09fd71f`](39c95ff), [`d63084dac296ccb2077ed742bc2ade0264da851d`](d63084d)]: - @vercel/build-utils@13.2.5 ## @vercel/routing-utils@5.3.2 ### Patch Changes - Add respectOriginCacheControl to rewritesSchema ([#14506](#14506)) - Add respectOriginCacheControl to routes schema ([#14565](#14565)) ## @vercel/static-build@2.8.16 ### Patch Changes - Updated dependencies \[]: - @vercel/gatsby-plugin-vercel-builder@2.0.115 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Update rewritesSchema with respectOriginCacheControl