Skip to content

Conversation

@aliabid94
Copy link
Collaborator

If you tried updating an extended gr.HTML component, if you set the props, it wouldn't work if you also set the prop to self.prop_name. E.g.:

import gradio as gr

class SimpleText(gr.HTML):
    def __init__(self, value="Hello World!", color="black", todos=None, **kwargs):
        self.todos = todos
        super().__init__(value=value, html_template="""
            <div style="color: ${color};">This:${value}</div>
            ${todos ? `<ul>${todos.map(todo => `<li>${todo}</li>`).join('')}</ul>` : ''}
        """, color=color, todos=todos, **kwargs)

with gr.Blocks() as demo:
    with gr.Row():
        name_input = gr.Textbox(label="Enter your name")
        color_input = gr.ColorPicker(label="Pick a text color", value="#0000FF")
        submit_button = gr.Button("Submit")

    t1 = SimpleText(value="Hello World!", color="blue")

    def updateColor(name, color):
        return SimpleText(value=f"Hello {name}!", color=color, todos=list(name))

    submit_button.click(fn=updateColor, inputs=[name_input, color_input], outputs=t1)

if __name__ == "__main__":
    demo.launch()

The line self.todos = todos stopped updates from changing todos, because previously we were relying on class props to determine if they were part of gr.HTML or if they should be part of additional props. The above is fixed, we just read the gr.HTML constructor directly.

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Dec 18, 2025

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/9541b32c2c3b43a0ff600bc27d764018708e49d7/gradio-6.1.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@9541b32c2c3b43a0ff600bc27d764018708e49d7#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/9541b32c2c3b43a0ff600bc27d764018708e49d7/gradio-client-2.0.0.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Dec 18, 2025

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch

  • Fix custom gr.HTML updates

✅ Changeset approved by @freddyaboulton

  • Maintainers can remove approval by unchecking this checkbox.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

""",
container=container,
label=label,
ordered=ordered,
Copy link
Member

Choose a reason for hiding this comment

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

Do you still need to pass attributes to the parent HTML class?

props = None
if hasattr(block, "props"):
props = {k: v for k, v in update_dict.items() if not hasattr(block, k)}
if isinstance(block, HTML):
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth adding a comment here explaining that this is needed for custom html components since it might not be clear to someone reading the codebase why this is needed

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

LGTM nice fix!

@freddyaboulton freddyaboulton added v: patch A change that requires a patch release t: fix A change that implements a fix labels Dec 19, 2025
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

LGTM nice @aliabid94 !

@freddyaboulton freddyaboulton merged commit 2119a24 into main Dec 19, 2025
18 of 19 checks passed
@freddyaboulton freddyaboulton deleted the fix_html_prop_updates branch December 19, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t: fix A change that implements a fix v: patch A change that requires a patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants