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 undefined" when a component tracks more than 32 values and uses a slotted component with a prop on the slot. #4624

Closed
dimfeld opened this issue Apr 2, 2020 · 3 comments · Fixed by #4862
Labels

Comments

@dimfeld
Copy link
Contributor

dimfeld commented Apr 2, 2020

My scenario: A main component includes a slotted child component. The child component has a slot which passes a prop back to the parent. The main component is tracking enough variables to make dirty be an array. When the slot prop changes, an error occurs.

To Reproduce
Open this REPL, open the console, and click the Toggle button. See that an error occurs: Cannot read property '0' of undefined.
https://svelte.dev/repl/8f6205fdd9d04a5aa250c1c67f6efbce?version=3.20.1

When the child component's slot prop changes, an error is thrown as the update is communicated back to the parent. It appears that the call to get_slot_changes in the child component's update function is returning undefined.

Expected behavior
No error is thrown.

Information about your Svelte project:
Svelte 3.20.1 (see REPL)

Severity

Important but not blocking. Svelte 3.15 before the dirty bitmask change works, so I've been able to revert to that, but I am using some features that were added in later versions, such as referencing a slot variable in an attribute of the slot (e.g. <tr slot="row" let:row class:finished={row.finished}>...). I have worked around the lack of 3.16+ features for now.

@dimfeld
Copy link
Contributor Author

dimfeld commented Apr 2, 2020

It appears that this is specifically related to the slot in the parent NOT using the slot prop. In the REPL, if I add let:open in the parent then it works, even if I never actually use open.

In the breaking case, I see that the definition passed to get_slot_changes contains a single entry, the function to create the slot. When I add let:open, I see that definition has two more entries, and so the check for definition[2] && fn returns true, leading to the working code path. Seems like the obvious fix is to always generate the extra two entries in definition even if they would do nothing, but I'm not familiar enough with the Svelte internals to say for sure.

I've confirmed that this workaround also fixes the problem in my actual codebase, so I'm no longer blocked.

@Rich-Harris
Copy link
Member

Fixed in the next release via #4862

@Conduitry
Copy link
Member

The fix has been released in 3.23.0 - https://svelte.dev/repl/8f6205fdd9d04a5aa250c1c67f6efbce?version=3.23.0

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

Successfully merging a pull request may close this issue.

3 participants