diff --git a/packages/next/src/client/page-loader.ts b/packages/next/src/client/page-loader.ts index 76ecb8fb0439d..61d0071b10fcf 100644 --- a/packages/next/src/client/page-loader.ts +++ b/packages/next/src/client/page-loader.ts @@ -64,7 +64,8 @@ export default class PageLoader { return window.__DEV_PAGES_MANIFEST.pages } else { this.promisedDevPagesManifest ||= fetch( - `${this.assetPrefix}/_next/static/development/${DEV_CLIENT_PAGES_MANIFEST}` + `${this.assetPrefix}/_next/static/development/${DEV_CLIENT_PAGES_MANIFEST}`, + { credentials: 'same-origin' } ) .then((res) => res.json()) .then((manifest: { pages: string[] }) => { @@ -98,7 +99,8 @@ export default class PageLoader { // TODO: Decide what should happen when fetching fails instead of asserting // @ts-ignore this.promisedMiddlewareMatchers = fetch( - `${this.assetPrefix}/_next/static/${this.buildId}/${DEV_MIDDLEWARE_MANIFEST}` + `${this.assetPrefix}/_next/static/${this.buildId}/${DEV_MIDDLEWARE_MANIFEST}`, + { credentials: 'same-origin' } ) .then((res) => res.json()) .then((matchers: MiddlewareMatcher[]) => { diff --git a/packages/next/src/client/route-loader.ts b/packages/next/src/client/route-loader.ts index f3ebc4740d168..ca22834908464 100644 --- a/packages/next/src/client/route-loader.ts +++ b/packages/next/src/client/route-loader.ts @@ -323,7 +323,7 @@ export function createRouteLoader(assetPrefix: string): RouteLoader { styleSheets.set( href, - (prom = fetch(href) + (prom = fetch(href, { credentials: 'same-origin' }) .then((res) => { if (!res.ok) { throw new Error(`Failed to load stylesheet: ${href}`) diff --git a/test/integration/dynamic-routing/test/index.test.js b/test/integration/dynamic-routing/test/index.test.js index e33021a60179b..d5d874a97aaa9 100644 --- a/test/integration/dynamic-routing/test/index.test.js +++ b/test/integration/dynamic-routing/test/index.test.js @@ -1156,6 +1156,26 @@ function runTests({ dev }) { } ` ) + await check(async () => { + const response = await fetchViaHTTP( + appPort, + '/_next/static/development/_devPagesManifest.json', + undefined, + { + credentials: 'same-origin', + } + ) + + // Check if the response was successful (status code in the range 200-299) + if (!response.ok) { + return 'fail' + } + + const contents = await response.text() + const containsAddedLater = contents.includes('added-later') + + return containsAddedLater ? 'success' : 'fail' + }, 'success') await check(async () => { const contents = await renderViaHTTP(