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

Passing component to nested slots gives TypeError: Cannot read property 'parentNode' of null #3548

Closed
jmhmd opened this issue Apr 6, 2021 · 7 comments · Fixed by #3554
Closed
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working

Comments

@jmhmd
Copy link

jmhmd commented Apr 6, 2021

Version

3.0.11

Reproduction link

https://codesandbox.io/s/naughty-carson-95syx?file=/src/App.vue

Steps to reproduce

Click the rendered dropdown button with the component included in the slot "popoverContent". Commenting out the component and refreshing gives expected behavior, toggling the popover with "hello".

What is expected?

Expect to be able to render arbitrary content, including other components, in the nested slots.

What is actually happening?

When a component is included in the nested slot content, an error is thrown: "TypeError: Cannot read property 'parentNode' of null."

This error goes away and normal behavior is seen when only text is included in the slot.


I am implementing a custom toolbar with buttons that can be passed content to be displayed in a popover. The component has a slot "popoverContent". then includes a component with a slot "content". The content is passed through those two slots. Including any other component in that slot content produces this error.

@HcySunYang HcySunYang added 🐞 bug Something isn't working 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Apr 7, 2021
@HcySunYang
Copy link
Member

HcySunYang commented Apr 7, 2021

Here is a workaround https://codesandbox.io/s/nostalgic-water-cjnrw?file=/src/ControlButton.vue, see the ControlButton.vue

Edit: #1745 (comment)

Also, if you are trying to check for presence of a slot, you should do !!$slots.default in the template (don't call it)

@HcySunYang HcySunYang added the has workaround A workaround has been found to avoid the problem label Apr 7, 2021
@Alanscut
Copy link
Contributor

Alanscut commented Apr 7, 2021

Removing && this.$slots.popoverContent() of the hasPopover function also works, that's strange...
https://codesandbox.io/s/eloquent-sun-29s91?file=/src/ControlButton.vue

@HcySunYang
Copy link
Member

The root cause of the problem is the same as #1745, I am thinking of a solution...

@jmhmd
Copy link
Author

jmhmd commented Apr 7, 2021

Thanks so much for the workaround! can confirm it is working for me.

@jmhmd
Copy link
Author

jmhmd commented Apr 9, 2021

FYI @HcySunYang when using your workaround, the same error re-appeared when using the production build (built with vite). @Alanscut solution (just removing function call) works in both dev and in production build.

@HcySunYang
Copy link
Member

Yeah, removing that is the correct and recommended workaround.

yyx990803 pushed a commit that referenced this issue May 25, 2021
…lls a compiled slot inside template expression (#3554)

fix #3548, partial fix for #3569
@RemMai
Copy link

RemMai commented Jul 14, 2021

老哥,我就问这个问题解决没有。
我使用

 <suspense>
    <router-view />
  </suspense>

包含子页面的时候,子页面全部是 async setup {} , 如果切换过快的话,会出现TypeError: Cannot read property 'parentNode' of null
而且后面 router.push() 无法进行跳转。

啥时候解决啊,谢谢大佬啊

@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working
Projects
None yet
4 participants