forgetChild() 方法必须调用 super
概述
#最近一次全局 Key 复制检测重构现在要求重写 forgetChild()
方法的 Element
子类调用 super()
。
背景
#当遇到将被后续 Element 重建清理的全局 Key 复制时,我们不能报告全局 Key 复制。我们之前的实现会在检测到复制时立即抛出错误,而不会等待重建(如果具有复制全局 Key 的 Element 会被重建)。
新实现会在构建周期内跟踪所有全局 Key 复制,并在该周期结束后仅验证全局 Key 复制,而不是立即抛出错误。作为重构的一部分,我们在 forgetChild
中实现了一个机制,如果发生重建,则移除之前的全局 Key 复制。然而,这要求所有重写 forgetChild
的 Element
子类调用 super
方法。
变更说明
#抽象类 Element
的 forgetChild
方法有一个基础实现,用于移除全局 Key 预留,并且它由 @mustCallSuper
元标签强制执行。所有重写该方法的子类都必须调用 super
;否则,分析器会显示一个 linting 错误,并且全局 Key 复制检测可能会抛出意外错误。
迁移指南
#在下面的示例中,应用程序的 Element
子类重写了 forgetChild
方法。
迁移前的代码
dart
class CustomElement extends Element {
@override
void forgetChild(Element child) {
...
}
}
迁移后的代码
dart
class CustomElement extends Element {
@override
void forgetChild(Element child) {
...
super.forgetChild(child);
}
}
时间线
#发布版本: 1.16.3
稳定版本: 1.17
参考资料
#API 文档
相关问题
相关 PR