Unverified Commit 5d9022ed authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

[backport] Fix unset crossOrigin in Turbopack manifests (#97930)

Backports [Fix unset crossOrigin in Turbopack
manifests](https://github.com/vercel/next.js/pull/97164) to `next-16-3`.

<!-- NEXT_JS_LLM -->
parent d8f45609
...@@ -70,9 +70,14 @@ pub struct CssResource { ...@@ -70,9 +70,14 @@ pub struct CssResource {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ModuleLoading { pub struct ModuleLoading {
pub prefix: RcStr, pub prefix: RcStr,
#[serde(skip_serializing_if = "is_cross_origin_none")]
pub cross_origin: CrossOrigin, pub cross_origin: CrossOrigin,
} }
fn is_cross_origin_none(cross_origin: &CrossOrigin) -> bool {
matches!(cross_origin, CrossOrigin::None)
}
#[derive(Serialize, Default, Debug, Clone)] #[derive(Serialize, Default, Debug, Clone)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ManifestNode { pub struct ManifestNode {
......
import { connection } from 'next/server'
import { Suspense } from 'react'
async function DynamicContent() {
if (!process.env.NEXT_TEST_OUTPUT_EXPORT) {
await connection()
}
return <p>dynamic page</p>
}
export default function DynamicPage() {
return (
<Suspense fallback={<p>loading dynamic page</p>}>
<DynamicContent />
</Suspense>
)
}
export default function RootLayout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
'use client'
export default function Page() {
return <p>hello world</p>
}
module.exports = {
assetPrefix: 'https://example.vercel.sh',
crossOrigin: undefined,
output: process.env.NEXT_TEST_OUTPUT_EXPORT ? 'export' : undefined,
}
import { createReadStream } from 'node:fs'
import { createServer } from 'node:http'
import { extname, join } from 'node:path'
const outputDirectory = join(process.cwd(), 'out')
const server = createServer((request, response) => {
let pathname = new URL(request.url, 'http://localhost').pathname
if (pathname.endsWith('/')) {
pathname += 'index.html'
} else if (!extname(pathname)) {
pathname += '.html'
}
const stream = createReadStream(
join(outputDirectory, pathname.replace(/^\/+/, ''))
)
stream.on('error', () => {
response.writeHead(404)
response.end('Not found')
})
stream.pipe(response)
})
server.listen(Number(process.env.PORT), () => {
const address = server.address()
const port = typeof address === 'object' && address ? address.port : 0
console.log(`- Local: http://localhost:${port}`)
})
import { nextTestSetup } from 'e2e-utils' import path from 'path'
import { isNextStart, nextTestSetup } from 'e2e-utils'
describe('app dir - crossOrigin config', () => { const assetPrefix = 'https://example.vercel.sh'
const { next, isNextStart, skipped } = nextTestSetup({
if (!isNextStart) {
describe('app dir - crossOrigin config', () => {
const { next, skipped } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true, skipDeployment: true,
}) })
...@@ -10,10 +14,6 @@ describe('app dir - crossOrigin config', () => { ...@@ -10,10 +14,6 @@ describe('app dir - crossOrigin config', () => {
return return
} }
if (isNextStart) {
it('skip in start mode', () => {})
return
}
it('should render correctly with assetPrefix: "/"', async () => { it('should render correctly with assetPrefix: "/"', async () => {
const $ = await next.render$('/') const $ = await next.render$('/')
// Only potential external (assetPrefix) <script /> and <link /> should have crossorigin attribute // Only potential external (assetPrefix) <script /> and <link /> should have crossorigin attribute
...@@ -36,4 +36,67 @@ describe('app dir - crossOrigin config', () => { ...@@ -36,4 +36,67 @@ describe('app dir - crossOrigin config', () => {
expect(crossOrigin).toBeUndefined() expect(crossOrigin).toBeUndefined()
}) })
}) })
}) })
} else {
describe('app dir - unset crossOrigin config', () => {
describe('default output', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'default'),
skipDeployment: true,
})
function expectCrossOriginAttributesToBeOmitted(
$: Awaited<ReturnType<typeof next.render$>>
) {
const scripts = $(`script[src^="${assetPrefix}"]`)
expect(scripts.length).toBeGreaterThan(0)
scripts.each((_, script) => {
expect($(script).attr('crossorigin')).toBeUndefined()
})
}
it('does not add crossorigin attributes to statically generated scripts', async () => {
expectCrossOriginAttributesToBeOmitted(await next.render$('/'))
})
it('does not add crossorigin attributes to dynamically rendered scripts', async () => {
expectCrossOriginAttributesToBeOmitted(await next.render$('/dynamic'))
})
})
if (process.env.__NEXT_CACHE_COMPONENTS !== 'true') {
describe('output: export', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'default'),
env: {
NEXT_TEST_OUTPUT_EXPORT: '1',
},
skipStart: true,
skipDeployment: true,
startCommand: 'node server.mjs',
serverReadyPattern: /- Local:/,
})
function expectCrossOriginAttributesToBeOmitted(
$: Awaited<ReturnType<typeof next.render$>>
) {
const scripts = $(`script[src^="${assetPrefix}"]`)
expect(scripts.length).toBeGreaterThan(0)
scripts.each((_, script) => {
expect($(script).attr('crossorigin')).toBeUndefined()
})
}
it('does not add crossorigin attributes to exported scripts', async () => {
await next.build()
await next.start({ skipBuild: true })
expectCrossOriginAttributesToBeOmitted(await next.render$('/'))
expectCrossOriginAttributesToBeOmitted(await next.render$('/dynamic'))
})
})
}
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment