vercel / next.js

The React Framework
https://nextjs.org
MIT License
121.81k stars 26.05k forks source link

When using `<Script>` with `crossorigin` specified, `crossorigin` is missing from `<link>` that preloads the script #65879

Open mwskwong opened 2 weeks ago

mwskwong commented 2 weeks ago

Link to the code that reproduces this issue

https://github.com/mwskwong/missing-cross-origin-from-preload-script

To Reproduce

  1. Build the project
  2. In index.html, observe the <link> that preloads the ad sense script https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js. Note that crossorigin="anonymous" is missing from <link> despite it is specified in <Script>

Current vs. Expected behavior

Current

When including a script with crossOrigin set:

<Script
  async
  crossOrigin="anonymous"
  src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"
/>

crossorigin is missing from the <link> that preloads the script.

Expected

For <link>, crossorigin should be set to the same value as that in <Script>.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 32493
  Available CPU cores: 20
Binaries:
  Node: 20.12.2
  npm: N/A
  Yarn: N/A
  pnpm: 8.14.1
Relevant Packages:
  next: 14.3.0-canary.68 // Latest available version is detected (14.3.0-canary.68).
  eslint-config-next: 14.3.0-canary.68
  react: 19.0.0-beta-04b058868c-20240508
  react-dom: 19.0.0-beta-04b058868c-20240508
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Script (next/script)

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), Vercel (Deployed)

Additional context

No response