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

Scripts don't work outside of Head in _document #44930

Open
1 task done
NiedziolkaMichal opened this issue Jan 16, 2023 · 0 comments
Open
1 task done

Scripts don't work outside of Head in _document #44930

NiedziolkaMichal opened this issue Jan 16, 2023 · 0 comments
Labels
template: bug A user has filled out the bug report template. Issue needs triaging

Comments

@NiedziolkaMichal
Copy link
Contributor

NiedziolkaMichal commented Jan 16, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Home
Binaries:
  Node: 19.4.0
  npm: N/A
  Yarn: N/A
  pnpm: 7.22.0
Relevant packages:
  next: 13.1.3-canary.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Script optimization (next/script)

Link to the code that reproduces this issue

https://github.com/NiedziolkaMichal/next-document-script-bug

To Reproduce

_document contains the following code:

export default function Document() {
  return (
    <Html lang="en">
      <Head>
          <Script src="/script-1.js" strategy="beforeInteractive" />
          <Script2 />
      </Head>
      <Script src="/script-3.js" strategy="beforeInteractive" />
      <body>
        <Main />
        <NextScript />
      </body>
    </Html>
  );
}

function Script2({}) {
    return <Script src="/script-2.js" strategy="beforeInteractive" />
}

While each script file contains only console.log, outputting its index.

Describe the Bug

Only script-1.js is executed.

Expected Behavior

All 3 scripts should be executed, in the same order as they are placed.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@NiedziolkaMichal NiedziolkaMichal added the template: bug A user has filled out the bug report template. Issue needs triaging label Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
template: bug A user has filled out the bug report template. Issue needs triaging
Projects
None yet
Development

No branches or pull requests

1 participant