From 68c57fb67f6aca4474883aa03bbec2ecdf2e042d Mon Sep 17 00:00:00 2001 From: Hixie Date: Mon, 28 Sep 2015 11:53:03 -0700 Subject: [PATCH] Require giving a GlobalKey to UniqueComponent Having UniqueComponent automatically generate its own key is a trap. If anyone ever creates a UniqueComponent in a build function (rather than ahead of time) and forgets to pass a key, then that entire subtree is going to be rebuilt, including layout, every time it's updated. Since there's basically no way for us to catch this, we should at least force the author to see the explicit "new GlobalKey()" call in their code. --- sky/packages/sky/lib/src/fn3/unique_component.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sky/packages/sky/lib/src/fn3/unique_component.dart b/sky/packages/sky/lib/src/fn3/unique_component.dart index c3ef3664185..560d3b44770 100644 --- a/sky/packages/sky/lib/src/fn3/unique_component.dart +++ b/sky/packages/sky/lib/src/fn3/unique_component.dart @@ -5,7 +5,9 @@ import 'package:sky/src/fn3.dart'; abstract class UniqueComponent extends StatefulComponent { - UniqueComponent({ GlobalKey key }) : super(key: key ?? new GlobalKey()); + UniqueComponent({ GlobalKey key }) : super(key: key) { + assert(key != null); + } T createState();