fix(web): reconcile client state when a settle does not land #4593
Closedcolonelpanic8(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/4593/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/lib/resyncRequests.ts lines 19 to 19OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,19 @@1+import { ResyncRequests } from "@t3tools/client-runtime/connection";2+3+/**4+ * Coalescing wrapper around the shared resync signal.5+ *6+ * A reconcile costs a snapshot fetch and a resubscribe, and the callers that7+ * need one arrive in bursts — settling twenty threads at once would otherwise8+ * ask twenty times for work that a single reconcile already covers for the9+ * whole environment.10+ */11+12+/** Minimum spacing between reconciles. */13+export const RESYNC_MIN_INTERVAL_MS = 5_000;14+15+let lastRequestAtMs: number | null = null;16+17+/** Request a reconcile, dropping anything inside the coalescing window. */18+export function requestResync(nowMs: number = Date.now()): void {19+ if (lastRequestAtMs !== null && nowMs - lastRequestAtMs < RESYNC_MIN_INTERVAL_MS) {
- apps/web/src/lib/resyncRequests.ts line 78Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +4,21 @@4+ * Coalescing wrapper around the shared resync signal.5+ *6+ * A reconcile costs a snapshot fetch and a resubscribe, and the callers that7+ * need one arrive in bursts — settling twenty threads at once would otherwise8+ * ask twenty times for work that a single reconcile already covers for the9+ * whole environment.10+ */11+12+/** Minimum spacing between reconciles. */13+export const RESYNC_MIN_INTERVAL_MS = 5_000;14+15+let lastRequestAtMs: number | null = null;16+17+/** Request a reconcile, dropping anything inside the coalescing window. */18+export function requestResync(nowMs: number = Date.now()): void {19+ if (lastRequestAtMs !== null && nowMs - lastRequestAtMs < RESYNC_MIN_INTERVAL_MS) {20+ return;21+ }22+ lastRequestAtMs = nowMs;23+ ResyncRequests.requestResync();24+}
- apps/web/src/lib/resyncRequests.ts line 77Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +44,21 @@44+ * defers to the end of the current window — never drops the request.45+ */46+export function requestResync(scheduler: ResyncScheduler = defaultScheduler): void {47+ const nowMs = scheduler.now();48+ const elapsedMs = lastFiredAtMs === null ? null : nowMs - lastFiredAtMs;49+ // A clock that jumped backward (NTP correction, manual change) must not50+ // wedge the throttle shut until wall time catches back up: a negative51+ // elapsed means the recorded timestamp is meaningless, so start a fresh52+ // window rather than suppressing every reconcile in the meantime.53+ if (elapsedMs === null || elapsedMs < 0 || elapsedMs >= RESYNC_MIN_INTERVAL_MS) {54+ fire(nowMs);55+ return;56+ }57+ if (trailingScheduled) {58+ return;59+ }60+ trailingScheduled = true;61+ scheduler.setTimer(() => {62+ trailingScheduled = false;63+ fire(scheduler.now());64+ }, RESYNC_MIN_INTERVAL_MS - elapsedMs);
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
7aafa55e-231f-4def-b5dd-92cf8e16bd20You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
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