diff --git a/client/scripts/eslint-baseline.json b/client/scripts/eslint-baseline.json index e4d70fd48..9bdd80557 100644 --- a/client/scripts/eslint-baseline.json +++ b/client/scripts/eslint-baseline.json @@ -15,7 +15,7 @@ "@typescript-eslint/no-unused-vars": 117, "react-hooks/immutability": 28, "max-lines-per-function": 127, - "react-hooks/static-components": 50, + "react-hooks/static-components": 38, "react-hooks/preserve-manual-memoization": 12, "no-useless-assignment": 7, "no-empty": 19, diff --git a/client/src/components/Admin/DevNotificationsPanel.test.tsx b/client/src/components/Admin/DevNotificationsPanel.test.tsx index 5960c616b..2ca7cfa30 100644 --- a/client/src/components/Admin/DevNotificationsPanel.test.tsx +++ b/client/src/components/Admin/DevNotificationsPanel.test.tsx @@ -349,4 +349,16 @@ describe('DevNotificationsPanel', () => { expect(btn.style.background).toBe(''); expect(btn.className).toContain('hover:bg-surface-secondary'); }); + + it('FE-ADMIN-DEVNOTIF-017: a send button stays the same element while the panel updates around it', async () => { + render(<>); + const btn = screen.getByRole('button', { name: /Simple → Me/ }); + + // The lookups answer and re-render the panel. + await screen.findByText('Trip-Scoped Events'); + await screen.findByText('User-Scoped Events'); + + expect(btn.isConnected).toBe(true); + expect(screen.getByRole('button', { name: /Simple → Me/ })).toBe(btn); + }); }); diff --git a/client/src/components/Admin/DevNotificationsPanel.tsx b/client/src/components/Admin/DevNotificationsPanel.tsx index 7e44749bf..fabeb81f3 100644 --- a/client/src/components/Admin/DevNotificationsPanel.tsx +++ b/client/src/components/Admin/DevNotificationsPanel.tsx @@ -25,20 +25,17 @@ function ButtonGrid({ children }: { children: React.ReactNode }): React.ReactEle return
{children}
} -export default function DevNotificationsPanel(): React.ReactElement { - const ids = useId() - const { - sending, trips, selectedTripId, setSelectedTripId, users, selectedUserId, setSelectedUserId, - tripInviteId, vacayInviteId, send, - } = useDevNotifications() - - // ── Helpers ────────────────────────────────────────────────────────────── - - const Btn = ({ - id, label, sub, icon: Icon, onClick, - }: { - id: string; label: string; sub: string; icon: React.ElementType; onClick: () => void - }) => ( +/** + * One send button. Declared here, not inside the panel: a component made during + * render is a new type on every render, so React would remount every button on + * each state change and a click could land on one that is already gone. + */ +function Btn({ + id, label, sub, icon: Icon, onClick, sending, +}: { + id: string; label: string; sub: string; icon: React.ElementType; onClick: () => void; sending: string | null +}): React.ReactElement { + return ( ) +} + +export default function DevNotificationsPanel(): React.ReactElement { + const ids = useId() + const { + sending, trips, selectedTripId, setSelectedTripId, users, selectedUserId, setSelectedUserId, + tripInviteId, vacayInviteId, send, + } = useDevNotifications() return (
@@ -66,16 +71,16 @@ export default function DevNotificationsPanel(): React.ReactElement { badge={DEV ONLY} > - - - - @@ -94,19 +99,19 @@ export default function DevNotificationsPanel(): React.ReactElement { - - - - - @@ -127,6 +132,7 @@ export default function DevNotificationsPanel(): React.ReactElement { -