You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit aefb36c
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/events/page_load_events.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,17 @@ def index():
41
41
return rx.text("A Beautiful App")
42
42
```
43
43
44
+
## Cancellation
45
+
46
+
Unfinished `on_load` event chains are cancelled when the client disconnects,
47
+
navigates to another page or reconnects. This includes events returned or yielded
48
+
by the page-load handler. A reconnect starts the new page's load events again.
49
+
Independent background events started outside the page-load chain continue
50
+
running after a disconnect.
51
+
52
+
Use `try`/`finally` to release resources when an async handler is cancelled. Avoid
53
+
suppressing `asyncio.CancelledError`, which prevents the handler from stopping.
54
+
44
55
## Handling Loading and Errors
45
56
46
57
Avoid heavy synchronous work directly in an `on_load` handler — the page renders before the handler finishes, so a slow handler leaves the user staring at stale or empty data with no feedback. Instead:
Cancel unfinished page-load event chains when the client disconnects, including hydration that has not yet started. Independent background events continue running.
0 commit comments