Repository navigation
Await the results of browser scripts from background handlers #7955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FarhanAliRaza
wants to merge
49
commits into
main
Choose a base branch
from
farhan/focused-darwin-dx76ek-await-results
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,494
−130
Open
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
a785b68
Await the results of browser scripts from background handlers
FarhanAliRaza e285c29
Keep timeout out of script event signatures
FarhanAliRaza 42ba65c
Format the awaited script result tests
FarhanAliRaza 154a894
Report script errors whose value cannot become text
FarhanAliRaza b33c046
Carry the browser call request id in the script event's payload
FarhanAliRaza 53e4424
Import the exceptions at the top of the CallScript test app
FarhanAliRaza 37feb97
Make BrowserScriptError picklable
FarhanAliRaza 1b647a4
Allow browser_call_timeout=None to wait without a limit
FarhanAliRaza 863c878
Keep the timeout of a browser call off the wire
FarhanAliRaza 717217d
Answer an awaited script even when its thrown value cannot be read
FarhanAliRaza e5d6617
Fail an awaited browser call at once when its page is gone
FarhanAliRaza 5916a61
Test awaited browser calls across dropped sockets and reloads
FarhanAliRaza 7bd31a0
Document the errors of awaited browser calls and their fixes
FarhanAliRaza 3402e53
Keep the timeout of a browser call when its spec is copied
FarhanAliRaza de666a7
Compare connect frames of two apps up to their random page id
FarhanAliRaza 3b8ab52
Copy only browser-call specs with dataclasses.replace
FarhanAliRaza 81ecfaa
Test a result too deep to parse without relying on the stack depth
FarhanAliRaza eaaa193
Describe an unreadable thrown value in one place
FarhanAliRaza 286e56a
Drop the one-caller wrappers around awaited browser calls
FarhanAliRaza 98d7a9e
Let each cancelled browser call cancel its own grace timer
FarhanAliRaza 0aff9c8
Trim the script event timeout tests to the PR's behavior
FarhanAliRaza f9e1af5
Start every waiting awaited script through one test helper
FarhanAliRaza 02865f8
Keep browser calls waiting for their tab after a refused reconnect
FarhanAliRaza 7766260
Check every interleaving of a tab's browser calls against their invar…
FarhanAliRaza 15fbc40
Test a refused connect with no linked token or no event processor
FarhanAliRaza b2a623b
Give the client token, page and request id of browser calls distinct …
FarhanAliRaza 50a4438
Run the grace period of browser calls until a connect is accepted
FarhanAliRaza ed33271
Reject a DOM node or window of an iframe as a browser call result
FarhanAliRaza 3d820f8
Reject a browser call timeout or grace period that is not finite
FarhanAliRaza 3ffae34
Import every browser call exception the docs name
FarhanAliRaza 6a3b98e
Say when a reload fails awaited calls and where to await them
FarhanAliRaza e83fc0d
Tell a DOM node from data without running the result's getters
FarhanAliRaza 937818c
Tell a window from data without reading the result's Symbol.toStringTag
FarhanAliRaza 8a86e16
Reject a call's browser timeout that is not positive seconds when the…
FarhanAliRaza 777f2bf
Await browser calls from their own spec instead of a branch of execut…
FarhanAliRaza 40c7e87
Fail an awaited script result too large for one message at once
FarhanAliRaza bf1e8a5
Keep awaited browser calls of a tab that reconnects under a new token
FarhanAliRaza 04ae88a
Say that a tab back on another backend worker loses an awaited result
FarhanAliRaza 989ab83
Fail awaited browser calls at once when a reload connects before its …
FarhanAliRaza 0d86612
Budget a polled script result together with the message that refers t…
FarhanAliRaza ed02ae5
Merge remote-tracking branch 'upstream/main' into farhan/focused-darw…
FarhanAliRaza 6a51647
Merge remote-tracking branch 'upstream/main' into farhan/focused-darw…
FarhanAliRaza e142fba
Cut a long error a script throws to fit a message to the backend
FarhanAliRaza b24ddab
Keep a clipped script error text within MAX_ERROR_TEXT, its ellipsis …
FarhanAliRaza c2ca742
Reconnect the call_script test tab with its current client token
FarhanAliRaza 94b6527
Merge branch 'main' into farhan/focused-darwin-dx76ek-await-results
claude afdf4b1
Name a stale frontend in the browser call timeout; document reload li…
FarhanAliRaza e6c4ba1
Test the result size check against a real socket.io-client
FarhanAliRaza 7c3d533
Name the polling test transport's pending flag apart from engine.io m…
FarhanAliRaza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| The backend receives the results of browser scripts that a background event handler awaits (`await rx.call_script(...)`), keeps those calls alive while their tab reconnects, and fails them with `BrowserDisconnectedError` when the reloaded page connects, or when no tab reconnects within `browser_call_grace_period`. |
11 changes: 11 additions & 0 deletions
11
packages/reflex-base/news/+await-browser-results.feature.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| A background event handler can now `await` `rx.call_script`, `rx.call_function` and `rx.run_script` outside `async with self` to get the script's result directly, instead of passing a `callback`: | ||
|
|
||
| ```python | ||
| @rx.event(background=True) | ||
| async def measure(self): | ||
| size = await rx.call_script("({w: window.innerWidth, h: window.innerHeight})") | ||
| async with self: | ||
| self.width = size["w"] | ||
| ``` | ||
|
|
||
| A script error raises `BrowserScriptError`, a missing result `TimeoutError` (`browser_call_timeout` in `rxconfig.py`, or `timeout=` per call), and a tab that is closed, reloaded or away longer than `browser_call_grace_period` raises `BrowserDisconnectedError`. Awaiting inside `async with self` raises `EventHandlerTypeError`. See [Awaiting Results](https://reflex.dev/docs/api-reference/browser-javascript/#awaiting-results). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.