fix: prevent template dialog from closing when switching browser tabs - #4906
Open
zenojunior wants to merge 1 commit into
Open
fix: prevent template dialog from closing when switching browser tabs#4906zenojunior wants to merge 1 commit into
zenojunior wants to merge 1 commit into
Conversation
The template dialog was rendered inside the Create Service DropdownMenuContent. When the browser tab lost and regained focus, Radix dismissed the dropdown (focus moving to the portalled dialog is treated as an outside interaction), unmounting the dialog and its state along with it. Lift the dialog out of the dropdown by making AddTemplate a controlled component and rendering it as a sibling of the DropdownMenu, with the menu item only toggling the open state. This also closes the dropdown properly when the dialog opens instead of keeping it open behind the modal.
zenojunior
marked this pull request as ready for review
July 24, 2026 20:01
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.
What is this PR about?
Fixes a bug where the Create from Template dialog closes by itself when the user switches to another browser tab (or another window) and comes back.
Root cause:
AddTemplaterendered itsDialog(and itsopenstate) inside the Create ServiceDropdownMenuContent, usingonSelect={(e) => e.preventDefault()}to keep the menu open while the dialog was showing. When the tab regains focus, Radix treats the focus landing on the portalled dialog as an outside interaction and dismisses the dropdown. Since a closedDropdownMenuContentunmounts its children, the wholeAddTemplatecomponent — dialog included — gets unmounted, which looks like the modal "closing" on its own.Fix (the pattern recommended by Radix/shadcn for dialogs inside menus):
AddTemplateis now a controlled component (open/onOpenChangeprops) and no longer renders its ownDropdownMenuItemtrigger.<AddTemplate />as a sibling of theDropdownMenu, so it survives the menu closing.As a side benefit, the dropdown now closes properly when the dialog opens, instead of staying open (invisible) behind the modal.
Note: other items in this menu (
AddApplication,AddDatabase,AddCompose, etc.) follow the same nested-dialog pattern and are affected by the same issue. I kept this PR scoped to the Template dialog as reported, but I'm happy to apply the same fix to the other items in a follow-up if the maintainers want.Verification:
tsc --noEmitpasses andbiome checkreports no new issues on the touched files (the 2 pre-existing lint warnings inadd-template.tsxwere left untouched to keep the diff focused).Checklist
Before submitting this PR, please make sure that:
canarybranch.Issues related (if applicable)
N/A — no existing issue found for this bug.
Screenshots (if applicable)
Repro steps (before): Project → Create Service → Template → switch to another browser tab → switch back → the dialog is gone. After this change the dialog stays open.