angular ngIf with animation, nested in ngFor, create clones of itself, when item is reordered "upwards"

ymzxtsji  于 2个月前  发布在  Angular
关注(0)|答案(3)|浏览(30)

哪个@angular/*包是bug的来源?

animations

这是个回归吗?

?

描述

ngIf 项目在 ngFor 列表中向上移动(而不是向下)时,以下代码模板出现故障。

<div *ngFor="let item of list$ | async; trackBy: trackFn">
  <div class="item">
    {{ item.text }}
    <div *ngIf="item.id === openItem()" [@State] class="sub-content">
      {{ item.text }} content
    </div>
  </div>
</div>

这个错误发生在 trackBy 函数返回 ngFor 项目id时,并且嵌套的 ngIf 元素具有动画。
请参阅下面的视频:
2023-12-11 14-19-04.webm
视频中的最终状态在下面的图片中显示,上面粘贴的模板代码生成了两个额外的div,每个向上移动一个。

请提供一个链接,用于最小化重现bug

https://stackblitz.com/edit/hswtny?file=src%2Fexample%2Flist-overview-example.html

请提供您看到的异常或错误

  • 无响应*

请提供您发现此bug的环境(运行 ng version )

Angular 17.0.6, in stackblitz

还有其他要说的吗?

视频错误地显示“当前构建:17.0.3”,实际上是17.0.6。

mspsb9vt

mspsb9vt1#

我目前正在研究这个问题,到目前为止,我注意到以下几点:

如果你查看"AnimationTransitionNamespace"中的"_signalRemovalForInnerTriggers"函数,你会发现在"向下移动"过程中,该函数不会被执行。然而,在"向上移动"过程中,该函数会被调用。然后,该函数会为所有子元素调用"clearElementCache",从而删除子元素的状态。我们是否可以检查一下,确保实际上想要清除子元素的缓存?不确定我是否走对了方向。

这能解决问题吗:

// If the child elements were removed along with the parent, their animations might not
// have completed. Clear all the elements from the cache so we don't end up with a memory leak.
this._engine.afterFlushAnimationsDone(() => elements.forEach(elm => {
  if (elm[REMOVAL_FLAG]) return;
  this.clearElementCache(elm);
}));
bqjvbblv

bqjvbblv2#

我已经在示例中将Angular更新到了17.2.1版本,但问题仍然存在。
感谢dominicbachmann对此的检查。

7bsow1i6

7bsow1i63#

我认为Angular团队的某个人应该查看这个问题。由于我对代码库的了解不足,无法对这个问题进行适当的评估。

相关问题