perf(ux): useNewTable sleeps 2s for tx indexer — replace with WS event or backoff poll
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
- #748 di @Dzeezbtc — chiusa senza merge
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 2
- Fork
- 5
- Merge medio
- 23h 23m
- PR unite (30g)
- 97
Preparare l'ambiente
Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di block52/ui
-
enhancement tech debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
feat(ui): player notes and tags — click a seat to note a player; tag icons (fish, shark, tight, loose…) show by their pillForse già presa @Dzeezbtc l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
chore(ui): move existing inline null/empty and typeof checks to the guardsForse già presa @bitcoinbrisbane l’ha presa 3 giorni fa. Apertarefactor tech debt UI
block52/ui#937 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
architecture refactor tech debt
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
caprover/caprover-frontend#273 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ai-driven-dev/framework#1147 ·
I maintainer di solito rispondono entro 1 giorno
-
agent-ui bug p2
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
cybersemics/em#6232 ·
I maintainer di solito rispondono entro 1 giorno