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

Keyed each block does not render the {:else} clause #4536

Closed
Fygo opened this issue Mar 10, 2020 · 5 comments · Fixed by #4558
Closed

Keyed each block does not render the {:else} clause #4536

Fygo opened this issue Mar 10, 2020 · 5 comments · Fixed by #4558
Labels

Comments

@Fygo
Copy link

Fygo commented Mar 10, 2020

Description:
A keyed each block does not render its {:else} clause when there is 0 items in the store:
-it does render the clause after startup (on mount = render = or whatever I should call it)
-it does NOT render it when the items are removed during the existence of the component

REPL:
https://svelte.dev/repl/adc8c6b13f9b44aeaf80165bb786392a?version=3.19.2

You can see there is a store with a few items that are then just written out in an each block. Then there is a button which updates the store by setting an empty array to it.

Steps to reproduce:

  1. Run the REPL
  2. Click the 'Remove all' button

Result:
The {:else} clause not rendered.

Expected result:
The {:else} clause rendered.

Additional information:

  1. As mentioned above, starting with an empty store would actually render the {:else} clause.
  2. Removing the KEY (item.id) would make everything work correctly.

Am I missing something here? Why would the each block's key block the output of the else clause? This must be a bug...

@rproserpio
Copy link

Hi! It seems the bug was introduced in #4413.
The value of the updated array is in scope only in the each block and not in the else block.
I'm not really experienced with the codebase but i could try to submit a pr later.
The fix should be easy enough, but I could use some advice or example on what kind of test to write for this bug.

@bwbroersma
Copy link
Contributor

Good find! Make a simpler failing test case, e.g. REPL (working in 3.18.2).

See the runtime each-block-else test case. Probably the best is to make a keyed version for each-block-else, so each-block-keyed-else.

@rproserpio
Copy link

Thank you! I'll try in a few hours.

bwbroersma added a commit to bwbroersma/svelte that referenced this issue Mar 13, 2020
@bwbroersma
Copy link
Contributor

The test case above is just a copy of the each-block-else. Now it's only the task to make this failing test case succeed and not fail other test cases 🙂

image

@Conduitry
Copy link
Member

This has been fixed in 3.20.0 - https://svelte.dev/repl/adc8c6b13f9b44aeaf80165bb786392a?version=3.20.0

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