perf(ux): useNewTable sleeps 2s for tx indexer — replace with WS event or backoff poll
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #748 của @Dzeezbtc — đã đóng, không merge
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Severity: UX bug — 2 seconds of UI dead time on every table creation, for no good reason.
Where
`src/hooks/game/useNewTable.ts:134`
```ts
if (txHash) {
setNewGameId(txHash);
const cosmosClient = getCosmosClient(currentNetwork);
if (!cosmosClient) return null;
// Wait a moment for the transaction to be indexed
await new Promise(resolve => setTimeout(resolve, 2000));
let tx;
try {
tx = await cosmosClient.getTx(txHash);
} catch (_txError) {
// Indexer hiccup — tx is on-chain but we couldn't fetch it.
return { txHash, gameId: null };
}
...
}
```
What's happening
Cosmos returns the tx hash from `broadcastTx` before the indexer has fully recorded the tx, so an immediate `getTx(hash)` can 404. The author sleeps 2s and hopes.
Why this is wrong
- 2s is a guess, not a guarantee. Under chain load it might not be enough — the `getTx` falls through into the catch block (`return { txHash, gameId: null }`), and the user gets a partial result anyway.
- Under normal conditions you're paying 2s of UI dead time for nothing. The indexer is almost certainly ready in <500ms; the user just stares at a spinner for the remaining 1.5s.
- The catch block already handles the 404 case. So the sleep is a coin flip between "too short and falls into the catch anyway" and "too long and the UI hangs."
Proposed fix
Option A (preferred): poll with backoff
Try `getTx` immediately. If it 404s, retry with backoff (e.g., 200ms, 500ms, 1s, 2s), capped at ~5s total. Returns the moment the indexer has the tx, which is usually well under the current 2s sleep.
```ts
async function getTxWithBackoff(client, hash, totalBudgetMs = 5000) {
const delays = [0, 200, 500, 1000, 2000];
const start = Date.now();
for (const delay of delays) {
if (Date.now() - start + delay > totalBudgetMs) break;
if (delay > 0) await new Promise(r => setTimeout(r, delay));
try {
return await client.getTx(hash);
} catch {
// 404 — indexer not ready yet, retry
}
}
return null;
}
```
Option B: subscribe via WebSocket
We already subscribe to chain events for tables. The new-game-created event will arrive over the WS faster than any REST polling. Wire that signal into the table-creation flow and skip the `getTx` round trip entirely.
Option B is the architecturally correct fix (aligns with the WS-first principle from #421) but requires plumbing the new-game event through whichever subscription handles it. Option A is the smaller change and gets the immediate UX win.
Acceptance criteria
- No fixed-duration `setTimeout` sleep before `getTx`
- Median table-creation completes in <500ms (vs current ~2s+)
- Worst-case behaviour under a slow indexer is the same or better than today (i.e., still falls through to `{ txHash, gameId: null }` after a reasonable budget)
- No regression on the "chain accepted but message failed" path (the `code !== 0` check below the sleep)
Related
Part of #421 (FE CPU umbrella). Surfaced alongside #(auto-action race bug) while auditing `setTimeout` usage.
- Ngôn ngữ chính
- TypeScript
- Star
- 2
- Fork
- 5
- Merge trung bình
- 23 giờ 23 phút
- Pull request đã merge (30 ngày)
- 97
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của block52/ui
-
guards: accept readonly arrays (and other array-likes) in isEmpty / hasElements / safeLengthĐang mởenhancement tech debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
feat(ui): player notes and tags — click a seat to note a player; tag icons (fish, shark, tight, loose…) show by their pillCó thể đã có người làm @Dzeezbtc đã nhận 3 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
chore(ui): move existing inline null/empty and typeof checks to the guardsCó thể đã có người làm @bitcoinbrisbane đã nhận 3 ngày trước. Đang mởrefactor tech debt UI
block52/ui#937 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
architecture refactor tech debt
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Website: the hero tip's video play() has no catch, so a refused play is an unhandled rejectionĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
liberation-data/drivine#615 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend bug ready-for-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
geolens-io/geolens#3639 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
radius-project/ai-extensions#1196 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100