Skip to content

Commit e1567f9

Browse files
fix: tasks did not have a stable key, causing hot reloads to miss values
The key of the task was used also for the reactive variables, so if a reload with 2 users caused the keys to change, both pages would see a missing values. On later reloads it could go back to the old value again.
1 parent cf4f5c1 commit e1567f9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

solara/tasks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,15 @@ def Page():
772772
def wrapper(f: Union[None, Callable[P, Union[Coroutine[Any, Any, R], R]]]) -> Task[P, R]:
773773
# we use wraps to make the key of the reactive variable more unique
774774
# and less likely to mixup during hot reloads
775+
assert f is not None
776+
key = solara.toestand._create_key_callable(f)
777+
775778
@functools.wraps(f) # type: ignore
776779
def create_task():
777780
if inspect.iscoroutinefunction(f):
778-
return TaskAsyncio[P, R](prefer_threaded and has_threads, f, key=solara.toestand._create_key_callable(create_task))
781+
return TaskAsyncio[P, R](prefer_threaded and has_threads, f, key=key)
779782
else:
780-
return TaskThreaded[P, R](cast(Callable[P, R], f), key=solara.toestand._create_key_callable(create_task))
783+
return TaskThreaded[P, R](cast(Callable[P, R], f), key=key)
781784

782785
return cast(Task[P, R], Proxy(create_task))
783786

solara/toestand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def _check_mutation(self):
442442
raise ValueError(msg)
443443

444444

445-
def _create_key_callable(f: Callable[[], S]):
445+
def _create_key_callable(f: Callable):
446446
try:
447447
prefix = f.__qualname__
448448
except Exception:

0 commit comments

Comments
 (0)