From 66382e791ba15965f91e9ddfde99bacf2767b2ca Mon Sep 17 00:00:00 2001 From: Maurice Date: Thu, 26 Nov 2026 13:16:00 +0100 Subject: [PATCH] fix(admin): keep the dev notification buttons mounted while the panel updates The desktop panel declared its button component inside its render, so every state change (each lookup landing, each send starting and ending) made a new component type and React remounted every button: focus and hover were lost, and a click that arrived during a re-render went to a button that was no longer there. Btn now lives at module level and takes the send in flight as a prop, as the phone panel's Btn already does. FE-ADMIN-DEVNOTIF-017 holds a button across the lookups landing and expects the same element; it fails with the old panel. --- client/scripts/eslint-baseline.json | 2 +- .../Admin/DevNotificationsPanel.test.tsx | 12 ++++ .../Admin/DevNotificationsPanel.tsx | 55 +++++++++++-------- 3 files changed, 44 insertions(+), 25 deletions(-) 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 { -