diff --git a/solara/lab/toestand.py b/solara/lab/toestand.py index 3ad37250e..a64c903a5 100644 --- a/solara/lab/toestand.py +++ b/solara/lab/toestand.py @@ -486,7 +486,6 @@ def set(self, value): class AutoSubscribeContextManager: # a render loop might trigger a new render loop of a differtent render context # so we want to save, and restore the current reactive_used - reactive_used_before: Optional[Set[ValueBase]] = None reactive_used: Optional[Set[ValueBase]] = None reactive_added_previous_run: Optional[Set[ValueBase]] = None subscribed: Dict[ValueBase, Callable] @@ -499,7 +498,6 @@ def __enter__(self): self.reactive_used_before = thread_local.reactive_used self.reactive_used = thread_local.reactive_used = set() - def __exit__(self, exc_type, exc_val, exc_tb): assert thread_local.reactive_used is self.reactive_used, f"{hex(id(thread_local.reactive_used))} vs {hex(id(self.reactive_used))}" _, set_counter = solara.use_state(0, key="auto_subscribe_force_update_counter") @@ -544,7 +542,9 @@ def cleanup(): return cleanup solara.use_effect(on_close, []) - thread_local.reactive_used = self.reactive_used_before + + def __exit__(self, exc_type, exc_val, exc_tb): + pass # alias for compatibility diff --git a/tests/unit/lab/toestand_test.py b/tests/unit/lab/toestand_test.py index ee7b88ef3..9e3b59e7e 100644 --- a/tests/unit/lab/toestand_test.py +++ b/tests/unit/lab/toestand_test.py @@ -1036,3 +1036,22 @@ def Test(): assert mock2.call_count == 1 rc.close() + + +def test_reactive_var_in_use_effect(): + + var = Reactive(1) + + @solara.component + def Test(): + def modify(): + var.value = 2 + + solara.use_effect(modify) + # note: just pass the value, not the reactive variable + # otherwise the test passes. It is important *this* + # component listens to the reactive variable. + return solara.IntSlider("test", value=var.value) + + box, rc = solara.render(Test(), handle_error=False) + assert rc.find(v.Slider).widget.v_model == 2