Fix a React 19 + TypeScript 5.8 browser component that shows a list of messages and lets the user optimistically add a new message from the keyboard. The app runs in development and production; in development the root component is wrapped in React.StrictMode. The component receives only one prop: roomId: string. API contract: GET /api/rooms/:roomId/messages returns { roomId: string; messages: Array<{ id: string; text: string; status: 'sent' | 'pending' }> }; POST /api/rooms/:roomId/messages accepts { text: string } and returns { id: string; text: string; status: 'sent' } or a network/HTTP error. Requirements: when roomId changes, a new list must be loaded; when sending, the message must appear immediately in the list as pending; on success it must be replaced with the server record; on error it must be removed; the Send button must be keyboard accessible and sending with Enter must work in the input field. Reproduction: 1) open room A, quickly send a message and immediately switch to room B; 2) type a message and press Enter; 3) with a slow server response, verify that the list and status do not roll back to an outdated result; 4) on send error, verify that the unsuccessful draft disappears and old messages do not vanish. Assume the network layer is available through fetch, and the build uses no additional libraries besides React and TypeScript.
React 19.0.x, TypeScript 5.8.x, browser DOM, Vite-style ESM entry, development with React.StrictMode and production without StrictMode; no SSR, no external state libraries
Use line comments to explain the problem, its impact, the fix and how to test it.