Fix Label component's value change detection to avoid infinite loop dispatching the change event (#8054)

* Fix Label component's value change detection to avoid infinite loop dispatching the change event

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Yuichiro Tachibana (Tsuchiya) 2024-04-19 21:43:10 +01:00 committed by GitHub
parent 367a20c525
commit 176a8a4d71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/label": patch
"gradio": patch
---
feat:Fix Label component's value change detection to avoid infinite loop dispatching the change event

View File

@ -23,6 +23,7 @@
label?: string;
confidences?: { label: string; confidence: number }[];
} = {};
let old_value: typeof value | null = null;
export let label = gradio.i18n("label.label");
export let container = true;
export let scale: number | null = null;
@ -31,8 +32,14 @@
export let show_label = true;
export let _selectable = false;
$: ({ confidences, label: _label } = value);
$: _label, confidences, gradio.dispatch("change");
$: {
if (JSON.stringify(value) !== JSON.stringify(old_value)) {
old_value = value;
gradio.dispatch("change");
}
}
$: _label = value.label;
</script>
<Block