vercel / next.js

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

[Script] Inline scripts do not work with the "worker" strategy #36318

Closed housseindjirdeh closed 2 years ago

housseindjirdeh commented 2 years ago

Verify canary release

Provide environment information

Any environment

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Embedding an inline script with next/script and the worker strategy shows a console error and the script is not executed in the web worker.

Example:

<Script
  id="gtm"
  strategy="worker"
  dangerouslySetInnerHTML={{
    __html: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
          new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
          j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
          'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
          })(window,document,'script','dataLayer','GTM-******');`,
  }}
/>;

Error:

Screen Shot 2022-04-20 at 12 30 52 PM

Expected Behavior

No error and that the script executes normally in the web worker.

To Reproduce

  1. Add experimental: { nextScriptWorkers: true } to next.config.js
  2. Install the required Partytown dependency
  3. Add an inline script to a page with <Script strategy="worker" ... />
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.