Open
Description
The swapComponent
/swapStyle
/swapTemplate
APIs do not work correctly in the following scenario (using swapStyle
to illustrate):
/* initial state */ // works - A is rendered
swapStyle(a, b) // works - B is rendered
swapStyle(b, a) // works - A is rendered
swapStyle(a, b) // does not work! A is still rendered
The reason for this is this line:
The swappedStyleMap
only ever grows – it never shrinks. So after swapping A and B a few times, we end up with the mappings:
A -> B
B -> A
Next, consider this code:
lwc/packages/@lwc/engine-core/src/framework/hot-swaps.ts
Lines 110 to 120 in e7377d2
There is a visited
set to avoid infinite loops. However, if we have entries for both A -> B
and B -> A
, then calling this function with A
will always return A
. This is why the third swapStyle
above doesn't work.
Related: #4115
Minimal repro: nolanlawson@3a135df
Activity