Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(desktop): stop the ambient offline toast duplicating the banner (#95231)

Paul D'Ambra99e6292b2543
diff --git a/products/desktop/packages/ui/src/features/connectivity/connectivity-events.contribution.ts b/products/desktop/packages/ui/src/features/connectivity/connectivity-events.contribution.ts
index 942e6ae18be0..ffa5dc238526 100644
--- a/products/desktop/packages/ui/src/features/connectivity/connectivity-events.contribution.ts
+++ b/products/desktop/packages/ui/src/features/connectivity/connectivity-events.contribution.ts
@@ -5,13 +5,13 @@ import {
CONNECTIVITY_CLIENT,
type ConnectivityClient,
} from "./connectivityClient";
-import { initializeConnectivityToast } from "./connectivityToast";
+import { initializeConnectivityToastDismissal } from "./connectivityToast";
/**
* Boots connectivity once at startup (formerly the platform-adapters/connectivity
* side-effect module): seeds the domain online store from the host's current
- * status, keeps it in sync via the status-change subscription, and starts the
- * debounced offline toast.
+ * status, keeps it in sync via the status-change subscription, and clears the
+ * offline toast on reconnect.
*/
@injectable()
export class ConnectivityEventsContribution implements Contribution {
@@ -32,6 +32,6 @@ export class ConnectivityEventsContribution implements Contribution {
onData: (status) => setOnline(status.isOnline),
});
- initializeConnectivityToast();
+ initializeConnectivityToastDismissal();
}
}
diff --git a/products/desktop/packages/ui/src/features/connectivity/connectivityToast.ts b/products/desktop/packages/ui/src/features/connectivity/connectivityToast.ts
index 10cb5d7b3afd..b932a676ec3e 100644
--- a/products/desktop/packages/ui/src/features/connectivity/connectivityToast.ts
+++ b/products/desktop/packages/ui/src/features/connectivity/connectivityToast.ts
@@ -1,12 +1,15 @@
import { connectivityStore } from "@posthog/core/connectivity/connectivityStore";
import { toast } from "../../primitives/toast";
-const OFFLINE_DEBOUNCE_MS = 5_000;
-
// The live offline toast's id, tracked so re-entry never stacks a second one and
// reconnect dismisses exactly this toast.
let offlineToastId: string | undefined;
+/**
+ * Surfaces the offline toast for an action the user just tried and that the
+ * network blocked. Going offline on its own does not raise a toast — the shell's
+ * ConnectivityBanner already reports that state.
+ */
export function showOfflineToast() {
if (offlineToastId) return;
offlineToastId = toast.error("No internet connection", {
@@ -22,37 +25,16 @@ function dismissOfflineToast() {
offlineToastId = undefined;
}
-// Debounces flaky transitions: only surfaces a toast when continuously offline
-// for OFFLINE_DEBOUNCE_MS. A single tracked toast id guarantees it never stacks.
-export function initializeConnectivityToast() {
- let pendingTimer: ReturnType<typeof setTimeout> | null = null;
+// The action toast has no duration, so it needs the reconnect to clear it.
+export function initializeConnectivityToastDismissal() {
let wasOnline = connectivityStore.getState().isOnline;
- const clearPending = () => {
- if (pendingTimer) {
- clearTimeout(pendingTimer);
- pendingTimer = null;
- }
- };
-
- const unsubscribe = connectivityStore.subscribe((state) => {
+ return connectivityStore.subscribe((state) => {
if (state.isOnline === wasOnline) return;
wasOnline = state.isOnline;
- if (!state.isOnline) {
- clearPending();
- pendingTimer = setTimeout(() => {
- pendingTimer = null;
- showOfflineToast();
- }, OFFLINE_DEBOUNCE_MS);
- } else {
- clearPending();
+ if (state.isOnline) {
dismissOfflineToast();
}
});
-
- return () => {
- clearPending();
- unsubscribe();
- };
}
diff --git a/products/desktop/packages/ui/src/shell/App.tsx b/products/desktop/packages/ui/src/shell/App.tsx
index 12e806385eff..85c9a8af96ab 100644
--- a/products/desktop/packages/ui/src/shell/App.tsx
+++ b/products/desktop/packages/ui/src/shell/App.tsx
@@ -18,6 +18,7 @@ import { CanvasGenerationToaster } from "@posthog/ui/features/canvas/freeform/us
import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";
import { showChannelList } from "@posthog/ui/features/canvas/stores/channelPaneStore";
import { useSpaceTreeStore } from "@posthog/ui/features/canvas/stores/spaceTreeStore";
+import { ConnectivityBanner } from "@posthog/ui/features/connectivity/ConnectivityBanner";
import { ConsentScreen } from "@posthog/ui/features/consent/ConsentScreen";
import { useConsentAnalytics } from "@posthog/ui/features/consent/consentAnalytics";
import { useOrgConsent } from "@posthog/ui/features/consent/useOrgConsent";
@@ -240,8 +241,21 @@ function App({ devToolbar }: AppProps) {
return <AppLoadingScreen />;
}
+ // Which screen the app is on. The four pre-router screens render instead of
+ // the RouterProvider, so anything the routed shell mounts is absent there.
+ const activeScreen =
+ !hasCompletedOnboarding && !isBlockedByAccessPolicy
+ ? "onboarding"
+ : !isAuthenticated
+ ? "auth"
+ : isBlockedByAccessPolicy
+ ? "desktop-access"
+ : consent.status === "error" || needsConsent
+ ? "consent"
+ : "main";
+
const renderContent = () => {
- if (!hasCompletedOnboarding && !isBlockedByAccessPolicy) {
+ if (activeScreen === "onboarding") {
return (
<motion.div
key="onboarding"
@@ -255,7 +269,7 @@ function App({ devToolbar }: AppProps) {
);
}
- if (!isAuthenticated) {
+ if (activeScreen === "auth") {
return (
<motion.div key="auth" initial={{ opacity: 1 }} className="h-full">
<AuthScreen
@@ -265,7 +279,7 @@ function App({ devToolbar }: AppProps) {
);
}
- if (isBlockedByAccessPolicy) {
+ if (activeScreen === "desktop-access") {
return (
<motion.div
key="desktop-access"
@@ -297,7 +311,7 @@ function App({ devToolbar }: AppProps) {
);
}
- if (consent.status === "error" || needsConsent) {
+ if (activeScreen === "consent") {
return (
<motion.div key="consent" initial={{ opacity: 1 }} className="h-full">
<ConsentScreen
@@ -331,6 +345,9 @@ function App({ devToolbar }: AppProps) {
shouldSuppress={isNotAuthenticatedError}
>
<div className="flex h-screen flex-col">
+ {/* The routed shell mounts its own banner at `__root`; the pre-router
+ screens are outside the router, so they get it from here. */}
+ {activeScreen !== "main" && <ConnectivityBanner />}
<div className="relative min-h-0 flex-1 overflow-hidden">
{isAuthenticated ? (
<AnimatePresence mode="wait">{content}</AnimatePresence>