Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: proxy app context #394

Merged
merged 12 commits into from
Sep 11, 2023
Merged

fix: proxy app context #394

merged 12 commits into from
Sep 11, 2023

Conversation

alvarosabu
Copy link
Member

This might solve Tresjs/nuxt#33

@netlify
Copy link

netlify bot commented Sep 11, 2023

Deploy Preview for tresjs-docs ready!

Name Link
🔨 Latest commit 239308d
🔍 Latest deploy log https://app.netlify.com/sites/tresjs-docs/deploys/64ff54398667150008546bc5
😎 Deploy Preview https://deploy-preview-394--tresjs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@enpitsuLin
Copy link
Collaborator

I'm a little busy these days because I sent in my resignation last week :)

for that issue, I took some time to check how it happened, We can see here that does assign appContext in createApp, but using the render function didn't

https://github.com/vuejs/core/blob/b775b71c788499ec7ee58bc2cf4cd04ed388e072/packages/runtime-core/src/apiCreateApp.ts#L336C11-L336C11

I think just extend appContext and provides should work, but didn't test in nuxt module and globalProperties, separated multi repo makes testing difficult

diff --git a/src/components/TresCanvas.vue b/src/components/TresCanvas.vue
index 45b2fe8..d29cadf 100644
--- a/src/components/TresCanvas.vue
+++ b/src/components/TresCanvas.vue
@@ -18,7 +18,7 @@ import {
   Fragment,
   defineComponent,
   h,
-} from 'vue'
+  getCurrentInstance } from 'vue'
 import {
   useTresContextProvider,
   useLogger,
@@ -80,12 +80,25 @@ const { resume } = useRenderLoop()
 const slots = defineSlots<{
   default(): any
 }>()
+const instance = getCurrentInstance()!
 
 const createInternalComponent = (context: TresContext) =>
   defineComponent({
     setup() {
       provide('useTres', context)
       provide('extend', extend)
+      
+      const inner = getCurrentInstance()!
+      Object.assign(inner.appContext, instance.appContext)
+      //@ts-expect-error: internal property
+      Object.assign(inner.provides, inner.appContext.provides)
+      if (import.meta.env.DEV) {
+        //@ts-expect-error: internal property
+        inner.appContext.reload = () => {
+          mountCustomRenderer(context)
+        }
+      }
+
       return () => h(Fragment, null, slots?.default ? slots.default() : [])
     },
   })
@@ -157,7 +170,7 @@ onMounted(() => {
   if (!camera.value) {
     logWarning(
       'No camera found. Creating a default perspective camera. '
-        + 'To have full control over a camera, please add one to the scene.',
+      + 'To have full control over a camera, please add one to the scene.',
     )
     addDefaultCamera()
   }

@alvarosabu
Copy link
Member Author

Hi @enpitsuLin I really appreciate you taking the time, No worries. Get your stuff sorted out first. I will create a fake release on the next channel so we can test it in other repositories. 🤗

@alvarosabu alvarosabu merged commit 2301269 into main Sep 11, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants