Conditional `repeat` directive not removed from DOM
See original GitHub issueDescription
When using a repeat
directive that is based on a condition, and if that condition changes such that the repeat
directive will not be rendered anymore, the elements previously generated by repeat
are not removed from the DOM.
Steps to Reproduce
Put a repeat
directive behind a condition.
Live Reproduction Link
https://stackblitz.com/edit/u25pbw-jjbfqw (open console)
Expected Results
Repeat DOM disappears when condition changes to false.
Actual Results
Repeat DOM does not disappear.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Conditional `repeat` directive not removed from DOM · Issue #1007 ...
Description When using a repeat directive that is based on a condition, and if that condition changes such that the repeat directive will...
Read more >Built-in directives - Lit.dev
If no keyFn is provided, repeat will perform similar to a simple map of items to values, and DOM will be reused against...
Read more >angular - Apply a directive conditionally - Stack Overflow
Currently, there is NO way to conditionally apply a directive to a ... The components which you have created can be added or...
Read more >Using Directives - FAST design system
The when directive enables you to conditionally render blocks of HTML. ... Whether or not a repeat directive re-uses item views can be...
Read more >Built-in directives - Angular
Add or remove an element by applying an NgIf directive to a host element. When NgIf is false , Angular removes an element...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Interestingly with
nothing
therepeat
elements disappear, but they don’t reappear.While moving the condition to the list, not the
repeat
itself, is a neat work-around for this toy example, in reality things are more complicated if the condition is further up the DOM hierarchy. The fact that “this is somewhat expected [because] they generally don’t work well when used conditionally” is not something that is obvious to users of the library, and clearly not intended behavior. That’s why I think this should be considered a bug.This is fixed in 2.0: https://stackblitz.com/edit/lit-element-rau3qg?file=src%2Findex.js