Summary
useSSE in packages/data/src/hooks/useSSE.ts accepts a parse callback, but the effect dependency list only includes [url]. If a component re-renders with the same URL and a new parser, incoming events are still parsed by the old callback.
Reproduction
- Render useSSE(url, parseA).
- Re-render the same component with the same url and parseB.
- Emit another message event from the same EventSource.
Expected behavior
The hook should use the latest parser, either by including parse in the dependency list or by storing the latest callback in a ref.
Actual behavior
The event listener closes over the parser from the original effect run, so future messages can be transformed incorrectly.
Summary
useSSE in packages/data/src/hooks/useSSE.ts accepts a parse callback, but the effect dependency list only includes [url]. If a component re-renders with the same URL and a new parser, incoming events are still parsed by the old callback.
Reproduction
Expected behavior
The hook should use the latest parser, either by including parse in the dependency list or by storing the latest callback in a ref.
Actual behavior
The event listener closes over the parser from the original effect run, so future messages can be transformed incorrectly.