Closed kekkorider closed 1 year ago
Hey @kekkorider try the new release, I updated the core here https://github.com/Tresjs/nuxt/pull/35
@alvarosabu if you're talking about the 3.1.1
version, the error persists 🥲🔫
I meant updating the version of the @trejs/nuxt
.
Just updated @tresjs/nuxt
to 1.1.5
and nothing changed unfortunately 😕
Hey @danielroe I might need your support here. 😅
nuxtAppInstance = getCurrentInstance()?.appContext.app.$nuxt;
getCurrentInstance()
returns null
To fix the devtools, we introduce these changes on @tresjs.core@3.1.0
https://github.com/Tresjs/tres/pull/375/files#diff-d554b20c605a72c68b2d429ff9915cca4afa8e118026f56ede93382d130382a7
This means we don't longer mount a second app with the Tres renderer, We actually managed to have a "reconciliation" layer inside TresCanvas
. I think this is causing the' useNuxtApp' composable to break when used inside of the <TresCanvas />
context.
Any idea if we could potentially fix this?
Appreciate your time 🙏🏻
If this is purely client-side, you can access the current Nuxt app instance with window.useNuxtApp
(in the latest versions).
Just made a quick test 👇
const { $gsap } = useNuxtApp()
commented outlet gsap
variablegsap
variable inside the onMounted()
hook this way 👉 gsap = window.useNuxtApp().$gsap
This way, it works.
I also tested some other potential solutions, but none of these succeeded 👇
SampleBox.vue
to SampleBox.client.vue
<SampleBox />
with <ClientOnly />
in MyScene.client.vue
I'm not entirely sure of the details - maybe a reproduction would help me.
Ideally users wouldn't need to update their code, and should be able to use useNuxtApp
as is in their components.
Are all the Nuxt injections missing from the Tres canvas?
@danielroe thanks for the reply!
Have you checked the reproduction link? 👉 https://stackblitz.com/github/kekkorider/nuxt-tres-starter/tree/tresjs-core-3-1?file=components%2FSampleBox.vue
By default the application breaks, but if you follow my instructions you'll see that it works
- Keep
const { $gsap } = useNuxtApp()
commented out- Instantiate a
let gsap
variable- Set the value of the above
gsap
variable inside theonMounted()
hook this way 👉gsap = window.useNuxtApp().$gsap
Are all the Nuxt injections missing from the Tres canvas?
I tested a bunch of random composables provided by Nuxt, most of them don't work and trigger the same error.
useRoute()
❌useRouter()
❌useSeoMeta()
✅useFetch()
❌useState()
❌I think there will be a lot of situations where users expect to be able to access an injection provided by a module's plugin, for example. Might be worth considering how to proxy injections across? Depending on the lifecycle (is the tres app created subsequent to all nuxt plugins?) you might be able to pass the injections across.
Yeah users should be able to acces those
In the TresCanvas
we "mount" the renderer like this:
const mountCustomRenderer = (context: TresContext) => {
const InternalComponent = createInternalComponent(context)
render(h(InternalComponent), scene.value as unknown as TresObject)
}
Being render
a method from the customRenderer.
@danielroe to inject them would be at this level or in the nuxt module itself?
I have the same error here, any fix?
@danielroe been investigating a little bit and the problem is that when getCurrentInstance
is used inside a Tres component (Inside the context of the custom renderer) app
is null
Since all this composable on nuxt uses it, they get broken.
Actually, @enpitsulin helped us out with the custom render, there would be any way to provide the custom renderer the app
value of it's parent (the vue app)?
It seems that using the custom renderer will create appContext which doesn't contain context from the root Vue App(Like Nuxt provided), I think this is expected
use custom renderer will create separate contexts just like creating different App Instances, whether using the render
function or createApp
we need to provide useful context alone as TresJs does
but it's unreasonable, I think proxy the root App's context to the context created by the custom renderer might be a solution, but don't know how to :)
Hi @enpitsuLin thanks for your insights! I manually proxy the context of the vue wrapper app to the TresJS one, really manual, not sure if it's the best approach but, might fix the issue.
Do you mind to give it a look? Thanks for your support
Confirming that with the 1.1.6
version of @tresjs/nuxt
the error is gone.
Describe the bug
I tried upgrading the
@tresjs/core
package from3.0.1
to3.1.x
and now every attempt to use theuseNuxtApp()
composable breaks the application.Reproduction
https://stackblitz.com/github/kekkorider/nuxt-tres-starter/tree/tresjs-core-3-1?file=components%2FSampleBox.vue
Steps to reproduce
In
/components/SampleBox.vue
, comment out line 19, the one whereuseNuxtApp()
is used. The error will be gone.System Info
Used Package Manager
pnpm
Code of Conduct