Skip to content

Fix submit button not restored after example click#12975

Merged
freddyaboulton merged 2 commits intomainfrom
fix-chatinterface-example-submit-btn-race
Mar 6, 2026
Merged

Fix submit button not restored after example click#12975
freddyaboulton merged 2 commits intomainfrom
fix-chatinterface-example-submit-btn-race

Conversation

@hysts
Copy link
Collaborator

@hysts hysts commented Mar 6, 2026

Description

Closes: #12974

Fix submit/stop button display not being restored after clicking an example in ChatInterface with run_examples_on_click=False.
The reported issue was with run_examples_on_click=False, but the root cause is a race condition in the event handler structure that is independent of that setting. The fix addresses the underlying race for all cases.

Root cause

_setup_stop_events() registered a separate handler on chatbot.example_select that set submit_btn=False on the textbox. The frontend dispatch loop processes multiple handlers for the same event sequentially, so:

  1. Handler 1 (main example chain) runs to completion, then dispatches the restore .then() as an async fire-and-forget call
  2. Handler 2 (submit_btn=False from _setup_stop_events) starts immediately after in the next loop iteration
  3. The restore and Handler 2 both make concurrent HTTP requests → race condition

With run_examples_on_click=False, the race consistently resulted in submit_btn=False winning (the textbox should never enter processing state at all in this case). With run_examples_on_click=True, the race was less likely to manifest in practice because the longer-running submit_fn shifted timing, but the same structural issue existed.

Changes

  1. Removed self.chatbot.example_select from event_triggers — eliminates the separate handler, eliminating the race
  2. Added submit_btn=False as a .then() step in the chain (only when run_examples_on_click=True and cache_examples=False) — placed after example_clicked and before submit_fn, keeping it in a single sequential chain so the restore always fires strictly after it
  3. Skip events_to_cancel for populate-only examples (run_examples_on_click=False) — no inference runs, so no stop/cancel behavior is needed

AI Disclosure

We encourage the use of AI tooling in creating PRs, but the any non-trivial use of AI needs be disclosed. E.g. if you used Claude to write a first draft, you should mention that. Trivial tab-completion doesn't need to be disclosed. You should self-review all PRs, especially if they were generated with AI.

  • I used AI (Claude Code) to identify the root cause through codebase analysis (tracing the frontend dispatch loop and backend event chain) and to generate the fix
  • I did not use AI

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Testing and Formatting Your Code

  1. PRs will only be merged if tests pass on CI. We recommend at least running the backend tests locally, please set up your Gradio environment locally and run the backed tests: bash scripts/run_backend_tests.sh

  2. Please run these bash scripts to automatically format your code: bash scripts/format_backend.sh, and (if you made any changes to non-Python files) bash scripts/format_frontend.sh

@hysts hysts requested a review from freddyaboulton March 6, 2026 06:58
@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Mar 6, 2026

🪼 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/79a84efc85967adda7e6e4f7cba46bfa36d8250e/gradio-6.8.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/79a84efc85967adda7e6e4f7cba46bfa36d8250e/gradio-client-2.1.0.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Mar 6, 2026

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch

  • Fix submit button not restored after example click

✅ 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.

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.

Clean fix @hysts ! tysm

@freddyaboulton freddyaboulton enabled auto-merge (squash) March 6, 2026 15:45
@freddyaboulton freddyaboulton merged commit 8523c89 into main Mar 6, 2026
24 of 28 checks passed
@freddyaboulton freddyaboulton deleted the fix-chatinterface-example-submit-btn-race branch March 6, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Submit/stop button display not restored after clicking an example in ChatInterface with run_examples_on_click=False

3 participants