test: add test for snabbdom mutating old children #2602
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Details
See discussion here: #2589 (comment)
Prior to this PR, we didn't have any Jest or Karma tests to exercise the
else
block in this code path (line 133):lwc/packages/@lwc/engine-core/src/3rdparty/snabbdom/snabbdom.ts
Lines 127 to 146 in d93e296
This PR adds a test that does hit this line of code:
Interestingly, the
if
block here seems completely unreachable:lwc/packages/@lwc/engine-core/src/3rdparty/snabbdom/snabbdom.ts
Line 136 in d93e296
The only way it could be reached is if two VNodes with two different tags (e.g.
x-foo
andx-bar
) occupy the same positions in the children array. I tried to repro this using both:lwc:dynamic
and<template if:true>
inside of a<template for:each>
…but neither seem to work. In the case of (1), the dynamic component has the same tag name (e.g.
x-dynamic
) regardless of whether it's actuallyx-foo
orx-bar
under the hood, and in the case of (2) there are holes in the array for the<template if:true>
and<template if:false>
, so two different element types cannot occupy the same index in the array.We can probably remove that part of the code, but I'd prefer not to, because maybe someday we will refactor our templates to avoid creating holes for if/else blocks?
Does this pull request introduce a breaking change?
Does this pull request introduce an observable change?