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

"Cannot read property '0' of null" thrown when appending to empty array in slot content #2912

Closed
haferje opened this issue Dec 29, 2020 · 3 comments
Labels
🐞 bug Something isn't working scope: slots

Comments

@haferje
Copy link

haferje commented Dec 29, 2020

Version

3.0.4

Reproduction link

https://jsfiddle.net/haferje/fs458ycu/15/

Steps to reproduce

  1. open JSFiddle example link
  2. open console
  3. click "Add Item" button in example
  4. see console exception "Uncaught (in promise) TypeError: Cannot read property '0' of null"

What is expected?

I assume the Box component slot would render as blank or the default slot content, if the v-for acts on an empty array, but display the array items when it is mutated.

What is actually happening?

Upon adding an item to the empty array, the Box component re-renders its slot, but is trying to access the 0 index in patchBlockChildren(), which it didn't previously render. This throws an exception, but I would expect it to render a single item where there would previously be no items.


I would expect a v-for iterated tag in a component slot to show no items when the item array is empty, or show the default slot content. When I push an item on the array, I would expect the item to be shown in the slot and replace any default slot content. However, when the first item is pushed into the array, the patching logic throws an exception. It took me hours to understand why this was happening, but adding a container tag around the v-for tag (additional commented code in example) fixes the issue, but does prevent the default slot content from showing when the array is empty. Am I misunderstanding how this should work? I didn't find anything in the documentation that explains this behavior.

@haferje haferje changed the title v-for as slot content with empty array throws exception "Cannot read property '0' of null" "Cannot read property '0' of null" thrown when appending to empty array in slot content Dec 29, 2020
@LinusBorg LinusBorg added 🐞 bug Something isn't working scope: slots labels Dec 29, 2020
@posva
Copy link
Member

posva commented Dec 29, 2020

Wasn't this already fixed but not released?

@LinusBorg
Copy link
Member

Possible, could have missed that.

@posva
Copy link
Member

posva commented Dec 29, 2020

Tested on master and works
Duplicate of #2715

@posva posva closed this as completed Dec 29, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working scope: slots
Projects
None yet
Development

No branches or pull requests

3 participants