Skip to content

Commit 3b3a517

Browse files
committed
feat: auto-update dev and preview branch selector
1 parent 4c2c255 commit 3b3a517

2 files changed

Lines changed: 18 additions & 0 deletions

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 (poll) while it's open so that new branches show up.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DropdownIcon } from "~/assets/icons/DropdownIcon";
55
import { useNavigation } from "@remix-run/react";
66
import { useEffect, useRef, useState } from "react";
77
import { BranchEnvironmentIconSmall } from "~/assets/icons/EnvironmentIcons";
8+
import { useAutoRevalidate } from "~/hooks/useAutoRevalidate";
89
import { useEnvironment } from "~/hooks/useEnvironment";
910
import { useEnvironmentSwitcher } from "~/hooks/useEnvironmentSwitcher";
1011
import { 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

Comments
 (0)