fix: prevent DuplicateBlockError in multi-page apps with gr.render#13007
Closed
gambletan wants to merge 1 commit intogradio-app:mainfrom
Closed
fix: prevent DuplicateBlockError in multi-page apps with gr.render#13007gambletan wants to merge 1 commit intogradio-app:mainfrom
gambletan wants to merge 1 commit intogradio-app:mainfrom
Conversation
Ensure Context.id is higher than any existing block ID in the session's blocks_config before creating new blocks in Renderable.apply(). In multi-page apps, blocks from all pages share the same ID space, but Context.id may not reflect the highest used ID (e.g. after a reload via `gradio app.py`), leading to ID collisions and DuplicateBlockError. Fixes gradio-app#12078 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
please do not open duplicate PRs for the same issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DuplicateBlockErrorthat occurs when usinggr.renderin multi-page apps launched viagradio app.pyContext.id(the global block ID counter) can fall behind the highest block ID in the session'sblocks_configafter pages are merged, causing newly created blocks inRenderable.apply()to receive IDs that collide with existing blocksContext.idis set to at leastmax(existing_block_ids) + 1before creating new blocks in the render functionDetails
In a multi-page app, when
page1.demo.render()andpage2.demo.render()are called, blocks from both pages are merged into the root context'sblocks_config. When theloadevent fires and triggersRenderable.apply(), new blocks are created via the user's render function (e.g.gr.Markdown(...)). These blocks get IDs fromContext.id, which may not account for all merged block IDs — particularly after a module reload triggered bygradio app.py. This causes theDuplicateBlockErrorcheck inBlock.render()to fail.The fix adds a guard at the start of
Renderable.apply()that bumpsContext.idpast the highest existing block ID in the session's config.Closes #12078
Test plan
gr.renderas described in DuplicateBlockError in multi page app with render #12078gradio app.pyand verify noDuplicateBlockErroron first page loadgr.Markdown) displays correctlygr.renderare unaffected🤖 Generated with Claude Code