Skip to content

Commit

Permalink
Merge pull request #33 from widgetti/fix_no_effect_call_on_exceptions
Browse files Browse the repository at this point in the history
fix: do not call effects when an exceptions occurs.
  • Loading branch information
maartenbreddels authored Apr 17, 2024
2 parents 7ac42e8 + f6068ba commit d6e022f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions reacton/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,9 @@ def _reconsolidate(self, el: Element, default_key: str, parent_key: str):
context.needs_render = True
effect = child_context.effects[effect_index] = effect.next
try:
if child_context.exceptions_self or child_context.exceptions_children:
# we had an exception, so we skip the effect (not the cleanup)
continue
effect()
except BaseException as e:
context.exceptions_self.append(e)
Expand All @@ -1899,6 +1902,9 @@ def _reconsolidate(self, el: Element, default_key: str, parent_key: str):
context.needs_render = True
else:
try:
if child_context.exceptions_self or child_context.exceptions_children:
# we had an exception, so we skip the effect (not the cleanup)
continue
effect()
except BaseException as e:
context.exceptions_self.append(e)
Expand Down
22 changes: 22 additions & 0 deletions reacton/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,28 @@ def Test():
rc.close()


def test_exception_in_child_no_run_effect():
set_fail = None

mock = unittest.mock.Mock()

@react.component
def Test():
nonlocal set_fail
children = v.Btn(children=[1])
# we do not want to run this effect
use_effect(mock, [])
return children

box, rc = react.render(Test(), handle_error=True)
assert not mock.called

assert not rc.find(ipyvuetify.Btn)
assert "Traceback" in rc.find(ipywidgets.HTML).widget.value

rc.close()


def test_state_get():
set_value = None

Expand Down

0 comments on commit d6e022f

Please sign in to comment.