fix: make sure comp.instance exists (#10207)

* fix: make sure `comp.instance` exists

* add changeset

* fix: update syntax

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Col0ring 2024-12-18 00:58:42 +08:00 committed by GitHub
parent 13a83e5001
commit 314a8b55f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/core": patch
"gradio": patch
---
fix:fix: make sure `comp.instance` exists

View File

@ -385,7 +385,7 @@ export function create_components(initial_layout: ComponentMeta | undefined): {
if (!comp) {
return null;
}
if (comp.instance.get_value) {
if (comp.instance?.get_value) {
return comp.instance.get_value() as Promise<any>;
}
return comp.props.value;
@ -414,7 +414,7 @@ export function create_components(initial_layout: ComponentMeta | undefined): {
state: "open" | "closed" | "waiting"
): void {
const comp = _component_map.get(id);
if (comp && comp.instance.modify_stream_state) {
if (comp?.instance?.modify_stream_state) {
comp.instance.modify_stream_state(state);
}
}
@ -423,14 +423,14 @@ export function create_components(initial_layout: ComponentMeta | undefined): {
id: number
): "open" | "closed" | "waiting" | "not_set" {
const comp = _component_map.get(id);
if (comp && comp.instance.get_stream_state)
if (comp?.instance?.get_stream_state)
return comp.instance.get_stream_state();
return "not_set";
}
function set_time_limit(id: number, time_limit: number | undefined): void {
const comp = _component_map.get(id);
if (comp && comp.instance.set_time_limit) {
if (comp?.instance?.set_time_limit) {
comp.instance.set_time_limit(time_limit);
}
}