Skip to content

Commit f4af139

Browse files
authored
feat: auto-update dev and preview branch selector (#4171)
1 parent ce123c1 commit f4af139

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: improvement
4+
---
5+
6+
The environment and branch selector dropdown will automatically revalidate when opened so that new branches show up.

apps/webapp/app/components/navigation/EnvironmentSelector.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ChevronRightIcon, Cog8ToothIcon } from "@heroicons/react/20/solid";
22
import { DEFAULT_DEV_BRANCH } from "@trigger.dev/core/v3/utils/gitBranch";
33
import { isBranchableEnvironment } from "~/utils/branchableEnvironment";
44
import { DropdownIcon } from "~/assets/icons/DropdownIcon";
5-
import { useNavigation } from "@remix-run/react";
5+
import { useNavigation, useRevalidator } from "@remix-run/react";
66
import { useEffect, useRef, useState } from "react";
77
import { BranchEnvironmentIconSmall } from "~/assets/icons/EnvironmentIcons";
88
import { useEnvironment } from "~/hooks/useEnvironment";
@@ -52,11 +52,20 @@ export function EnvironmentSelector({
5252
const [isMenuOpen, setIsMenuOpen] = useState(false);
5353
const navigation = useNavigation();
5454
const { urlForEnvironment } = useEnvironmentSwitcher();
55+
const revalidator = useRevalidator();
5556

5657
useEffect(() => {
5758
setIsMenuOpen(false);
5859
}, [navigation.location?.pathname]);
5960

61+
// Fetch immediately on open so the list is fresh right away
62+
useEffect(() => {
63+
if (isMenuOpen && revalidator.state !== "loading") {
64+
revalidator.revalidate();
65+
}
66+
// eslint-disable-next-line react-hooks/exhaustive-deps
67+
}, [isMenuOpen]);
68+
6069
const hasStaging = project.environments.some((env) => env.type === "STAGING");
6170
return (
6271
<Popover onOpenChange={(open) => setIsMenuOpen(open)} open={isMenuOpen}>

0 commit comments

Comments
 (0)