Fix return gtmPlugin from app context
I have a problem with Vite inline, which in production mode just copies the useGtm function wholesale to the calling file, without copying the scope. This fix solves that problem, since it always fetches the gtm instance from the vue app context
Here's the bug in nuxt-gtm that this would solve (at least in my use-case): https://github.com/zadigetvoltaire/nuxt-gtm/issues/14
Looks like getCurrentInstance is there since Vue v3.0.0. So I guess this is safe.
https://github.com/vuejs/core/commit/9c0f820a8e4a934227175b2911090658064d6017
Is it possible to add a test for this? So we can prevent regression?
Is it possible to add a test for this? So we can prevent regression?
I'll see if I can come up with a way to test it. What triggered it in our case was two levels of indirection (it was initialized through nuxt-gtm and useGtm was called directly in our project, so I guess Vite couldn't connect the dots). I'll see if I can reproduce a similar sandbox.
Is it possible to add a test for this? So we can prevent regression?
I'll see if I can come up with a way to test it. What triggered it in our case was two levels of indirection (it was initialized through
nuxt-gtmanduseGtmwas called directly in our project, so I guess Vite couldn't connect the dots). I'll see if I can reproduce a similar sandbox.
Maybe spy or mocks can help to simplify it