GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mobile): a slow older widget read no longer overwrites newer rows · pingdotgg/t3code@f7773cf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/mobile/src/features/agent-awareness
    • remoteRegistration.test.ts
    • remoteRegistration.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/mobile/src/features/agent-awareness/remoteRegistration.test.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/agent-awareness/remoteRegistration.test.ts
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,34 @@ describe("makeRelayDeviceRegistrationRequest", () => {
13821382
}).pipe(Effect.provide(relay));
13831383
});
13841384

1385+
it.effect("keeps the newest rows when an older overlapping read finishes last", () =>
1386+
Effect.gen(function* () {
1387+
const newer = { ...aggregate, activeCount: 2 };
1388+
const olderRequested = yield* Deferred.make<void>();
1389+
const olderResponse = yield* Deferred.make<{ readonly aggregate: typeof aggregate }>();
1390+
let reads = 0;
1391+
const relay = fakeRelay(() => {
1392+
reads++;
1393+
return reads === 1
1394+
? Deferred.succeed(olderRequested, undefined).pipe(
1395+
Effect.andThen(Deferred.await(olderResponse)),
1396+
)
1397+
: Effect.succeed({ aggregate: newer });
1398+
});
1399+
setAgentAwarenessRelayTokenProvider(() => Promise.resolve("clerk-token"), "user-a");
1400+
1401+
const older = yield* Effect.forkChild(
1402+
refreshActiveLiveActivityRemoteRegistration().pipe(Effect.provide(relay)),
1403+
);
1404+
yield* Deferred.await(olderRequested);
1405+
yield* refreshActiveLiveActivityRemoteRegistration().pipe(Effect.provide(relay));
1406+
yield* Deferred.succeed(olderResponse, { aggregate });
1407+
yield* Fiber.join(older);
1408+
1409+
expect(publishWidgetMock).toHaveBeenLastCalledWith({ kind: "snapshot", aggregate: newer });
1410+
}),
1411+
);
1412+
13851413
it("shows the signed-out state after cloud sign-out", () => {
13861414
setAgentAwarenessRelayTokenProvider(() => Promise.resolve("clerk-token"), "user-a");
13871415

Collapse file

‎apps/mobile/src/features/agent-awareness/remoteRegistration.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/agent-awareness/remoteRegistration.ts
+22-10Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ const registeredActivityPushTokens = new Map<string, number>();
9494
// A failed read keeps the current account's last rows, but must not leave the
9595
// widget claiming the user is signed out or showing a previous account.
9696
let widgetShowsCurrentAccount = false;
97+
// Refreshes can overlap (sign-in, foreground, retry); only the newest read may
98+
// repaint, so a slow older response never overwrites newer rows.
99+
let widgetSnapshotReads = 0;
97100
let androidDeviceReplayedAt: number | null = null;
98101
let pushTokenSubscription: { remove: () => void } | null = null;
99102
let appStateSubscription: { remove: () => void } | null = null;
@@ -917,6 +920,7 @@ export function __resetAgentAwarenessRemoteRegistrationForTest(): void {
917920
registeredActivityPushTokens.clear();
918921
activityPushTokenLocks.clear();
919922
widgetShowsCurrentAccount = false;
923+
widgetSnapshotReads = 0;
920924
}
921925

922926
export function unregisterAgentAwarenessDeviceForCurrentUser(
@@ -1059,21 +1063,28 @@ export function refreshActiveLiveActivityRemoteRegistration(): Effect.Effect<
10591063
}
10601064

10611065
// The home-screen widget has no push path of its own, so every foreground
1062-
// refresh repaints it from one snapshot read. Returns false once the account
1063-
// changed during the read, so a stale result is never shown or primed.
1066+
// refresh repaints it from one snapshot read. Yields undefined once the
1067+
// account changed or a newer read started, so a stale result is never
1068+
// shown or primed.
10641069
const identity = relayTokenProviderIdentity;
1065-
const repaintWidget = (snapshot: RelayAgentActivitySnapshotResponse | null): boolean => {
1066-
if (!relayTokenProvider || relayTokenProviderIdentity !== identity) {
1067-
return false;
1070+
const refreshWidget = Effect.gen(function* () {
1071+
const read = ++widgetSnapshotReads;
1072+
const snapshot = yield* readAgentActivitySnapshot();
1073+
if (
1074+
read !== widgetSnapshotReads ||
1075+
!relayTokenProvider ||
1076+
relayTokenProviderIdentity !== identity
1077+
) {
1078+
return undefined;
10681079
}
10691080
if (snapshot) {
10701081
widgetShowsCurrentAccount = true;
10711082
publishWidget({ kind: "snapshot", aggregate: snapshot.aggregate });
10721083
} else if (!widgetShowsCurrentAccount) {
10731084
publishWidget({ kind: "unavailable" });
10741085
}
1075-
return true;
1076-
};
1086+
return { snapshot };
1087+
});
10771088

10781089
let activities = yield* Effect.try({
10791090
try: () => getAgentLiveActivities(),
@@ -1108,10 +1119,11 @@ export function refreshActiveLiveActivityRemoteRegistration(): Effect.Effect<
11081119
// remote-starts one (background push-to-start wakes proved too unreliable
11091120
// to hand the token over).
11101121
if (!hadActivities) {
1111-
const snapshot = yield* readAgentActivitySnapshot();
1112-
if (!repaintWidget(snapshot)) {
1122+
const widgetRead = yield* refreshWidget;
1123+
if (!widgetRead) {
11131124
return;
11141125
}
1126+
const { snapshot } = widgetRead;
11151127
const preferences = yield* Effect.tryPromise({
11161128
try: () => loadPreferences(),
11171129
catch: (cause) =>
@@ -1185,7 +1197,7 @@ export function refreshActiveLiveActivityRemoteRegistration(): Effect.Effect<
11851197
// An existing card keeps its push token registered without waiting on the
11861198
// relay; the widget still repaints afterwards.
11871199
if (hadActivities) {
1188-
repaintWidget(yield* readAgentActivitySnapshot());
1200+
yield* refreshWidget;
11891201
}
11901202
});
11911203
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.