-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Closed
Labels
bugIssue was opened via the bug report template.Issue was opened via the bug report template.please verify canaryPlease verify the issue with the latest canary branch.Please verify the issue with the latest canary branch.
Description
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:

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.jsor 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
Labels
bugIssue was opened via the bug report template.Issue was opened via the bug report template.please verify canaryPlease verify the issue with the latest canary branch.Please verify the issue with the latest canary branch.