diff --git a/packages/next/src/build/swc/index.ts b/packages/next/src/build/swc/index.ts index 936a2e098d..3fc8bce72f 100644 --- a/packages/next/src/build/swc/index.ts +++ b/packages/next/src/build/swc/index.ts @@ -1056,7 +1056,8 @@ function bindingToApi(binding: any, _wasm: boolean) { nextConfig: NextConfigComplete, projectPath: string ): Promise { - let nextConfigSerializable = nextConfig as any + // Avoid mutating the existing `nextConfig` object. + let nextConfigSerializable = { ...(nextConfig as any) } nextConfigSerializable.generateBuildId = await nextConfig.generateBuildId?.() @@ -1091,9 +1092,12 @@ function bindingToApi(binding: any, _wasm: boolean) { : undefined // loaderFile is an absolute path, we need it to be relative for turbopack. - if (nextConfig.images.loaderFile) { - nextConfig.images.loaderFile = - './' + path.relative(projectPath, nextConfig.images.loaderFile) + if (nextConfigSerializable.images.loaderFile) { + nextConfigSerializable.images = { + ...nextConfig.images, + loaderFile: + './' + path.relative(projectPath, nextConfig.images.loaderFile), + } } return JSON.stringify(nextConfigSerializable, null, 2) diff --git a/test/integration/filesystempublicroutes/pages/exportpathmap-route.js b/test/integration/filesystempublicroutes/pages/exportpathmap-route.js index 1137e041b4..2921d4def3 100644 --- a/test/integration/filesystempublicroutes/pages/exportpathmap-route.js +++ b/test/integration/filesystempublicroutes/pages/exportpathmap-route.js @@ -1 +1,14 @@ -export default () =>
exportpathmap was here
+import { useEffect } from 'react' +import { useState } from 'react' +export default function ExportPathMapRoute() { + const [mounted, setMounted] = useState(false) + useEffect(() => { + setMounted(true) + }, []) + return ( +
+

exportpathmap was here

+ {mounted ?
Hello World
: null} +
+ ) +} diff --git a/test/integration/filesystempublicroutes/test/index.test.js b/test/integration/filesystempublicroutes/test/index.test.js index b887f37810..5418dd6692 100644 --- a/test/integration/filesystempublicroutes/test/index.test.js +++ b/test/integration/filesystempublicroutes/test/index.test.js @@ -2,12 +2,8 @@ import { join } from 'path' import getPort from 'get-port' -import { - fetchViaHTTP, - initNextServerScript, - killApp, - getPageFileFromBuildManifest, -} from 'next-test-utils' +import { fetchViaHTTP, initNextServerScript, killApp } from 'next-test-utils' +import webdriver from 'next-webdriver' const appDir = join(__dirname, '../') let appPort @@ -40,23 +36,14 @@ describe('FileSystemPublicRoutes', () => { const res = await fetch('/exportpathmap-route') expect(res.status).toBe(200) const body = await res.text() - expect(body).toMatch( - process.env.TURBOPACK ? /turbopack/ : /exportpathmap was here/ - ) + expect(body).toMatch(/exportpathmap was here/) }) - it('should still handle /_next routes', async () => { - await fetch('/exportpathmap-route') // make sure it's built - const pageFile = getPageFileFromBuildManifest( - appDir, - '/exportpathmap-route' - ) - const res = await fetch(join('/_next', pageFile)) - expect(res.status).toBe(200) - const body = await res.text() - expect(body).toMatch( - process.env.TURBOPACK ? /turbopack/ : /exportpathmap was here/ - ) + it('should serve JavaScript files correctly', async () => { + const browser = await webdriver(context.appPort, '/exportpathmap-route') + + const text = await browser.waitForElementByCss('#page-was-loaded').text() + expect(text).toBe('Hello World') }) it('should route to public folder files', async () => { diff --git a/test/turbopack-tests-manifest.json b/test/turbopack-tests-manifest.json index 613c415e47..9a146156f3 100644 --- a/test/turbopack-tests-manifest.json +++ b/test/turbopack-tests-manifest.json @@ -10749,13 +10749,12 @@ }, "test/integration/filesystempublicroutes/test/index.test.js": { "passed": [ - "FileSystemPublicRoutes should route to public folder files", - "FileSystemPublicRoutes should still handle /_next routes" - ], - "failed": [ "FileSystemPublicRoutes should not route to the index page", - "FileSystemPublicRoutes should route to exportPathMap defined routes in development" + "FileSystemPublicRoutes should route to exportPathMap defined routes in development", + "FileSystemPublicRoutes should route to public folder files", + "FileSystemPublicRoutes should serve JavaScript files correctly" ], + "failed": [], "pending": [], "flakey": [], "runtimeError": false