Skip to content

Commit

Permalink
conditional render none should not reset state for sibling components
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Dec 10, 2023
1 parent 78b5651 commit 98d92e1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/py/reactpy/tests/test_core/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,3 +1320,26 @@ def Child():
{"tagName": "div", "children": [{"tagName": "", "children": []}]}
],
}


async def test_conditionally_render_none_does_not_trigger_state_change_in_siblings():
toggle_condition = Ref()
effect_run_count = Ref(0)

@component
def Root():
condition, toggle_condition.current = use_toggle(True)
return html.div("text" if condition else None, Child())

@component
def Child():
@reactpy.use_effect
def effect():
effect_run_count.current += 1

async with layout_runner(Layout(Root())) as runner:
await runner.render()
poll(lambda: effect_run_count.current).until_equals(1)
toggle_condition.current()
await runner.render()
assert effect_run_count.current == 1

0 comments on commit 98d92e1

Please sign in to comment.