useScriptTag won't run script type: module second time #4510
Replies: 8 comments
-
maybe you can see this case: import { useScriptTag } from '@vueuse/core'
const { scriptTag, load, unload } = useScriptTag(
'https://player.twitch.tv/js/embed/v1.js',
() => {
// do something
},
{ manual: true },
)
// manual controls
await load()
await unload() use |
Beta Was this translation helpful? Give feedback.
-
I'm not following. The problem is that script with type=module loads twice, but doesn't execute twice. How's your example related to it? For starters, the twitch player is not a module script but a legacy CJS script. |
Beta Was this translation helpful? Give feedback.
-
@IlyaSemenov do you have a minimal reproduction of this issue? |
Beta Was this translation helpful? Give feedback.
-
@OrbisK I provided the minimal reproduction with the issue under Reproduction chapter, did you check it? https://stackblitz.com/edit/nuxt-starter-cbmqng It includes the steps to reproduce the problem: ![]() |
Beta Was this translation helpful? Give feedback.
-
You are right. I think I missed that one. Sorry. |
Beta Was this translation helpful? Give feedback.
-
@IlyaSemenov I have tried a few things. But I am pretty sure this is not a vueuse problem. It looks like the browser is caching some things. I have a workaround for you, if you add a random query param to the url it does not cache it. Like |
Beta Was this translation helpful? Give feedback.
-
I appreciate your help, but this workaround was listed in the beginning of the issue description:
If |
Beta Was this translation helpful? Give feedback.
-
Sorry. Worked on 10 topics at once yesterday 😅 I did some research. Looks like this is expected behaviour https://stackoverflow.com/a/64363954/17603999. The composable works as expected. I think what you want is:
This is also how most of the [Nuxt Scripts] (https://scripts.nuxt.com/) work. Hope it helps. I will convert this into a discussion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
Using
useScriptTag
with<script type="module">
doesn't work. The script will only execute (run its side effects) on first load, but it won't re-execute the second time.This is perhaps not a bug in the technical sense but rather lack of specific workarounds (e.g. adding
?v=<random>
to the URL fixes the problem, albeit being very suboptimal), but from user's point of view it's simply not working.Reproduction
https://stackblitz.com/edit/nuxt-starter-cbmqng
System Info
Used Package Manager
pnpm
Validations
Beta Was this translation helpful? Give feedback.
All reactions