Improve asserts on Element.mount (#153477)

## Description

In debugging an issue with mount, I hit one of these asserts, and I thought it would be a much better assert with some context.

## Tests
 - No test changes because the change is only to the output string of an assert.
This commit is contained in:
Greg Spencer 2024-08-15 14:30:03 -07:00 committed by GitHub
parent ce63c029c5
commit 1633c47dda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4217,10 +4217,22 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
/// method, as in `super.mount(parent, newSlot)`. /// method, as in `super.mount(parent, newSlot)`.
@mustCallSuper @mustCallSuper
void mount(Element? parent, Object? newSlot) { void mount(Element? parent, Object? newSlot) {
assert(_lifecycleState == _ElementLifecycle.initial); assert(
assert(_parent == null); _lifecycleState == _ElementLifecycle.initial,
assert(parent == null || parent._lifecycleState == _ElementLifecycle.active); 'This element is no longer in its initial state (${_lifecycleState.name})',
assert(slot == null); );
assert(
_parent == null,
"This element already has a parent ($_parent) and it shouldn't have one yet.",
);
assert(
parent == null || parent._lifecycleState == _ElementLifecycle.active,
'Parent ($parent) should be null or in the active state (${parent._lifecycleState.name})',
);
assert(
slot == null,
"This element already has a slot ($slot) and it shouldn't",
);
_parent = parent; _parent = parent;
_slot = newSlot; _slot = newSlot;
_lifecycleState = _ElementLifecycle.active; _lifecycleState = _ElementLifecycle.active;