Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
* feat: add SSE for live block updates Add Server-Sent Events endpoint (GET /api/events) that streams new blocks to the frontend in real-time, replacing polling for block height and blocks list updates. Backend: - New SSE handler polls DB every 200ms, emits one event per block in order - SSE route excluded from 10s TimeoutLayer so connections stay alive - Nginx configured to proxy SSE with buffering disabled Frontend: - useBlockSSE hook buffers events in a ref-based queue and drains at the chain's natural block rate (computed from on-chain timestamps) - Navbar counter updates instantly via SSE, block time derived from 30s rolling window of block timestamps for stability - BlocksPage prepends new blocks from SSE on page 1 with auto-refresh - Polling falls back automatically when SSE disconnects Closes #11 * Fix SSE bootstrap query for empty blocks table * fix: address code review comments - sse.rs: replace silent error swallowing with tracing::warn! and continue - useBlockSSE: use named function expression to fix TS2448 self-reference - BlocksPage: filter SSE buffer instead of unconditional clear on fetch * fix: defer setState calls in effects to satisfy react-hooks/set-state-in-effect Wrap setSseBlocks calls in BlocksPage and setDisplayedHeight in Layout in requestAnimationFrame to avoid calling setState synchronously inside useEffect bodies, which is flagged by eslint-plugin-react-hooks v7. * fix: disable polling entirely while SSE is connected Stop polling every 10s as a safety net when SSE is active — periodic refetches disrupt the smooth live flow. Instead, refetch immediately when SSE disconnects to catch any missed blocks during the gap. * fix: stop polling when SSE connected, fix cursor advance on failed fetch - BlocksPage: skip API polling entirely while SSE is connected to avoid disrupting the live block flow; trigger an immediate refetch when SSE drops to recover any missed blocks - BlocksPage: guard SSE block merge to page 1 + autoRefresh only, so navigating to page 2+ never shows page-1 SSE blocks - sse.rs: only advance last_block_number after the initial block is successfully fetched and emitted, preventing the cursor from skipping the block on a transient fetch failure * docs: fix /api/height reference to actual /api/status endpoint, document SSE * fix: batch SSE prepend per frame to prevent burst block loss Replace cancel-and-reschedule RAF pattern with a pending buffer so that burst arrivals (e.g. blocks 100, 101, 102 before a frame fires) are all flushed in a single requestAnimationFrame rather than only the last block surviving. Also clarify CLAUDE.md /api/status contract. * fix: bound SSE catch-up query, add unit tests, fix docker volume - Add LIMIT 100 to the SSE block polling query to prevent unbounded memory usage and avoid infinite retry loops from statement_timeout - Add unit tests for NewBlockEvent serialization - Remove external: true from pgdata volume so docker compose up works on fresh systems * style: fix rustfmt formatting in sse tests * chore: simplify (#22) * simplify * fix build * feat: switch SSE fanout to postgres notifications * style: match rustfmt 1.94 output * style: align SSE formatting with CI * style: run stable rustfmt on SSE handler * fix: harden SSE client state handling * Refine live update streaming behavior * Fix backend clippy lint --------- Co-authored-by: Marko <marko@baricevic.me>
* feat: add SSE for live block updates Add Server-Sent Events endpoint (GET /api/events) that streams new blocks to the frontend in real-time, replacing polling for block height and blocks list updates. Backend: - New SSE handler polls DB every 200ms, emits one event per block in order - SSE route excluded from 10s TimeoutLayer so connections stay alive - Nginx configured to proxy SSE with buffering disabled Frontend: - useBlockSSE hook buffers events in a ref-based queue and drains at the chain's natural block rate (computed from on-chain timestamps) - Navbar counter updates instantly via SSE, block time derived from 30s rolling window of block timestamps for stability - BlocksPage prepends new blocks from SSE on page 1 with auto-refresh - Polling falls back automatically when SSE disconnects Closes #11 * Fix SSE bootstrap query for empty blocks table * fix: address code review comments - sse.rs: replace silent error swallowing with tracing::warn! and continue - useBlockSSE: use named function expression to fix TS2448 self-reference - BlocksPage: filter SSE buffer instead of unconditional clear on fetch * fix: defer setState calls in effects to satisfy react-hooks/set-state-in-effect Wrap setSseBlocks calls in BlocksPage and setDisplayedHeight in Layout in requestAnimationFrame to avoid calling setState synchronously inside useEffect bodies, which is flagged by eslint-plugin-react-hooks v7. * fix: disable polling entirely while SSE is connected Stop polling every 10s as a safety net when SSE is active — periodic refetches disrupt the smooth live flow. Instead, refetch immediately when SSE disconnects to catch any missed blocks during the gap. * fix: stop polling when SSE connected, fix cursor advance on failed fetch - BlocksPage: skip API polling entirely while SSE is connected to avoid disrupting the live block flow; trigger an immediate refetch when SSE drops to recover any missed blocks - BlocksPage: guard SSE block merge to page 1 + autoRefresh only, so navigating to page 2+ never shows page-1 SSE blocks - sse.rs: only advance last_block_number after the initial block is successfully fetched and emitted, preventing the cursor from skipping the block on a transient fetch failure * docs: fix /api/height reference to actual /api/status endpoint, document SSE * fix: batch SSE prepend per frame to prevent burst block loss Replace cancel-and-reschedule RAF pattern with a pending buffer so that burst arrivals (e.g. blocks 100, 101, 102 before a frame fires) are all flushed in a single requestAnimationFrame rather than only the last block surviving. Also clarify CLAUDE.md /api/status contract. * fix: bound SSE catch-up query, add unit tests, fix docker volume - Add LIMIT 100 to the SSE block polling query to prevent unbounded memory usage and avoid infinite retry loops from statement_timeout - Add unit tests for NewBlockEvent serialization - Remove external: true from pgdata volume so docker compose up works on fresh systems * style: fix rustfmt formatting in sse tests * chore: simplify (#22) * simplify * fix build * feat: switch SSE fanout to postgres notifications * style: match rustfmt 1.94 output * style: align SSE formatting with CI * style: run stable rustfmt on SSE handler * fix: harden SSE client state handling * Refine live update streaming behavior * Fix backend clippy lint --------- Co-authored-by: Marko <marko@baricevic.me>
Overview
run simplify on the code changes in sse events prs. Feel free to close if this is not needed