Skip to content

Duplicating script component when using rewrite rule in config.next.js #28538

@zt1983811

Description

@zt1983811

What example does this report relate to?

next/script + rewrite rule

What version of Next.js are you using?

11.1.0

What version of Node.js are you using?

15.7.0

What browser are you using?

Chrome

What operating system are you using?

Macos/Linux

How are you deploying your application?

use codesandbox https://codesandbox.io/s/old-flower-wx1zm?file=/next.config.js

Describe the Bug

I see 2 times of script being generated by next/script when I have rewrites rule in next.config.js

Check following screenshot you have script with console.log 2 times being generated:
image

Please see the detail in codesandbox:
https://codesandbox.io/s/old-flower-wx1zm

Expected Behavior

only one script suppose be generated.

To Reproduce

  • add script in either _app.js or and pages component by next/script ie: in _app.js
import Script from "next/script";

function MyApp({ Component, pageProps }) {
  return (
    <>
      <Component {...pageProps} />
      <Script>console.log("this is duplicated")</Script>;
    </>
  );
}
export default MyApp;
  • create whatever rewrites rule in next.config.js
module.exports = {
  async rewrites() {
    return [
      {
        source: "/about",
        destination: "/"
      }
    ];
  }
};
  • Run page if script
    and search for script tag

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.please verify canaryPlease verify the issue with the latest canary branch.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions