diff --git a/reacton/core.py b/reacton/core.py index 25f2aa8..cb40a1b 100644 --- a/reacton/core.py +++ b/reacton/core.py @@ -2129,7 +2129,12 @@ def _remove_element(self, el: Element, default_key: str, parent_key): new_parent_key = join_key(parent_key, key) self._remove_element(self.context.root_element, "/", parent_key=new_parent_key) finally: + def _check_key_mutation(child_context: ComponentContext): + for key, el in child_context.elements.items(): + if key != el._key: + raise RuntimeError(f"Key mismatch: {key} != {el._key}. Did you mutate a key?") try: + _check_key_mutation(child_context) assert not child_context.elements, f"left over elements {child_context.elements}" assert not child_context.element_to_widget, f"left over element_to_widget {child_context.element_to_widget}" assert not child_context.widgets, f"left over widgets {child_context.widgets}"