From 8d1dc5ef34951bdb286a537863c26b36591a78cc Mon Sep 17 00:00:00 2001 From: Iisakki Rotko Date: Wed, 17 Apr 2024 16:53:54 +0200 Subject: [PATCH] feat: check for key mutation when removing children --- reacton/core.py | 5 +++++ 1 file changed, 5 insertions(+) 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}"