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

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

Closed
1 task done
housseindjirdeh opened this issue Apr 20, 2022 · 1 comment · Fixed by #36364
Closed
1 task done

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

housseindjirdeh opened this issue Apr 20, 2022 · 1 comment · Fixed by #36364
Assignees
Labels
Script (next/script) Related to Next.js Script Optimization.

Comments

@housseindjirdeh
Copy link
Collaborator

Verify canary release

  • I verified that the issue exists in Next.js 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" ... />
@housseindjirdeh housseindjirdeh added the bug Issue was opened via the bug report template. label Apr 20, 2022
@housseindjirdeh housseindjirdeh self-assigned this Apr 20, 2022
@balazsorban44 balazsorban44 added Script (next/script) Related to Next.js Script Optimization. kind: bug and removed bug Issue was opened via the bug report template. labels Apr 22, 2022
janicklas-ralph added a commit to housseindjirdeh/next.js that referenced this issue Apr 22, 2022
housseindjirdeh added a commit to housseindjirdeh/next.js that referenced this issue Apr 25, 2022
ijjk added a commit to housseindjirdeh/next.js that referenced this issue Apr 29, 2022
@kodiakhq kodiakhq bot closed this as completed in #36364 Apr 29, 2022
kodiakhq bot pushed a commit that referenced this issue Apr 29, 2022
…eforeInteractive` strategies (#36364)

Adds inline script functionality to `next/script` for `worker` and `beforeInteractive` strategies. 

- fixes #36318 
- fixes #26343
- fixes #26591
- fixes #26343
- fixes #26240


Co-authored-by: Janicklas Ralph <6142074+janicklas-ralph@users.noreply.github.com>
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Script (next/script) Related to Next.js Script Optimization.
Projects
None yet
2 participants