Skip to content

Commit 96d6ada

Browse files
syi0808devjiwonchoi
authored andcommitted
fix(next): add cross origin in react dom preload (#67423)
Co-authored-by: Jiwon Choi <[email protected]>
1 parent c572030 commit 96d6ada

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

packages/next/src/client/script.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,13 @@ function Script(props: ScriptProps): JSX.Element | null {
349349
ReactDOM.preload(
350350
src,
351351
restProps.integrity
352-
? { as: 'script', integrity: restProps.integrity, nonce }
353-
: { as: 'script', nonce }
352+
? {
353+
as: 'script',
354+
integrity: restProps.integrity,
355+
nonce,
356+
crossOrigin: restProps.crossOrigin,
357+
}
358+
: { as: 'script', nonce, crossOrigin: restProps.crossOrigin }
354359
)
355360
return (
356361
<script
@@ -370,8 +375,13 @@ function Script(props: ScriptProps): JSX.Element | null {
370375
ReactDOM.preload(
371376
src,
372377
restProps.integrity
373-
? { as: 'script', integrity: restProps.integrity, nonce }
374-
: { as: 'script', nonce }
378+
? {
379+
as: 'script',
380+
integrity: restProps.integrity,
381+
nonce,
382+
crossOrigin: restProps.crossOrigin,
383+
}
384+
: { as: 'script', nonce, crossOrigin: restProps.crossOrigin }
375385
)
376386
}
377387
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ReactNode } from 'react'
2+
export default function Root({ children }: { children: ReactNode }) {
3+
return (
4+
<html>
5+
<body>{children}</body>
6+
</html>
7+
)
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Script from 'next/script'
2+
3+
export default function Page() {
4+
return (
5+
<Script
6+
src="https://code.jquery.com/jquery-3.7.1.min.js"
7+
crossOrigin="use-credentials"
8+
/>
9+
)
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
3+
describe('Script component with crossOrigin props', () => {
4+
const { next } = nextTestSetup({
5+
files: __dirname,
6+
})
7+
8+
it('should be set crossOrigin also in preload link tag', async () => {
9+
const browser = await next.browser('/')
10+
11+
const crossorigin = await browser
12+
.elementByCss('link[href="https://code.jquery.com/jquery-3.7.1.min.js"]')
13+
.getAttribute('crossorigin')
14+
15+
expect(crossorigin).toBe('use-credentials')
16+
})
17+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @type {import('next').NextConfig}
3+
*/
4+
const nextConfig = {}
5+
6+
module.exports = nextConfig

0 commit comments

Comments
 (0)