@@ -5,6 +5,7 @@ import { DropdownIcon } from "~/assets/icons/DropdownIcon";
55import { useNavigation } from "@remix-run/react" ;
66import { useEffect , useRef , useState } from "react" ;
77import { BranchEnvironmentIconSmall } from "~/assets/icons/EnvironmentIcons" ;
8+ import { useAutoRevalidate } from "~/hooks/useAutoRevalidate" ;
89import { useEnvironment } from "~/hooks/useEnvironment" ;
910import { useEnvironmentSwitcher } from "~/hooks/useEnvironmentSwitcher" ;
1011import { useFeatures } from "~/hooks/useFeatures" ;
@@ -53,10 +54,21 @@ export function EnvironmentSelector({
5354 const navigation = useNavigation ( ) ;
5455 const { urlForEnvironment } = useEnvironmentSwitcher ( ) ;
5556
57+ // Keep branch list fresh, only fires while the menu is open
58+ const revalidator = useAutoRevalidate ( { interval : 5000 , disabled : ! isMenuOpen } ) ;
59+
5660 useEffect ( ( ) => {
5761 setIsMenuOpen ( false ) ;
5862 } , [ navigation . location ?. pathname ] ) ;
5963
64+ // Fetch immediately on open so the list is fresh right away
65+ useEffect ( ( ) => {
66+ if ( isMenuOpen && revalidator . state !== "loading" ) {
67+ revalidator . revalidate ( ) ;
68+ }
69+ // eslint-disable-next-line react-hooks/exhaustive-deps
70+ } , [ isMenuOpen ] ) ;
71+
6072 const hasStaging = project . environments . some ( ( env ) => env . type === "STAGING" ) ;
6173 return (
6274 < Popover onOpenChange = { ( open ) => setIsMenuOpen ( open ) } open = { isMenuOpen } >
0 commit comments