S
Solara2mo ago
ntjess

State updates don't trigger page rerender in some cases

I have a @solara.component that immediately sets a reactive state to True. When this happens, the page fails to rerender:
import solara as sl


@sl.component
def MakeTrue(variable: sl.Reactive[bool]):
variable.set(True)


@sl.component
def Page():
x = sl.use_reactive(False)
MakeTrue(x)
sl.Text(str(x.value))
# Prints "False"

Page()
import solara as sl


@sl.component
def MakeTrue(variable: sl.Reactive[bool]):
variable.set(True)


@sl.component
def Page():
x = sl.use_reactive(False)
MakeTrue(x)
sl.Text(str(x.value))
# Prints "False"

Page()
Is this expected behavior?
4 Replies
Monty Python
Monty Python2mo ago
iisakkirotko
<:issue_open:882464248951877682> [widgetti/solara] No page re-render despite change in reactive value
On initial load, the page is not re-rendered even though the value of a reactive variable changes. In the example below, when the page is initially loaded, the value of var, as displayed in the Text component is None, even though in both the InputText and via clicking on the button, we find that the value has actually changed to become '!!!', see screenshot.
import solara

var = solara.Reactive(None)

def on_click():
print(var)

@solara.component
def BugComponent(
value: solara.Reactive[str],
on_value = None,
):

def on_change(event_value):
value.set(event_value)

if value.value is None:
value.set('!!!')

return solara.InputText(label='', value=value, on_value=on_change)

@solara.component
def Page():
BugComponent(value = var)

solara.Text(f"{var}")
solara.Button('click', on_click=on_click)
import solara

var = solara.Reactive(None)

def on_click():
print(var)

@solara.component
def BugComponent(
value: solara.Reactive[str],
on_value = None,
):

def on_change(event_value):
value.set(event_value)

if value.value is None:
value.set('!!!')

return solara.InputText(label='', value=value, on_value=on_change)

@solara.component
def Page():
BugComponent(value = var)

solara.Text(f"{var}")
solara.Button('click', on_click=on_click)
Labels
bug
Created
iisakkirotko
iisakkirotko2mo ago
(Sorry to say there's no solution yet... we suspect fixing might require quite some effort)
ntjess
ntjessOP2mo ago
👍 Thanks for the reply. In the meantime, is there a heuristic to anticipate when this happens, or any workaround?

Did you find this page helpful?