Skip to content

@gr.render and gr.HTML event behavior #13136

@ssolikhin17

Description

@ssolikhin17

Describe the bug

Wonder why when I re-render gr.HTML (click "new button"), the event on some html buttons are no longer working.

Image

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import gradio as gr
# from datetime import datetime
import random
import uuid

def newdate():
    return str(uuid.uuid4())
    # return datetime.now()
    
js_on_load="""
    const buttons = element.querySelectorAll('button');
    buttons.forEach(button => {
        button.addEventListener('click', () => {
            trigger('click', {clicked: button.innerText});
        });
    });
        """

def showrow(thedate):
    with gr.Blocks() as showrow_bl:
        @gr.render(inputs=[thedate])
        def showrow_render(theda):
            el_count = random.randint(1,5)
            htmlval = ' '.join([f"<button id='{newdate()}_{el}'>A_{el}</button>" for el in range(el_count)])
            button_set = gr.HTML(htmlval, js_on_load=js_on_load, elem_id=f"{newdate()}")
            clicked_box = gr.Textbox(label="Clicked")

            
            def on_button_click(evt: gr.EventData):
                return evt.clicked

            button_set.click(on_button_click, outputs=clicked_box)
        pass

    return showrow_bl
    pass

with gr.Blocks() as demo:
    row_count = 3
    date_st = gr.State(newdate())
    with gr.Row():
        for row in range(row_count):
            showrow(date_st)
            pass

        pass
    gen_button = gr.Button('new button')
    gen_button.click(
        outputs=[date_st],
        fn = newdate
    )

demo.launch(debug=True)

Screenshot

No response

Logs

System Info

gr.__version__ = '6.10.0'

Severity

Blocking usage of gradio

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions