mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-12 12:40:29 +08:00
ensure internal data has updated before dispatching success
or then
events (#5705)
* ensure internal data has updated before dispatching then or success events * ensure internal data has updated before dispatching then or success events * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
parent
dba651904c
commit
78e7cf5163
7
.changeset/rare-lines-show.md
Normal file
7
.changeset/rare-lines-show.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
"@gradio/app": patch
|
||||
"@gradio/client": patch
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:ensure internal data has updated before dispatching `success` or `then` events
|
@ -379,9 +379,9 @@ export function api_factory(fetch_implementation: typeof fetch): Client {
|
||||
if (status.stage === "error") rej(status);
|
||||
if (status.stage === "complete") {
|
||||
status_complete = true;
|
||||
app.destroy();
|
||||
// if complete message comes after data, resolve here
|
||||
if (data_returned) {
|
||||
app.destroy();
|
||||
res(result);
|
||||
}
|
||||
}
|
||||
|
@ -436,80 +436,82 @@
|
||||
handle_update(data, fn_index);
|
||||
})
|
||||
.on("status", ({ fn_index, ...status }) => {
|
||||
//@ts-ignore
|
||||
loading_status.update({
|
||||
...status,
|
||||
status: status.stage,
|
||||
progress: status.progress_data,
|
||||
fn_index
|
||||
});
|
||||
if (
|
||||
!showed_duplicate_message &&
|
||||
space_id !== null &&
|
||||
status.position !== undefined &&
|
||||
status.position >= 2 &&
|
||||
status.eta !== undefined &&
|
||||
status.eta > SHOW_DUPLICATE_MESSAGE_ON_ETA
|
||||
) {
|
||||
showed_duplicate_message = true;
|
||||
messages = [
|
||||
new_message(DUPLICATE_MESSAGE, fn_index, "warning"),
|
||||
...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) => {
|
||||
if (dep.trigger_after === fn_index) {
|
||||
trigger_api_call(i);
|
||||
}
|
||||
tick().then(() => {
|
||||
//@ts-ignore
|
||||
loading_status.update({
|
||||
...status,
|
||||
status: status.stage,
|
||||
progress: status.progress_data,
|
||||
fn_index
|
||||
});
|
||||
|
||||
submission.destroy();
|
||||
}
|
||||
if (status.broken && is_mobile_device && user_left_page) {
|
||||
window.setTimeout(() => {
|
||||
if (
|
||||
!showed_duplicate_message &&
|
||||
space_id !== null &&
|
||||
status.position !== undefined &&
|
||||
status.position >= 2 &&
|
||||
status.eta !== undefined &&
|
||||
status.eta > SHOW_DUPLICATE_MESSAGE_ON_ETA
|
||||
) {
|
||||
showed_duplicate_message = true;
|
||||
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,
|
||||
(_, b) => b
|
||||
);
|
||||
messages = [
|
||||
new_message(_message, fn_index, "error"),
|
||||
new_message(DUPLICATE_MESSAGE, fn_index, "warning"),
|
||||
...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
|
||||
];
|
||||
}
|
||||
dependencies.map(async (dep, i) => {
|
||||
if (
|
||||
dep.trigger_after === fn_index &&
|
||||
!dep.trigger_only_on_success
|
||||
) {
|
||||
trigger_api_call(i);
|
||||
}
|
||||
});
|
||||
|
||||
submission.destroy();
|
||||
}
|
||||
if (status.stage === "complete") {
|
||||
dependencies.map(async (dep, i) => {
|
||||
if (dep.trigger_after === fn_index) {
|
||||
trigger_api_call(i);
|
||||
}
|
||||
});
|
||||
|
||||
submission.destroy();
|
||||
}
|
||||
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,
|
||||
(_, b) => b
|
||||
);
|
||||
messages = [
|
||||
new_message(_message, fn_index, "error"),
|
||||
...messages
|
||||
];
|
||||
}
|
||||
dependencies.map(async (dep, i) => {
|
||||
if (
|
||||
dep.trigger_after === fn_index &&
|
||||
!dep.trigger_only_on_success
|
||||
) {
|
||||
trigger_api_call(i);
|
||||
}
|
||||
});
|
||||
|
||||
submission.destroy();
|
||||
}
|
||||
});
|
||||
})
|
||||
.on("log", ({ log, fn_index, level }) => {
|
||||
messages = [new_message(log, fn_index, level), ...messages];
|
||||
|
Loading…
x
Reference in New Issue
Block a user