vercel / next.js

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

data-nscript attribue breaks some third party scripts #35146

Closed wlhtck closed 2 years ago

wlhtck commented 2 years ago

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:42 PST 2022; root:xnu-7195.141.19~2/RELEASE_X86_64
Binaries:
  Node: 12.21.0
  npm: 6.14.11
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.1.1-canary.7
  react: 17.0.2
  react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Other Platform

Describe the Bug

As of Next12 it looks like NextJS is adding a data attribute (data-nscript) to scripts rendered by the built in Script Tag. This behavior breaks a key third script in our application which uses data attributes for configuring and therefore prevents upgrading from Next11 to Next12. As far as I can tell this behavior is undocumented and not possible to control. Please see the attached screen shots for the impact of this data attribute for our use case:

NextScript1 NextScript2 NextScript3

Expected Behavior

I'm not entirely sure why NextJS is adding this data attribute, but it would be helpful if we could somehow opt out of it.

To Reproduce

Use the Script tag in Next12 or later. Note the data-nscript attribute that is added to the DOM.

SukkaW commented 2 years ago

IMHO it is not a bug of Next.js. Because not only data-nscript but any extra attributes (type="application/javascript", or type="text/javascript", or language="javascript", or charset="UTF-8") will throw the error as well:

<!-- All of examples below will cause the error -->
<script type="application/javascript" src="..."></script>
<script type="text/javascript" src="..."></script>
<script language="javascript" src="..."></script>
<script charset="UTF-8" src="..."></script>

You should report the bug to the vendor instead.

timneutkens commented 2 years ago

Agreed, thanks for looking at this @SukkaW 👏

github-actions[bot] commented 2 years ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.