From 176a8a4d713246383c760d86fcb964298ee68c6b Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Fri, 19 Apr 2024 21:43:10 +0100 Subject: [PATCH] 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 --- .changeset/silly-drinks-glow.md | 6 ++++++ js/label/Index.svelte | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changeset/silly-drinks-glow.md diff --git a/.changeset/silly-drinks-glow.md b/.changeset/silly-drinks-glow.md new file mode 100644 index 0000000000..e396e6e38a --- /dev/null +++ b/.changeset/silly-drinks-glow.md @@ -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 diff --git a/js/label/Index.svelte b/js/label/Index.svelte index f23a67ad2c..2e814f01c6 100644 --- a/js/label/Index.svelte +++ b/js/label/Index.svelte @@ -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;