Commit 96d6adac authored by Sung Ye In's avatar Sung Ye In Committed by Zack Tanner

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

Co-authored-by: 's avatarJiwon Choi <devjiwonchoi@gmail.com>
parent c572030a
...@@ -349,8 +349,13 @@ function Script(props: ScriptProps): JSX.Element | null { ...@@ -349,8 +349,13 @@ function Script(props: ScriptProps): JSX.Element | null {
ReactDOM.preload( ReactDOM.preload(
src, src,
restProps.integrity 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 ( return (
<script <script
...@@ -370,8 +375,13 @@ function Script(props: ScriptProps): JSX.Element | null { ...@@ -370,8 +375,13 @@ function Script(props: ScriptProps): JSX.Element | null {
ReactDOM.preload( ReactDOM.preload(
src, src,
restProps.integrity 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 }
) )
} }
} }
......
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
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"
/>
)
}
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')
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
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