The ability to update <Script /> component's src #64612
Replies: 6 comments
-
Hi ! I really want to join this open project, how can i do to apply ? |
Beta Was this translation helpful? Give feedback.
-
One alternative is using dangerouslySetInnerHTML: <div
dangerouslySetInnerHTML={{
__html: `
<script
src="https://www.googletagmanager.com/gtag/js?id=${id}"
></script>
`,
}}
></div> |
Beta Was this translation helpful? Give feedback.
-
@guilhermefront Would that remove the previous script? |
Beta Was this translation helpful? Give feedback.
-
@Ansvyager What do you mean? If you want to contribute to Next.js, I recommend you start with those introductory issues: issues/good-first-issues |
Beta Was this translation helpful? Give feedback.
-
I tested here and it replaces that script. See this codesandbox if you want to try anything. |
Beta Was this translation helpful? Give feedback.
-
@guilhermefront Thank you for your answer. It's the best we got so far, but unfortunately, when we tried it, the old script's variables and functions are still in the memory, so there has to be a reload. |
Beta Was this translation helpful? Give feedback.
-
Describe the feature you'd like to request
We're trying to integrate Google Analytics into our multi-language website.
Each country has a different
id
that we use to upload its relevant script via Next's<Script />
component.The problem is that when the id changes, the
<Script />
'ssrc
stays with the first value it received.Describe the solution you'd like
Is it possible that when the
id
changes, the first script gets replaced by a new script with the newsrc
value?Describe alternatives you've considered
We tried injecting native HTML
<script>
tag inuseEffect()
, but it didn't execute.Beta Was this translation helpful? Give feedback.
All reactions