Skip to content
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

Mobile queue fixes #4742

Merged
merged 46 commits into from Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ad98cb4
changes
aliabid94 Jun 14, 2023
fe5dee0
Merge branch 'main' into info_modal
abidlabs Jun 14, 2023
56afa6f
changes
aliabid94 Jun 15, 2023
b196c38
changes
aliabid94 Jun 15, 2023
53d24f8
Merge branch 'info_modal' of https://github.com/gradio-app/gradio int…
aliabid94 Jun 15, 2023
256ce30
changes
aliabid94 Jun 15, 2023
e1a7242
Merge branch 'main' into info_modal
aliabid94 Jun 15, 2023
eeffeec
Merge branch 'main' into info_modal
abidlabs Jun 15, 2023
dfed2e6
changes
aliabid94 Jun 15, 2023
e7c0007
Merge branch 'info_modal' of https://github.com/gradio-app/gradio int…
aliabid94 Jun 15, 2023
07321dc
Styling for error, warning and info toasts (#4603)
hannahblair Jun 22, 2023
0a2e0d6
chagnes
aliabid94 Jun 27, 2023
8bb18a3
changes
aliabid94 Jun 27, 2023
69c05ec
changes
aliabid94 Jun 27, 2023
b96f303
changes
aliabid94 Jun 27, 2023
1f04c52
changes
aliabid94 Jun 27, 2023
76b33fc
changes
aliabid94 Jun 27, 2023
2442d4e
changes
aliabid94 Jun 27, 2023
35a1f4f
changes
aliabid94 Jun 27, 2023
4a6a00c
chanegs
aliabid94 Jun 27, 2023
350698a
changes
aliabid94 Jun 27, 2023
b9ce360
changes
aliabid94 Jun 29, 2023
2120b43
changes
aliabid94 Jun 30, 2023
2422d1d
chagnes
aliabid94 Jun 30, 2023
4832121
changes
aliabid94 Jun 30, 2023
ffd04ca
changes
aliabid94 Jun 30, 2023
29d257b
changes
aliabid94 Jun 30, 2023
434546a
changes
aliabid94 Jun 30, 2023
7600b69
changes
aliabid94 Jun 30, 2023
d905aa0
changes
aliabid94 Jun 30, 2023
c9f55d2
changes
aliabid94 Jun 30, 2023
3bf4044
changes
aliabid94 Jun 30, 2023
6530910
changes
aliabid94 Jun 30, 2023
7203c98
changes
aliabid94 Jun 30, 2023
dc7437d
changes
aliabid94 Jul 6, 2023
457055a
Merge remote-tracking branch 'origin' into mobile_queue_fixes
aliabid94 Jul 6, 2023
fb8c9f7
changes
aliabid94 Jul 6, 2023
d72fe2f
Merge remote-tracking branch 'origin' into mobile_queue_fixes
aliabid94 Jul 6, 2023
2b1d070
changes
aliabid94 Jul 6, 2023
aefe5ed
changes
aliabid94 Jul 6, 2023
f2afbc7
changes
aliabid94 Jul 6, 2023
32f8c80
changes
aliabid94 Jul 6, 2023
bba0688
changes
aliabid94 Jul 6, 2023
4989460
Merge branch 'main' into mobile_queue_fixes
abidlabs Jul 7, 2023
67ba7ce
Merge remote-tracking branch 'origin' into mobile_queue_fixes
aliabid94 Jul 7, 2023
7f09b2f
changes
aliabid94 Jul 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -52,6 +52,7 @@
- Better errors when you define two Blocks and reference components in one Blocks from the events in the other Blocks [@abidlabs](https://github.com/abidlabs) in [PR 4738](https://github.com/gradio-app/gradio/pull/4738).
- Better message when share link is not created by [@abidlabs](https://github.com/abidlabs) in [PR 4773](https://github.com/gradio-app/gradio/pull/4773).
- Improve accessibility around selected images in gr.Gallery component by [@hannahblair](https://github.com/hannahblair) in [PR 4790](https://github.com/gradio-app/gradio/pull/4790)
- Warning on mobile that if a user leaves the tab, websocket connection may break. On broken connection, tries to rejoin queue and displays error conveying connection broke. By [@aliabid94](https://github.com/aliabid94) in [PR 4742](https://github.com/gradio-app/gradio/pull/4742)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to the correct changelog release section!


## Breaking Changes:

Expand Down
1 change: 1 addition & 0 deletions client/js/src/client.ts
Expand Up @@ -478,6 +478,7 @@ export function api_factory(fetch_implementation: typeof fetch) {
fire_event({
type: "status",
stage: "error",
broken: true,
message: BROKEN_CONNECTION_MSG,
queue: true,
endpoint: _endpoint,
Expand Down
1 change: 1 addition & 0 deletions client/js/src/types.ts
Expand Up @@ -41,6 +41,7 @@ export interface Status {
code?: string;
success?: boolean;
stage: "pending" | "error" | "complete" | "generating";
broken?: boolean;
size?: number;
position?: number;
eta?: number;
Expand Down
42 changes: 40 additions & 2 deletions js/app/src/Blocks.svelte
Expand Up @@ -240,12 +240,30 @@
id: ++_error_id
});
let _error_id = -1;

let user_left_page: boolean = false;
document.addEventListener("visibilitychange", function () {
if (document.visibilityState === "hidden") {
user_left_page = true;
}
});

const MESSAGE_QUOTE_RE = /^'([^]+)'$/;

const DUPLICATE_MESSAGE =
"There is a long queue of requests pending. Duplicate this Space to skip.";
const MOBILE_QUEUE_WARNING =
"On mobile, the connection can break if this tab is unfocused or the device sleeps, losing your position in queue.";
const MOBILE_RECONNECT_MESSAGE =
"Lost connection due to leaving page. Rejoining queue...";
const SHOW_DUPLICATE_MESSAGE_ON_ETA = 15;
const SHOW_MOBILE_QUEUE_WARNING_ON_ETA = 10;
Copy link
Member

@abidlabs abidlabs Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also set this to 15 seconds like SHOW_DUPLICATE_MESSAGE_ON_ETA so that we have a consistent definition of a "long waiting time" that we can communicate to users

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose 10 seconds specifically because that's how long it seems iPhones break a websocket connection on low power mode. I don't think there's any need for these to match

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should probably be documented in a comment near the constant :)

const is_mobile_device =
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
);
let showed_duplicate_message = false;
let showed_mobile_warning = false;

const trigger_api_call = async (
dep_index: number,
Expand Down Expand Up @@ -322,6 +340,18 @@
...messages
];
}
if (
!showed_mobile_warning &&
is_mobile_device &&
status.eta !== undefined &&
status.eta > SHOW_MOBILE_QUEUE_WARNING_ON_ETA
) {
showed_mobile_warning = true;
messages = [
new_message(MOBILE_QUEUE_WARNING, fn_index, "warning"),
...messages
];
}

if (status.stage === "complete") {
dependencies.map(async (dep, i) => {
Expand All @@ -332,8 +362,16 @@

submission.destroy();
}

if (status.stage === "error") {
if (status.broken && is_mobile_device && user_left_page) {
window.setTimeout(() => {
messages = [
new_message(MOBILE_RECONNECT_MESSAGE, fn_index, "error"),
...messages
];
}, 0);
trigger_api_call(dep_index, event_data);
user_left_page = false;
} else if (status.stage === "error") {
if (status.message) {
const _message = status.message.replace(
MESSAGE_QUOTE_RE,
Expand Down