Skip to content

fix(bridge): keep bridge order status polling while tab is hidden#7707

Open
tenderdeve wants to merge 6 commits into
cowprotocol:developfrom
tenderdeve:fix/6694-bridge-orders-background-updates
Open

fix(bridge): keep bridge order status polling while tab is hidden#7707
tenderdeve wants to merge 6 commits into
cowprotocol:developfrom
tenderdeve:fix/6694-bridge-orders-background-updates

Conversation

@tenderdeve

@tenderdeve tenderdeve commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Closes #6694.

The SWR config for the cross-chain order hook had refreshWhenHidden: false, so once the tab lost focus the bridge status stopped being polled. When the tab was re-opened, the order would stay marked as pending on CoW Swap (and lag on Explorer) for the usual 4-5s window before SWR caught up.

Flip refreshWhenHidden: true on both the cowswap-frontend and explorer cross-chain order hooks so the status keeps updating in the background. Polling still stops as soon as the bridge reaches a final status (EXECUTED / EXPIRED / REFUND), so there's no extra traffic for completed orders.

Files

  • apps/cowswap-frontend/src/entities/bridgeOrders/hooks/useCrossChainOrder.ts
  • apps/explorer/src/modules/bridge/hooks/useCrossChainOrder.ts

Testing steps

  1. Place a swap-and-bridge order (e.g. via the Near provider).
  2. Switch to another tab and wait for the bridge to progress on Explorer.
  3. Come back to the CoW Swap tab: the order status should already reflect the latest bridge status without the previous 4-5s catch-up delay.
  4. Repeat with the Explorer tab in the background while the bridge finalizes.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced data refresh behavior for cross-chain orders to maintain up-to-date information even when the browser tab is inactive.

SWR config for the cross-chain order hook disabled background refresh
(`refreshWhenHidden: false`). As a result, a swap-and-bridge order would
stay marked as pending on CoW Swap (and on Explorer) until the tab was
focused again, lagging the actual bridge status by 4-5s on each return.

Enable `refreshWhenHidden: true` for both the cowswap-frontend and
explorer cross-chain order hooks so the bridge status (and the order
state derived from it) stays in sync even when the tab is in the
background. Polling still stops once the bridge reaches a final status.

Closes cowprotocol#6694
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@tenderdeve is attempting to deploy a commit to the cow-dev Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5bcfe145-605a-4b0e-886a-60520caa028e

📥 Commits

Reviewing files that changed from the base of the PR and between ead6958 and 0de2170.

📒 Files selected for processing (2)
  • apps/cowswap-frontend/src/entities/bridgeOrders/hooks/useCrossChainOrder.ts
  • apps/explorer/src/modules/bridge/hooks/useCrossChainOrder.ts

Walkthrough

Two useCrossChainOrder hooks — one in cowswap-frontend and one in explorer — have their SWR configurations updated to set refreshWhenHidden: true, enabling continued polling of cross-chain order status even when the browser tab or page is not visible.

Changes

Background refresh for cross-chain order status

Layer / File(s) Summary
Enable refreshWhenHidden in both app hooks
apps/cowswap-frontend/src/entities/bridgeOrders/hooks/useCrossChainOrder.ts, apps/explorer/src/modules/bridge/hooks/useCrossChainOrder.ts
cowswap-frontend changes refreshWhenHidden from false to true; explorer adds refreshWhenHidden: true to swrOptions. SWR polling now continues while the document is hidden in both apps.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 Hop hop, no more waiting in the dark,
The orders refresh without a single spark!
Even when the tab is tucked away and sleeping,
The cross-chain status is busily beeping.
refreshWhenHidden: true — what a lark! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: enabling background polling for bridge order status when the tab is hidden.
Description check ✅ Passed The description is comprehensive and well-structured, covering the issue, solution, affected files, and clear testing steps that align with the template requirements.
Linked Issues check ✅ Passed The PR directly addresses issue #6694 by enabling background polling for bridge order status updates, eliminating the 4-5 second lag observed when tabs are hidden.
Out of Scope Changes check ✅ Passed All changes are focused solely on enabling background polling for cross-chain order hooks; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@elena-zh elena-zh added the trigger-preview Add to a fork PR to trigger CF-pages preview. See https://github.com/cowprotocol/cowswap/pull/7615 label Jun 23, 2026
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Cloudflare Pages preview mirror

Preview branch URL: https://github.com/cowprotocol/cowswap/tree/cf-preview/pr-7707
Mirror PR: #7708
Cloudflare Pages preview links will be posted on the mirror PR by the Cloudflare Pages GitHub integration once builds complete.

Source fork branch: tenderdeve/cowswap:fix/6694-bridge-orders-background-updates
Approval target SHA: 63e530bc32dd
Last mirrored SHA: 564451a7b265
Last comment update: @fairlighteth at 2026-07-10T15:46:14.673Z

  • Sync Cloudflare preview to approval target commit

@elena-zh elena-zh requested a review from alfetopito June 24, 2026 10:36

@elena-zh elena-zh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM from the UI perspective

@alfetopito alfetopito left a comment

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.

This addresses the issue, yes, however, we have the policy everywhere in this project to not refresh when hidden https://github.com/search?q=repo%3Acowprotocol%2Fcowswap%20refreshWhenHidden&type=code

How about using revalidateOnFocus instead, to trigger the check when the tab is focused again?
But I'd be willing to accept the change if this is the same behaviour as the order execution.
On a quick look I did not find the config for that, so your change could be the correct one.

@tenderdeve

tenderdeve commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@alfetopito the order execution doesn't go through SWR. It polls with plain setInterval in PendingOrdersUpdater (SWAP/LIMIT/TWAP), and timers keep firing while the tab is hidden, so those already update in the background.

The bridge hook is the only SWR-based one, and refreshWhenHidden: false is what was stopping it from updating while hidden — that's #6694. Flipping it to true just brings it in line with how the regular orders already behave. revalidateOnFocus would only refresh on refocus, so it'd still go stale in the background.

@elena-zh elena-zh requested a review from alfetopito June 30, 2026 08:13

@fairlighteth fairlighteth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI Review (Codex GPT-5, worked 37m): no new non-duplicate findings

Review completed. I found no new non-duplicate comments worth posting.

Related context checked

  • refreshWhenHidden policy concern is already covered by the existing top-level review comment; I rechecked the author’s reply against PendingOrdersUpdater, which does poll regular orders via setInterval.
  • Both changed hooks still stop polling once bridge status reaches EXECUTED, EXPIRED, or REFUND.
  • Current PR checks have preview/deploy checks passing; lint/typecheck/test jobs are skipped on this run.

Generated using the pr-review skill from the CoW Protocol skills repo.

@fairlighteth fairlighteth self-requested a review July 10, 2026 15:53
@fairlighteth fairlighteth enabled auto-merge (squash) July 10, 2026 15:54
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.

Swap and bridge orders are not updated in the background

4 participants