Skip to content

Commit 1f228b4

Browse files
authored
fix: _remove_element failing silently when child objects left over (#34)
This used to happen with Solara, I think because https://github.com/widgetti/solara/blob/c8ca20f8b137058e7e2374ed2a024320808875be/solara/server/patch.py#L521-L539 would react to a widget being (unexpectedly) deleted before the exception from reacton would be rendered. The reason why we could have a situation where no exception was displayed would also be fixed by this change - previously any `AssertionError`s were not being added to any context exception list
1 parent 761281b commit 1f228b4

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
@@ -2125,6 +2125,17 @@ def _remove_element(self, el: Element, default_key: str, parent_key):
21252125
new_parent_key = join_key(parent_key, key)
21262126
self._remove_element(self.context.root_element, "/", parent_key=new_parent_key)
21272127
finally:
2128+
try:
2129+
assert not child_context.elements, f"left over elements {child_context.elements}"
2130+
assert not child_context.element_to_widget, f"left over element_to_widget {child_context.element_to_widget}"
2131+
assert not child_context.widgets, f"left over widgets {child_context.widgets}"
2132+
assert not child_context.children, f"left over children {child_context.children}"
2133+
assert not child_context.owns, f"left over owns {child_context.owns}"
2134+
# TODO: this is not the case when an exception occurs
2135+
# assert not child_context.children_next, f"left over children {child_context.children_next}"
2136+
except Exception as e:
2137+
child_context.exceptions_self.append(e)
2138+
21282139
# restore context
21292140
self.context = context
21302141
if child_context.exceptions_self or child_context.exceptions_children and not child_context.exception_handler:
@@ -2159,14 +2170,6 @@ def _remove_element(self, el: Element, default_key: str, parent_key):
21592170
if el in context.element_to_widget:
21602171
del context.element_to_widget[el]
21612172
del context.elements[key]
2162-
if isinstance(el.component, ComponentFunction):
2163-
assert not child_context.elements, f"left over elements {child_context.elements}"
2164-
assert not child_context.element_to_widget, f"left over element_to_widget {child_context.element_to_widget}"
2165-
assert not child_context.widgets, f"left over widgets {child_context.widgets}"
2166-
assert not child_context.children, f"left over children {child_context.children}"
2167-
assert not child_context.owns, f"left over owns {child_context.owns}"
2168-
# TODO: this is not the case when an exception occurs
2169-
# assert not child_context.children_next, f"left over children {child_context.children_next}"
21702173

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

0 commit comments

Comments
 (0)