-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Dev mode validation of {#each} block argument #4408
Comments
haha and i asked for this in #4405 i would be happy to work on this, my first contribution to svelte |
@sw-yx sure 👍 Some pointers to help you started (if you need it 😉) :
|
yes i needed that help :) thanks vm |
update: i think since this is dev mode warning only, adding it in SSR is not needed? i looked at other devmode warnings and none of them are applied for SSR |
There are now hopefully more helpful dev mode errors if your |
Is your feature request related to a problem? Please describe.
Many people have been surprised when
{#each}
doesn't work with iterables, and there have been a number of issues about adding support for this - which we don't want to do, for reasons outlined elsewhere.Describe the solution you'd like
A dev mode only check that makes sure the argument to the
{#each}
block is an object with alength
property. If not, throw a descriptive runtime error about needing an array-like.If the object in question has a
Symbol.iterator
property, we could also add a note to the error about[...foo]
/Array.from(foo)
. We'd want to be careful to not accidentally cause a different error in js engines that don't haveSymbol.iterator
.This would probably be implemented by writing a new
validate_each_argument
(name tbd) function in the same vein asvalidate_store
orvalidate_each_keys
and only emit code to call it in dev mode.Describe alternatives you've considered
Do nothing. It's sort of worked so far.
How important is this feature to you?
The main reason it'd be important to me personally is that it might reduce the number of questions or issues about
{#each}
and iterables, which would be nice.Additional context
Not really.
The text was updated successfully, but these errors were encountered: