Skip to content

Conversation

@freddyaboulton
Copy link
Collaborator

Description

Closes: #11201

The Stateholder stored a shallow copy of the original blocks so updating one session's state could update the others.

🎯 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 May 15, 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/e83259f631b7ad55f7c93c61eb62ebdb787b2521/gradio-5.29.1-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/e83259f631b7ad55f7c93c61eb62ebdb787b2521/gradio-client-1.14.2.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/e83259f631b7ad55f7c93c61eb62ebdb787b2521/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented May 15, 2025

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Fix Deep Link Issue

Maintainers or the PR author can modify the PR title to modify this entry.

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 May 15, 2025 17:32
@abidlabs
Copy link
Member

Nice @freddyaboulton taking a look through this now. Is it possible to add a unit test for this btw?

@abidlabs
Copy link
Member

Thanks @freddyaboulton it looks like this fixes the original issue, but this does not seem to work for functions that return an updated component. Repro:

So this works:

import gradio as gr

with gr.Blocks() as demo:
    text = gr.Textbox()
    out = gr.Textbox()
    gr.DeepLinkButton()
    text.submit(fn=lambda x: x, inputs=text, outputs=out)
demo.launch()

But this does not:

import gradio as gr

with gr.Blocks() as demo:
    text = gr.Textbox()
    out = gr.Textbox()
    gr.DeepLinkButton()
    text.submit(fn=lambda x: gr.Textbox(x, lines=int(x)), inputs=text, outputs=out)
demo.launch()
Screen.Recording.2025-05-15.at.11.12.35.AM.mov

You'll notice that the output is not restored, neither the value nor the number of lines

@freddyaboulton
Copy link
Collaborator Author

Thanks for catching that @abidlabs ! I fixed the issue and added a unit test as well

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.

works beautifully!

Copy link
Collaborator

@hysts hysts left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix! LGTM!

@freddyaboulton
Copy link
Collaborator Author

Thank you for the reviews!

@freddyaboulton freddyaboulton merged commit 53688a2 into main May 16, 2025
22 checks passed
@freddyaboulton freddyaboulton deleted the deep-copy-state branch May 16, 2025 15:13
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.

gr.DeepLinkButton might return someone else's result

5 participants