@@ -2,7 +2,7 @@ import { ChevronRightIcon, Cog8ToothIcon } from "@heroicons/react/20/solid";
22import { DEFAULT_DEV_BRANCH } from "@trigger.dev/core/v3/utils/gitBranch" ;
33import { isBranchableEnvironment } from "~/utils/branchableEnvironment" ;
44import { DropdownIcon } from "~/assets/icons/DropdownIcon" ;
5- import { useNavigation } from "@remix-run/react" ;
5+ import { useNavigation , useRevalidator } from "@remix-run/react" ;
66import { useEffect , useRef , useState } from "react" ;
77import { BranchEnvironmentIconSmall } from "~/assets/icons/EnvironmentIcons" ;
88import { 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