Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/next/src/client/script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
)
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/app-dir/next-script/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
10 changes: 10 additions & 0 deletions test/e2e/app-dir/next-script/app/page.js
Original file line number Diff line number Diff line change
@@ -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"
/>
)
}
32 changes: 32 additions & 0 deletions test/e2e/app-dir/next-script/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createNext } from 'e2e-utils'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move to nextTestSetup? You can easily generate via pnpm new-test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing command! It's awesome. I created new test with pnpm new-test now.

import { NextInstance } from '../../../lib/next-modes/base'
import { BrowserInterface } from '../../../lib/browsers/base'

describe('Script component with crossOrigin props', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: __dirname,
})
})
afterAll(() => next.destroy())

it('should be set crossOrigin also in preload link tag', async () => {
let browser: BrowserInterface

try {
browser = await next.browser('/')

expect(
await browser
.elementByCss(
'link[href="https://code.jquery.com/jquery-3.7.1.min.js"]'
)
.getAttribute('crossorigin')
).toBe('use-credentials')
} finally {
if (browser) await browser.close()
}
})
})
Loading