Skip to content

test: added tests to check that the vary header contains 'RSC' #1993

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

Merged
merged 9 commits into from
Mar 23, 2023
9 changes: 9 additions & 0 deletions cypress/integration/default/appdir.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down
5 changes: 5 additions & 0 deletions packages/runtime/src/templates/edge-shared/rsc-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ 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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be on the Response?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right. Not sure why I put it on the request (late night coding 🙃 ), and also not sure why my tests and curls pass. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already worked. The problem isn't it returning the wrong data - that was already fixed. The problem is the browser caching the wrong data. The tests should be checking that the server is returning the Vary header, and you can manually test it in the browser with the instructions in https://github.com/netlify/pod-ecosystem-frameworks/issues/352

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added tests to check for the vary header. Oddly enough, it looks like the vary header is working already. I removed my change and just updated tests.


// If this is a static RSC request, rewrite to the data route
if (request.headers.get('rsc') === '1') {
log('Is rsc request')
Expand Down