fix(next): add cross origin in react dom preload (#67423)

Co-authored-by: Jiwon Choi <devjiwonchoi@gmail.com>
This commit is contained in:
Sung Ye In 2024-07-05 22:13:00 +09:00 committed by GitHub
parent a5ef0d8da5
commit 0dbe761e52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 55 additions and 4 deletions

View file

@ -332,8 +332,13 @@ function Script(props: ScriptProps): JSX.Element | null {
ReactDOM.preload(
src,
restProps.integrity
? { as: 'script', integrity: restProps.integrity, nonce }
: { as: 'script', nonce }
? {
as: 'script',
integrity: restProps.integrity,
nonce,
crossOrigin: restProps.crossOrigin,
}
: { as: 'script', nonce, crossOrigin: restProps.crossOrigin }
)
return (
<script
@ -353,8 +358,13 @@ function Script(props: ScriptProps): JSX.Element | null {
ReactDOM.preload(
src,
restProps.integrity
? { as: 'script', integrity: restProps.integrity, nonce }
: { as: 'script', nonce }
? {
as: 'script',
integrity: restProps.integrity,
nonce,
crossOrigin: restProps.crossOrigin,
}
: { as: 'script', nonce, crossOrigin: restProps.crossOrigin }
)
}
}

View file

@ -0,0 +1,8 @@
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}

View file

@ -0,0 +1,10 @@
import Script from 'next/script'
export default function Page() {
return (
<Script
src="https://code.jquery.com/jquery-3.7.1.min.js"
crossOrigin="use-credentials"
/>
)
}

View file

@ -0,0 +1,17 @@
import { nextTestSetup } from 'e2e-utils'
describe('Script component with crossOrigin props', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should be set crossOrigin also in preload link tag', async () => {
const browser = await next.browser('/')
const crossorigin = await browser
.elementByCss('link[href="https://code.jquery.com/jquery-3.7.1.min.js"]')
.getAttribute('crossorigin')
expect(crossorigin).toBe('use-credentials')
})
})

View file

@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig