next/script is not loading when navigating between pages
See original GitHub issueWhat version of Next.js are you using?
11.0.0
What version of Node.js are you using?
14.16.0
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying your application?
next start
Describe the Bug
next/script
is not loading when navigating between pages with next/link
, only if you load or reload the page outside of the SPA
Expected Behavior
the next/script
load normally
To Reproduce
npx create-next-app
- create any page, put a script url to load
- create a navigation (next/link) to the created page
- navigate to the page
index.js:
import Link from 'next/link'
export default function Home() {
return (
<div>
<Link href="/script" passHref><a>navigate to script</a></Link>
</div>
)
}
script.js:
import React from "react";
import Script from "next/script";
export default function script() {
return (
<>
<Script key="script_from_url" id="script_from_url" src="http://localhost:3000/script.js" strategy="beforeInteractive" onLoad={() => console.log("script loaded")} />
<div>script</div>
</>
);
}
Notes:
onLoad
is not being activated at any time with strategybeforeInteractive
- I am getting this error on the console when the script is first loaded (even though I put key and id in the
Script
props):
Warning: Each child in a list should have a unique “key” prop. See https://reactjs.org/link/warning-keys for more information.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
next js script is not working when navigating between the pages
I am using next/link for navigating between the pages for fast refreshing. The problem is it does not load script when I navigate...
Read more >Normal scripts "<script>" not working after page navigation
Normal scripts are working when the page is accessed for the first time or reloaded. It's not working when I navigate to any...
Read more >Script Loading, performance and Next Script
I have run tests on those pages through both webpage tests and PageSpeed Insights. Unfortunately, the results are not conclusive. The set up...
Read more >Optimizing third-party script loading in Next.js
It's important to consider the resource loading sequence of your page so that critical resources are not delayed and non-critical resources ...
Read more >Advanced Features: Custom `App` - Next.js
Custom App · Persist layouts between page changes · Keeping state when navigating pages · Inject additional data into pages · Add global...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
+1 for this For me, none of the Script tags load when i redirect or navigate to the page containing them, it’s only when i hit “refresh” that they then load.
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.