: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): keep the update banner when the feed's releaseDate parses as a Date (#98815)
Charles Vienbf7204c23be7
diff --git a/products/desktop/apps/code/scripts/inject-release-notes.mjs b/products/desktop/apps/code/scripts/inject-release-notes.mjsindex 89804d473225..55dea3c62130 100644--- a/products/desktop/apps/code/scripts/inject-release-notes.mjs+++ b/products/desktop/apps/code/scripts/inject-release-notes.mjs@@ -1,7 +1,8 @@#!/usr/bin/env nodeimport { readFileSync, realpathSync, writeFileSync } from "node:fs";import { fileURLToPath } from "node:url";-import { parse, stringify } from "yaml";+import { parse } from "yaml";+import { stringifyManifest } from "./merge-mac-manifests.mjs";export function withReleaseNotes(manifest, notes) {return { ...manifest, releaseNotes: notes };@@ -22,7 +23,7 @@ function main() {const manifest = parse(readFileSync(manifestPath, "utf8"));writeFileSync(manifestPath,- stringify(withReleaseNotes(manifest, notes)),+ stringifyManifest(withReleaseNotes(manifest, notes)),"utf8",);console.log(`Injected release notes -> ${manifestPath}`);diff --git a/products/desktop/apps/code/scripts/merge-mac-manifests.mjs b/products/desktop/apps/code/scripts/merge-mac-manifests.mjsindex a16928035ac1..99db846e80dc 100644--- a/products/desktop/apps/code/scripts/merge-mac-manifests.mjs+++ b/products/desktop/apps/code/scripts/merge-mac-manifests.mjs@@ -3,6 +3,13 @@ import { readFileSync, realpathSync, writeFileSync } from "node:fs";import { fileURLToPath } from "node:url";import { parse, stringify } from "yaml";+// electron-updater reads channel files with js-yaml's YAML 1.1 schema, which+// resolves an unquoted timestamp (releaseDate) to a Date. Serialize with the+// same schema so such strings come out quoted and round-trip as strings.+export function stringifyManifest(manifest) {+ return stringify(manifest, { schema: "yaml-1.1" });+}+export function mergeManifests(arm64, x64) {if (arm64.version !== x64.version) {throw new Error(@@ -37,7 +44,7 @@ function main() {const x64 = parse(readFileSync(x64Path, "utf8"));const merged = mergeManifests(arm64, x64);- writeFileSync(outputPath, stringify(merged), "utf8");+ writeFileSync(outputPath, stringifyManifest(merged), "utf8");console.log(`Merged ${merged.files.length} files from arm64+x64 manifests -> ${outputPath}`,);diff --git a/products/desktop/apps/code/scripts/merge-mac-manifests.test.mjs b/products/desktop/apps/code/scripts/merge-mac-manifests.test.mjsindex 4376ee990cfd..f608f079212f 100644--- a/products/desktop/apps/code/scripts/merge-mac-manifests.test.mjs+++ b/products/desktop/apps/code/scripts/merge-mac-manifests.test.mjs@@ -1,5 +1,6 @@import { describe, expect, it } from "vitest";-import { mergeManifests } from "./merge-mac-manifests.mjs";+import { parse } from "yaml";+import { mergeManifests, stringifyManifest } from "./merge-mac-manifests.mjs";const arm64Manifest = () => ({version: "1.2.3",@@ -86,3 +87,19 @@ describe("mergeManifests", () => {expect(mergeManifests(arm64, x64).files).toEqual([]);});});++describe("stringifyManifest", () => {+ it("quotes releaseDate so a YAML 1.1 reader keeps it a string", () => {+ const yaml = stringifyManifest({+ ...mergeManifests(arm64Manifest(), x64Manifest()),+ releaseNotes: "## What's Changed\n* one\n* two",+ });++ expect(yaml).toContain('releaseDate: "2026-06-20T00:00:00.000Z"');+ // The 1.1 schema resolves timestamps; a quoted scalar must stay a string.+ expect(parse(yaml, { schema: "yaml-1.1" }).releaseDate).toBe(+ "2026-06-20T00:00:00.000Z",+ );+ expect(yaml).toContain("releaseNotes: |-");+ });+});diff --git a/products/desktop/apps/code/src/main/platform-adapters/electron-updater.test.ts b/products/desktop/apps/code/src/main/platform-adapters/electron-updater.test.tsnew file mode 100644index 000000000000..55261b40a4eb--- /dev/null+++ b/products/desktop/apps/code/src/main/platform-adapters/electron-updater.test.ts@@ -0,0 +1,66 @@+import { describe, expect, it, vi } from "vitest";++type Listener = (payload: unknown) => void;++const mockAutoUpdater = vi.hoisted(() => {+ const listeners = new Map<string, Set<Listener>>();+ return {+ listeners,+ on: vi.fn((event: string, listener: Listener) => {+ if (!listeners.has(event)) listeners.set(event, new Set());+ listeners.get(event)?.add(listener);+ }),+ off: vi.fn((event: string, listener: Listener) => {+ listeners.get(event)?.delete(listener);+ }),+ emit(event: string, payload: unknown) {+ for (const listener of listeners.get(event) ?? []) listener(payload);+ },+ };+});++vi.mock("inversify", () => ({+ injectable: () => (target: unknown) => target,+}));++vi.mock("electron", () => ({+ app: { isPackaged: true },+}));++vi.mock("electron-log/main", () => ({ default: {} }));++vi.mock("electron-updater", () => ({ autoUpdater: mockAutoUpdater }));++import { ElectronUpdater } from "./electron-updater";++function updateInfo(releaseDate: unknown) {+ return {+ version: "1.2.3",+ releaseDate,+ releaseNotes: null,+ releaseName: null,+ files: [],+ };+}++describe("ElectronUpdater.onUpdateAvailable", () => {+ it.each([+ [+ "a Date parsed from an unquoted channel-file timestamp",+ new Date("2026-06-20T00:00:00.000Z"),+ "2026-06-20T00:00:00.000Z",+ ],+ ["a string", "2026-06-20T00:00:01.000Z", "2026-06-20T00:00:01.000Z"],+ ["an invalid Date", new Date("not a date"), undefined],+ ["a missing value", undefined, undefined],+ ])("reports releaseDate for %s as a string", (_name, input, expected) => {+ const handler = vi.fn();+ const unsubscribe = new ElectronUpdater().onUpdateAvailable(handler);++ mockAutoUpdater.emit("update-available", updateInfo(input));+ unsubscribe();++ expect(handler).toHaveBeenCalledTimes(1);+ expect(handler.mock.calls[0][0].releaseDate).toBe(expected);+ });+});diff --git a/products/desktop/apps/code/src/main/platform-adapters/electron-updater.ts b/products/desktop/apps/code/src/main/platform-adapters/electron-updater.tsindex 8a26a4f90f09..c62dcb4c1f84 100644--- a/products/desktop/apps/code/src/main/platform-adapters/electron-updater.ts+++ b/products/desktop/apps/code/src/main/platform-adapters/electron-updater.ts@@ -24,6 +24,20 @@ function normalizeReleaseNotes(return joined.length > 0 ? joined : null;}+// electron-updater types releaseDate as a string, but it parses the channel+// file with js-yaml, which turns an unquoted timestamp into a Date. A Date+// here fails the string output schema on `updates.getStatus`, so the renderer+// cannot read the initial update state and the update banner stays hidden.+function normalizeReleaseDate(+ releaseDate: UpdateInfo["releaseDate"],+): string | undefined {+ const value: unknown = releaseDate;+ if (value instanceof Date) {+ return Number.isNaN(value.getTime()) ? undefined : value.toISOString();+ }+ return typeof value === "string" && value.length > 0 ? value : undefined;+}+function pickDownloadSize(files: UpdateInfo["files"]): number | null {if (!files?.length) return null;const sizes = files.map((file) => file.size ?? 0).filter((size) => size > 0);@@ -86,7 +100,7 @@ export class ElectronUpdater implements IUpdater {handler({version: info.version,releaseNotes: normalizeReleaseNotes(info.releaseNotes),- releaseDate: info.releaseDate,+ releaseDate: normalizeReleaseDate(info.releaseDate),releaseName: info.releaseName,sizeBytes: pickDownloadSize(info.files),});diff --git a/products/desktop/apps/code/src/renderer/platform-adapters/updates.ts b/products/desktop/apps/code/src/renderer/platform-adapters/updates.tsindex 70450f4880a7..295f3a08a9d7 100644--- a/products/desktop/apps/code/src/renderer/platform-adapters/updates.ts+++ b/products/desktop/apps/code/src/renderer/platform-adapters/updates.ts@@ -13,6 +13,7 @@ import {} from "@posthog/ui/features/updates/updatesClient";import { toast } from "@posthog/ui/primitives/toast";import { logger } from "@posthog/ui/shell/logger";+import { useRendererWindowFocusStore } from "@posthog/ui/shell/rendererWindowFocusStore";import { hostTrpcClient } from "@renderer/trpc/client";const log = logger.scope("updates-host");@@ -42,17 +43,32 @@ void clientlog.error("Failed to get update enabled status", { error });});-void client- .getStatus()- .then((status) => {- const update = deriveUpdateUiStatus(status, store().status);- if (update) {- store().applyStatusUpdate(update);- }- })- .catch((error: unknown) => {- log.error("Failed to get update status", { error });- });+function syncStatus(): void {+ void client+ .getStatus()+ .then((status) => {+ const update = deriveUpdateUiStatus(status, store().status);+ if (update) {+ store().applyStatusUpdate(update);+ }+ })+ .catch((error: unknown) => {+ log.error("Failed to get update status", { error });+ });+}++syncStatus();++// The subscription below only carries transitions, so a status emitted before+// it was registered (or lost with it) never reaches the store. Re-read the+// snapshot on every return to the window so the banner cannot stay stale.+let wasFocused = useRendererWindowFocusStore.getState().focused;+useRendererWindowFocusStore.subscribe(({ focused }) => {+ if (focused && !wasFocused) {+ syncStatus();+ }+ wasFocused = focused;+});client.onStatus({onData: (status) => {