Skip to content

Commit 173e73e

Browse files
committed
fix: _remove_element failing silently when child objects left over
1 parent d6e022f commit 173e73e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

reacton/core.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,17 @@ def _remove_element(self, el: Element, default_key: str, parent_key):
21292129
new_parent_key = join_key(parent_key, key)
21302130
self._remove_element(self.context.root_element, "/", parent_key=new_parent_key)
21312131
finally:
2132+
try:
2133+
assert not child_context.elements, f"left over elements {child_context.elements}"
2134+
assert not child_context.element_to_widget, f"left over element_to_widget {child_context.element_to_widget}"
2135+
assert not child_context.widgets, f"left over widgets {child_context.widgets}"
2136+
assert not child_context.children, f"left over children {child_context.children}"
2137+
assert not child_context.owns, f"left over owns {child_context.owns}"
2138+
# TODO: this is not the case when an exception occurs
2139+
# assert not child_context.children_next, f"left over children {child_context.children_next}"
2140+
except Exception as e:
2141+
child_context.exceptions_self.append(e)
2142+
21322143
# restore context
21332144
self.context = context
21342145
if child_context.exceptions_self or child_context.exceptions_children and not child_context.exception_handler:
@@ -2163,14 +2174,6 @@ def _remove_element(self, el: Element, default_key: str, parent_key):
21632174
if el in context.element_to_widget:
21642175
del context.element_to_widget[el]
21652176
del context.elements[key]
2166-
if isinstance(el.component, ComponentFunction):
2167-
assert not child_context.elements, f"left over elements {child_context.elements}"
2168-
assert not child_context.element_to_widget, f"left over element_to_widget {child_context.element_to_widget}"
2169-
assert not child_context.widgets, f"left over widgets {child_context.widgets}"
2170-
assert not child_context.children, f"left over children {child_context.children}"
2171-
assert not child_context.owns, f"left over owns {child_context.owns}"
2172-
# TODO: this is not the case when an exception occurs
2173-
# assert not child_context.children_next, f"left over children {child_context.children_next}"
21742177

21752178
def _visit_children(self, el: Element, default_key: str, parent_key: str, f: Callable):
21762179
assert self.context is not None

0 commit comments

Comments
 (0)