feat: isolate live section refresh backoff (#167)
This commit is contained in:
1 parent
5fe0b28747
commit
4870b58c5b
5 files changed
+262
-100
No files matched your search
+19
-7
@@ -1216,8 +1216,12 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
}
|
||||
|
||||
function renderLiveSnapshot(snapshot) {
|
||||
const notificationsFresh = Array.isArray(snapshot.notifications);
|
||||
if (notificationsFresh) {
|
||||
const contextFreshness = snapshot.freshness?.sections?.context;
|
||||
const eventsFreshness = snapshot.freshness?.sections?.events;
|
||||
const notificationFreshness = snapshot.freshness?.sections?.notifications;
|
||||
const hasNotifications = Array.isArray(snapshot.notifications);
|
||||
const notificationsFresh = hasNotifications && !notificationFreshness?.stale;
|
||||
if (hasNotifications) {
|
||||
if (notificationPagination.page > 1) {
|
||||
const byId = new Map(lastNotifications.map(item => [item.id, item]));
|
||||
snapshot.notifications.forEach(item => byId.set(item.id, item));
|
||||
@@ -1238,19 +1242,27 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
if (snapshot.context) {
|
||||
snapshot.context.notifications = lastNotifications;
|
||||
renderContextSnapshot(snapshot.context);
|
||||
if (!notificationsFresh) markNotificationsStale();
|
||||
if (contextFreshness?.stale) markMyWorkStale();
|
||||
else if (!notificationsFresh) markNotificationsStale();
|
||||
} else handleContextError(new Error('Context section unavailable'));
|
||||
if (snapshot.events) {
|
||||
paintEventStream(snapshot.events);
|
||||
if (Array.isArray(snapshot.events)) paintEventStream(snapshot.events);
|
||||
if (eventsFreshness?.revalidating) {
|
||||
setEventStreamStatus('Refreshing activity · showing last activity');
|
||||
} else if (eventsFreshness?.stale || eventsFreshness?.degraded) {
|
||||
const retrySeconds = Number(eventsFreshness.retry_in_seconds) || 0;
|
||||
setEventStreamStatus('Activity refresh failed · showing last activity' +
|
||||
(retrySeconds > 0 ? ' · retrying in ' + retrySeconds + 's' : ''));
|
||||
} else if (Array.isArray(snapshot.events)) {
|
||||
setEventStreamStatus('Updated ' + fmt(new Date()));
|
||||
} else {
|
||||
setEventStreamStatus('Update failed · showing last activity');
|
||||
}
|
||||
if (snapshot.freshness?.degraded && !snapshot.freshness.revalidating) {
|
||||
// Compatibility fallback for snapshots produced before section metadata.
|
||||
if (!eventsFreshness && snapshot.freshness?.degraded && !snapshot.freshness.revalidating) {
|
||||
const retrySeconds = Number(snapshot.freshness.retry_in_seconds) || 0;
|
||||
setEventStreamStatus('Refresh failed · showing last known data' +
|
||||
(retrySeconds > 0 ? ' · retrying in ' + retrySeconds + 's' : ''));
|
||||
} else if (snapshot.freshness?.revalidating) {
|
||||
} else if (!eventsFreshness && snapshot.freshness?.revalidating) {
|
||||
setEventStreamStatus('Refreshing · showing recent snapshot');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user