Skip to content

Conversation

@freddyaboulton
Copy link
Collaborator

@freddyaboulton freddyaboulton commented Dec 1, 2025

Description

Closes: #12482
Closes: #12506
Closes: #12505

In 5.0, we would only render components that are visible. We did not do that optimization in 6.0.

This PR

fast-load

Main

slow-load

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 to... [fill here]
  • 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

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Dec 1, 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/31967f962a07a7856a36784815f6c96570368f7e/gradio-6.0.2-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/31967f962a07a7856a36784815f6c96570368f7e/gradio-client-2.0.0.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Dec 1, 2025

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/accordion patch
@gradio/colorpicker patch
@gradio/core patch
@gradio/tabitem patch
@gradio/tabs patch
gradio patch

  • Load visible components in 6.0

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

@freddyaboulton freddyaboulton marked this pull request as ready for review December 2, 2025 23:08
} from "./init_utils";
import { translate_if_needed } from "./i18n";
import { tick } from "svelte";
import { tick, getContext } from "svelte";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The main changes are in this file:

  • untrack_children_of_closed_accordions_or_inactive_tabs sets visibility=False for children of unopened accordions, inactive tabs
  • changes to update_state. If a component with visible=False is the output of an event, we would previously not update its props. Now we do. We also let components with visible=False, trigger change events. This was true in 5.x. In order to trigger change events from update_state, we have to pass in the gradio_dispatch_function from blocks
  • Last big change is that tabs/accordions now dispatch custom events that let the AppTree know when to render the children of an Accordion/Tabs. You can see that in js/tabs/, js/accodion, and Blocks.svelte mostly

@FurkanGozukara
Copy link

I am willing to test this just let me know how to install

@freddyaboulton
Copy link
Collaborator Author

You can install with pip install https://gradio-pypi-previews.s3.amazonaws.com/dcc065c33a15ada1ed0626f4756a01114f4e189a/gradio-6.0.2-py3-none-any.whl

@FurkanGozukara
Copy link

You can install with pip install https://gradio-pypi-previews.s3.amazonaws.com/dcc065c33a15ada1ed0626f4756a01114f4e189a/gradio-6.0.2-py3-none-any.whl

wow so many times faster. cant wait you to publish great work

@aliabid94
Copy link
Collaborator

Seems like visibility toggling is very broken even on main with something as simple as:

import gradio as gr

with gr.Blocks() as demo:
    textbox = gr.Textbox(visible=False)

    make_visible_btn = gr.Button("Show")
    def show():
        return gr.Textbox(visible=True)
    
    make_visible_btn.click(fn=show, outputs=textbox)

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

Confirmed that this works for Tabs and Accordion though! Components only mount when made visible there.

Also, I tried this:

import gradio as gr

with gr.Blocks() as demo:
    with gr.Tab("A"):
        timerA = gr.Timer()
        timerA.tick(lambda: print("A"))
    with gr.Tab("B"):
        timerB = gr.Timer()
        timerB.tick(lambda: print("B"))

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

Both timers tick, I'm not sure why. Would have expected the hidden ticker to not tick, but doesn't seem to be the case. Not too important, just wondering why.

Would be nice if we could test for this somehow, especially if there's some component that triggers and event onMount (this is why I was playing with Timers).

@aliabid94
Copy link
Collaborator

I'm trying to figure out why visible= is broken but seems like a component that starts off as visible=False can never be visible again. Also seems like a component like Textbox that gets hidden will not hide its parent Form container.
(this isn't necessarily related to this PR but was exploring this as a result of this PR)

Demo:

import gradio as gr

with gr.Blocks() as demo:
    textbox = gr.Textbox(visible=False)

    make_visible_btn = gr.Button("Show")
    def show():
        return gr.Textbox(visible=True)
    
    make_visible_btn.click(fn=show, outputs=textbox)

    make_invisible_btn = gr.Button("Hide")
    def hide():
        return gr.Textbox(visible=False)
    make_invisible_btn.click(fn=hide, outputs=textbox)


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

Recording 2025-12-04 at 13 43 13

If it is initially set to visible=True:

Recording 2025-12-04 at 13 44 09

@freddyaboulton
Copy link
Collaborator Author

freddyaboulton commented Dec 4, 2025

Thanks for the thorough review @aliabid94 ! Yea the issue with textbox is that it is the child of a form component and if all children of a form are invisible, then we mark that form as invisible so we don't render an empty form (looks ugly in UI). If you tried with a ColorPicker or something everything would work as expected. The problem was that updating the visibility of a child would not update the visibility of the parent form. I added a function called update_parent_visibility to handle that case. I don't think we should be updating the visibility of parents depending on the children automatically though so this handles the case where there is only one child in the form.

The issue with the timers in inactive tabs triggering is also fixed.

Copy link
Collaborator

@aliabid94 aliabid94 left a comment

Choose a reason for hiding this comment

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

Nice, thanks for fixing! Just to be clear I still see the Form parent when the child is hidden by an event listener, but can confirm everything else works great! Approved
Screenshot 2025-12-04 at 3 51 33 PM

@aliabid94
Copy link
Collaborator

just lots of console.logs to remove

@freddyaboulton
Copy link
Collaborator Author

Thanks for the thorough review @aliabid94 ! I removed those console logs and handled removing the empty form if its children are invisible. However, that issue is trickier than expected and filed a follow-up issue for it.

#12513

@freddyaboulton freddyaboulton merged commit 4f6327b into main Dec 5, 2025
20 of 24 checks passed
@freddyaboulton freddyaboulton deleted the 12482-long-time-to-load branch December 5, 2025 17:54
@FurkanGozukara
Copy link

@freddyaboulton will it come with gradio 6.0.3?

@freddyaboulton
Copy link
Collaborator Author

Yes. Next release will be 6.1.0

@FurkanGozukara
Copy link

Yes. Next release will be 6.1.0

awesome any ETA? thank you so much for great work

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.

Invisible dataframes become empty Cannot change visibility of Column component Performance slowness on Gradio 6.0.1 with a rich GUI App

5 participants