Skip to content

Commit e49f97c

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

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

reacton/core.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ def format(reason: RerenderReason):
14761476
for el in self._shared_elements_next:
14771477
logger.debug("\t%r %x", el, id(el))
14781478

1479-
logger.debug("Current elements:")
1479+
logger.debug("Current elements: %r", self._shared_elements)
14801480
for el in self._shared_elements:
14811481
logger.debug("\t %r %x", el, id(el))
14821482
if self.context_root.exceptions_children:
@@ -1564,7 +1564,10 @@ def format(reason: RerenderReason):
15641564

15651565
value = html.escape(error)
15661566
from . import ipywidgets as w
1567+
from pprint import pprint
15671568

1569+
print("EXCEPTION FROM REACTON", value, "\n")
1570+
pprint(self.container)
15681571
return self.render(w.HTML(value="<pre>" + value + "</pre>", layout=w.Layout(overflow="auto")), self.container)
15691572
else:
15701573
raise exc
@@ -2129,6 +2132,17 @@ def _remove_element(self, el: Element, default_key: str, parent_key):
21292132
new_parent_key = join_key(parent_key, key)
21302133
self._remove_element(self.context.root_element, "/", parent_key=new_parent_key)
21312134
finally:
2135+
try:
2136+
assert not child_context.elements, f"left over elements {child_context.elements}"
2137+
assert not child_context.element_to_widget, f"left over element_to_widget {child_context.element_to_widget}"
2138+
assert not child_context.widgets, f"left over widgets {child_context.widgets}"
2139+
assert not child_context.children, f"left over children {child_context.children}"
2140+
assert not child_context.owns, f"left over owns {child_context.owns}"
2141+
# TODO: this is not the case when an exception occurs
2142+
# assert not child_context.children_next, f"left over children {child_context.children_next}"
2143+
except Exception as e:
2144+
child_context.exceptions_self.append(e)
2145+
21322146
# restore context
21332147
self.context = context
21342148
if child_context.exceptions_self or child_context.exceptions_children and not child_context.exception_handler:
@@ -2163,14 +2177,6 @@ def _remove_element(self, el: Element, default_key: str, parent_key):
21632177
if el in context.element_to_widget:
21642178
del context.element_to_widget[el]
21652179
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}"
21742180

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

0 commit comments

Comments
 (0)