Skip to content

Use sockets to update latest block/batch on home page#3353

Open
maxaleks wants to merge 3 commits intomainfrom
issue-3245
Open

Use sockets to update latest block/batch on home page#3353
maxaleks wants to merge 3 commits intomainfrom
issue-3245

Conversation

@maxaleks
Copy link
Copy Markdown
Contributor

@maxaleks maxaleks commented Apr 17, 2026

Description and Related Issue(s)

Resolves #3245

Checklist for PR author

  • I have tested these changes locally.
  • I added tests to cover any new functionality, following this guide
  • Whenever I fix a bug, I include a regression test to ensure that the bug does not reappear silently.
  • If I have added a feature or functionality that is not privacy-compliant (e.g., tracking, analytics, third-party services), I have disabled it for private mode.
  • If I have added, changed, renamed, or removed an environment variable
    • I updated the list of environment variables in the documentation
    • I made the necessary changes to the validator script according to the guide
    • I added "ENVs" label to this pull request

Note

Medium Risk
Introduces live socket-driven cache updates for homepage stats, which can cause stale/incorrect UI if event payloads or query keys don’t match expectations, but changes are localized to the homepage widgets.

Overview
Homepage stats now derive the Latest block value from the general:homepage_blocks endpoint (with a stub placeholder) instead of treating it as a "total blocks" metric, and the widget label is updated accordingly (including degraded/fallback UI and mocks).

Adds websocket subscriptions on the homepage stats panel to push real-time updates into the React Query cache for blocks:new_block and (for Arbitrum/zkEVM) latest batch events, with guardrails to disable sockets during placeholder/error states and to de-duplicate/sort incoming items.

Reviewed by Cursor Bugbot for commit 2338b24. Bugbot is set up for automated code reviews on this repo. Configure here.

@maxaleks maxaleks requested a review from tom2drum April 17, 2026 16:33
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 17, 2026

Important

Review skipped

Auto reviews are disabled on this repository. To trigger a review, include @coderabbitai review in the PR description. 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e215cc18-9442-4724-a308-a4dcd999e9d1

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

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.

@github-actions github-actions bot added the enhancement New feature or request label Apr 17, 2026
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2338b24. Configure here.

Comment thread ui/home/Stats.tsx
channel: blocksChannel,
event: 'new_block',
handler: handleNewBlockMessage,
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate socket handler updates same query cache

Low Severity

handleNewBlockMessage in Stats.tsx nearly duplicates the same handler in LatestBlocks.tsx (lines 62–73). Both components fetch general:homepage_blocks, subscribe to the same blocks:new_block socket channel, and call setQueryData on the same React Query cache key. Since both are always rendered together on the home page (confirmed in Home.tsx), every new block message triggers two redundant cache updates. This increases maintenance burden and risks divergent behavior if one handler is updated but not the other.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: Bugbot PR Review Rules

Reviewed by Cursor Bugbot for commit 2338b24. Configure here.

Comment thread ui/home/Stats.tsx Outdated
label: statsData?.total_blocks?.title || 'Total blocks',
value: Number(statsData?.total_blocks?.value || apiData?.total_blocks).toLocaleString(),
label: 'Latest block',
value: Number(blocksQuery.data?.[0]?.height || statsData?.total_blocks?.value || apiData?.total_blocks).toLocaleString(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fallback value semantically mismatches "Latest block" label

Low Severity

When blocksQuery.data is an empty array (no blocks returned by API), the value falls back to statsData?.total_blocks?.value or apiData?.total_blocks, which represent the total block count, not the latest block height. The label reads "Latest block" but the displayed number would be total blocks (off by one from the actual latest height). The falsy check on height also means block height 0 would incorrectly trigger this fallback path.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2338b24. Configure here.

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 17, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Comment thread ui/home/Stats.tsx

const isPlaceholderData = statsQuery.isPlaceholderData || apiQuery.isPlaceholderData;
const latestBlockQueryKey = React.useMemo(() => [ ...getResourceKey('general:homepage_blocks'), 'stats_latest_block' ], []);
const latestBlockQuery = useApiQuery('general:homepage_blocks', {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already fetch the latest blocks on this page. Since the query key is different here, will there be two requests on the initial load?

Will the data be fetched on rollup instances where we don't display block information?

Comment thread ui/home/Stats.tsx
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to restructure this component.

Since updates to the latest block number can occur very frequently, the entire component will re-render, which is inefficient. It would be better to move the LatestBlock widget to a separate component and encapsulate all the necessary logic there. This way, the re-render will only affect that specific part of the tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Main page. Replace Total blocks with dynamic Latest block

2 participants