From 5dcb0982c675674bfffb3ac4a88efa5b097dc95a Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Wed, 15 Mar 2023 19:19:23 -0400 Subject: [PATCH 1/6] fix: added a vary header with RSC to get proper content-type --- packages/runtime/src/templates/edge-shared/rsc-data.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/runtime/src/templates/edge-shared/rsc-data.ts b/packages/runtime/src/templates/edge-shared/rsc-data.ts index 07fc3e232b..c4971b8d78 100644 --- a/packages/runtime/src/templates/edge-shared/rsc-data.ts +++ b/packages/runtime/src/templates/edge-shared/rsc-data.ts @@ -60,6 +60,12 @@ export const getRscDataRouter = ({ routes: staticRoutes, dynamicRoutes }: Preren const debug = request.headers.has('x-next-debug-logging') const log = debug ? (...args: unknown[]) => console.log(...args) : noop const url = new URL(request.url) + + // Set the 'vary' header to 'RSC' to ensure that we cache correctly for the different + // possible mime types: application/octet-stream and text/html + // See https://github.com/netlify/pod-ecosystem-frameworks/issues/352#issuecomment-1450364417 + request.headers.set('vary', 'RSC') + // If this is a static RSC request, rewrite to the data route if (request.headers.get('rsc') === '1') { log('Is rsc request') From 958fb89d88273c3ffd3ef275d6cfd5df43a56da1 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Wed, 15 Mar 2023 19:50:54 -0400 Subject: [PATCH 2/6] test: added test to ensure content type is HTML for non-RSC requests in app dir --- cypress/integration/default/appdir.spec.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cypress/integration/default/appdir.spec.ts b/cypress/integration/default/appdir.spec.ts index 6c024c1a8a..97792fbf8e 100644 --- a/cypress/integration/default/appdir.spec.ts +++ b/cypress/integration/default/appdir.spec.ts @@ -29,6 +29,15 @@ describe('appDir', () => { }) }) + it('returns HTML for non-RSC requests to ISR pages', () => { + cy.request({ + url: '/blog/erica/', + followRedirect: false, + }).then((response) => { + expect(response.headers).to.have.property('content-type', 'text/html; charset=utf-8') + }) + }) + it('returns RSC data for RSC requests to static pages', () => { cy.request({ url: '/blog/erica/first-post/', From 2620db5288de92466c64b57b2d2766d0048411f6 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Thu, 16 Mar 2023 07:30:16 -0400 Subject: [PATCH 3/6] chore: fixed up comment --- packages/runtime/src/templates/edge-shared/rsc-data.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/runtime/src/templates/edge-shared/rsc-data.ts b/packages/runtime/src/templates/edge-shared/rsc-data.ts index c4971b8d78..2562c9f952 100644 --- a/packages/runtime/src/templates/edge-shared/rsc-data.ts +++ b/packages/runtime/src/templates/edge-shared/rsc-data.ts @@ -62,8 +62,7 @@ export const getRscDataRouter = ({ routes: staticRoutes, dynamicRoutes }: Preren const url = new URL(request.url) // Set the 'vary' header to 'RSC' to ensure that we cache correctly for the different - // possible mime types: application/octet-stream and text/html - // See https://github.com/netlify/pod-ecosystem-frameworks/issues/352#issuecomment-1450364417 + // possible content-types: application/octet-stream and text/html request.headers.set('vary', 'RSC') // If this is a static RSC request, rewrite to the data route From cdedf0bfe819be0e2d3cf07fb8ba74b06b9e805a Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Thu, 16 Mar 2023 11:14:53 -0400 Subject: [PATCH 4/6] chore: updated test description --- cypress/integration/default/appdir.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/default/appdir.spec.ts b/cypress/integration/default/appdir.spec.ts index 97792fbf8e..e98a58dcce 100644 --- a/cypress/integration/default/appdir.spec.ts +++ b/cypress/integration/default/appdir.spec.ts @@ -29,7 +29,7 @@ describe('appDir', () => { }) }) - it('returns HTML for non-RSC requests to ISR pages', () => { + it('returns HTML for non-RSC data requests to ISR pages', () => { cy.request({ url: '/blog/erica/', followRedirect: false, From f48643a7eb6a9a3417a19fb6eb3ef7f3d734b3ab Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 17 Mar 2023 09:43:03 -0400 Subject: [PATCH 5/6] test: added tests to check vary header for RSC --- cypress/integration/default/appdir.spec.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cypress/integration/default/appdir.spec.ts b/cypress/integration/default/appdir.spec.ts index e98a58dcce..e944844955 100644 --- a/cypress/integration/default/appdir.spec.ts +++ b/cypress/integration/default/appdir.spec.ts @@ -29,12 +29,24 @@ describe('appDir', () => { }) }) - it('returns HTML for non-RSC data requests to ISR pages', () => { + it('returns a vary header for RSC data requests to ISR pages', () => { + cy.request({ + url: '/blog/erica/', + followRedirect: false, + headers: { + RSC: '1', + }, + }).then((response) => { + expect(response.headers).to.have.property('vary').contains('RSC') + }) + }) + + it('returns a vary header for non-RSC data requests to ISR pages', () => { cy.request({ url: '/blog/erica/', followRedirect: false, }).then((response) => { - expect(response.headers).to.have.property('content-type', 'text/html; charset=utf-8') + expect(response.headers).to.have.property('vary').contains('RSC') }) }) From 2ce423e71f3ecec1eeca2569c29a1e24017cb164 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 17 Mar 2023 09:44:48 -0400 Subject: [PATCH 6/6] Revert "fix: added a vary header with RSC to get proper content-type" This reverts commit 5dcb0982c675674bfffb3ac4a88efa5b097dc95a. --- packages/runtime/src/templates/edge-shared/rsc-data.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/runtime/src/templates/edge-shared/rsc-data.ts b/packages/runtime/src/templates/edge-shared/rsc-data.ts index 2562c9f952..07fc3e232b 100644 --- a/packages/runtime/src/templates/edge-shared/rsc-data.ts +++ b/packages/runtime/src/templates/edge-shared/rsc-data.ts @@ -60,11 +60,6 @@ export const getRscDataRouter = ({ routes: staticRoutes, dynamicRoutes }: Preren const debug = request.headers.has('x-next-debug-logging') const log = debug ? (...args: unknown[]) => console.log(...args) : noop const url = new URL(request.url) - - // Set the 'vary' header to 'RSC' to ensure that we cache correctly for the different - // possible content-types: application/octet-stream and text/html - request.headers.set('vary', 'RSC') - // If this is a static RSC request, rewrite to the data route if (request.headers.get('rsc') === '1') { log('Is rsc request')