Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(notifications): notifications status/list remain stale on stale tab (#4268)
dev-rb70f80c690cd3
diff --git a/js/app/packages/queries/notification/user-notifications.ts b/js/app/packages/queries/notification/user-notifications.tsindex 4649d75b40..ffce795d1e 100644--- a/js/app/packages/queries/notification/user-notifications.ts+++ b/js/app/packages/queries/notification/user-notifications.ts@@ -78,6 +78,8 @@ export function useUserNotificationsQuery(args?: { limit?: number }) {UserNotificationsPageParam>) => data.pages.flatMap(({ items }) => items.map(stripOwnerId)),+ // Always refetch in the case of a stale browser tab+ refetchOnWindowFocus: 'always',}));}diff --git a/js/app/packages/service-clients/service-connection/websocket.ts b/js/app/packages/service-clients/service-connection/websocket.tsindex 33a6a11686..dc737bb1f2 100644--- a/js/app/packages/service-clients/service-connection/websocket.ts+++ b/js/app/packages/service-clients/service-connection/websocket.ts@@ -56,6 +56,24 @@ export const ws = new WebsocketBuilder(resolveWsUrl)}).build();+function reconnectIfDisconnected() {+ ws.reconnectIfDisconnected();+}++function handleVisibilityChange() {+ if (document.visibilityState === 'visible') {+ reconnectIfDisconnected();+ }+}++// When the browser regains connectivity or a background tab becomes visible,+// kick the connection immediately instead of waiting for heartbeat/backoff+// timers, which may have been throttled while the tab was stale.+if (typeof window !== 'undefined' && typeof document !== 'undefined') {+ window.addEventListener('online', reconnectIfDisconnected);+ document.addEventListener('visibilitychange', handleVisibilityChange);+}+export const state = createWebsocketStateSignal(ws);// TODO: add type mapping on the websocket eventexport function createConnectionBlockWebsocketEffect(diff --git a/js/app/packages/service-clients/service-storage/websocket.ts b/js/app/packages/service-clients/service-storage/websocket.tsindex f656da95a8..0eef378888 100644--- a/js/app/packages/service-clients/service-storage/websocket.ts+++ b/js/app/packages/service-clients/service-storage/websocket.ts@@ -34,6 +34,24 @@ const ws = new WebsocketBuilder(SERVER_HOSTS['websocket-service'])export const storageWS = ws;+function reconnectIfDisconnected() {+ storageWS.reconnectIfDisconnected();+}++function handleVisibilityChange() {+ if (document.visibilityState === 'visible') {+ reconnectIfDisconnected();+ }+}++// When the browser regains connectivity or a background tab becomes visible,+// kick the connection immediately instead of waiting for heartbeat/backoff+// timers, which may have been throttled while the tab was stale.+if (typeof window !== 'undefined' && typeof document !== 'undefined') {+ window.addEventListener('online', reconnectIfDisconnected);+ document.addEventListener('visibilitychange', handleVisibilityChange);+}+const _state = createWebsocketStateSignal(ws);type WebSocketJobConfig<T, R, D, U> = {