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

Missing ref owner context. ref cannot be used on hoisted vnodes. [ TransitionRoot with vite ] #3286

Open
gustawdaniel-statscore opened this issue Jun 12, 2024 · 1 comment
Assignees
Labels

Comments

@gustawdaniel-statscore
Copy link

gustawdaniel-statscore commented Jun 12, 2024

What package within Headless UI are you using?

"@headlessui/vue"

What version of that package are you using?

1.7.22

What browser are you using?

Chrome

Reproduction URL

I copied fragment from docs: https://headlessui.com/v1/vue/transition

<template>
  <button @click="isShowing = !isShowing">Toggle</button>
  <TransitionRoot :show="isShowing">
    I will appear and disappear.
  </TransitionRoot>
</template>

<script setup>
  import { ref } from 'vue'
  import { TransitionRoot } from '@headlessui/vue'

  const isShowing = ref(true)
</script>

and pasted into component called TransitionDebug

I have "vue": "3.4.14" with vite 5.

Describe your issue

I added this component to app inside of Setting component and after page load I see

main.ts:22 [Vue warn]: Missing ref owner context. ref cannot be used on hoisted vnodes. A vnode with ref must be created inside the render function. 
  at <Anonymous onBeforeEnter=fn<onBeforeEnter> onAfterEnter=fn<onAfterEnter> onBeforeLeave=fn<onBeforeLeave>  ... > 
  at <Anonymous show=true > 
  at <TransitionDebug> 
  at <Settings onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > > 
  at <RouterView> 
  at <App>

I can see paragraph I will appear and disappear.

When I clicking toggle button, I see warning in console

TransitionDebug.vue:2 [Vue warn]: Missing ref owner context. ref cannot be used on hoisted vnodes. A vnode with ref must be created inside the render function. 
  at <Anonymous onBeforeEnter=fn<onBeforeEnter> onAfterEnter=fn<onAfterEnter> onBeforeLeave=fn<onBeforeLeave>  ... > 
  at <Anonymous show=false > 
  at <TransitionDebug> 
  at <Settings onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< Proxy(Object) {saveSettings: ƒ, …} > > 
  at <RouterView> 
  at <App>

but paragraph is constantly displayed.


I have another project with nuxt, where this error is not possible to reproduce.


Potentially linked issues:
#959 Bug: Dialog and TransitionRoot is not working as documented
#2939 Transition broken with vue v3.4.15


Update

Now inspired by @albertpratomo I fixing by

  <transition name="fade">
    <span v-if="isShowing">I will appear and disappear.</span>
  </transition>

instead of

  <TransitionRoot :show="isShowing">
    I will appear and disappear.
  </TransitionRoot>
@thecrypticace thecrypticace self-assigned this Jun 13, 2024
@thecrypticace
Copy link
Contributor

Can you provide the project where you see this error? I do not see it in a fresh Vite project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants