Skip to content

fix: prevent template dialog from closing when switching browser tabs - #4906

Open
zenojunior wants to merge 1 commit into
Dokploy:canaryfrom
zenojunior:fix/template-dialog-closes-on-tab-switch
Open

fix: prevent template dialog from closing when switching browser tabs#4906
zenojunior wants to merge 1 commit into
Dokploy:canaryfrom
zenojunior:fix/template-dialog-closes-on-tab-switch

Conversation

@zenojunior

@zenojunior zenojunior commented Jul 24, 2026

Copy link
Copy Markdown

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: AddTemplate rendered its Dialog (and its open state) inside the Create Service DropdownMenuContent, using onSelect={(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 closed DropdownMenuContent unmounts its children, the whole AddTemplate component — dialog included — gets unmounted, which looks like the modal "closing" on its own.

Fix (the pattern recommended by Radix/shadcn for dialogs inside menus):

  • AddTemplate is now a controlled component (open / onOpenChange props) and no longer renders its own DropdownMenuItem trigger.
  • The environment page renders the Template menu item inside the dropdown (it just sets the open state) and renders <AddTemplate /> as a sibling of the DropdownMenu, 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 --noEmit passes and biome check reports no new issues on the touched files (the 2 pre-existing lint warnings in add-template.tsx were left untouched to keep the diff focused).

Checklist

Before submitting this PR, please make sure that:

  • You created a dedicated branch based on the canary branch.
  • You have read the suggestions in the CONTRIBUTING.md file https://github.com/Dokploy/dokploy/blob/canary/CONTRIBUTING.md#pull-request
  • You have tested this PR in your local instance. If you have not tested it yet, please do so before submitting. This helps avoid wasting maintainers' time reviewing code that has not been verified by you. (Opening as a draft — will test on a local instance and mark as ready once verified.)

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.

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
zenojunior marked this pull request as ready for review July 24, 2026 20:01
@zenojunior
zenojunior requested a review from Siumauricio as a code owner July 24, 2026 20:01
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant