Skip to content

chore: simplify#22

Merged
pthmas merged 2 commits intopthmas/websocket-live-updatesfrom
marko/simplify_pthomas
Mar 9, 2026
Merged

chore: simplify#22
pthmas merged 2 commits intopthmas/websocket-live-updatesfrom
marko/simplify_pthomas

Conversation

@tac0turtle
Copy link
Copy Markdown
Contributor

Overview

run simplify on the code changes in sse events prs. Feel free to close if this is not needed

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 8, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 59f8f33f-ab5d-4d9e-9081-f67055125de0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch marko/simplify_pthomas

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tac0turtle tac0turtle marked this pull request as ready for review March 9, 2026 06:10
@pthmas pthmas merged commit a3440d5 into pthmas/websocket-live-updates Mar 9, 2026
9 checks passed
@pthmas pthmas deleted the marko/simplify_pthomas branch March 9, 2026 19:08
pthmas added a commit that referenced this pull request Mar 15, 2026
* 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>
pthmas added a commit that referenced this pull request Mar 15, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants