Skip to content

Commit b8fe36e

Browse files
committed
fix(web): reopening Connections picks up new network addresses
Move keepAlive from the SWR wrapper to the source atom so the wrapper remounts when Connections reopens and revalidates a stale snapshot, while the previous snapshot still renders immediately. Fixes #15751.
1 parent ad5178a commit b8fe36e

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎apps/web/src/state/desktopNetworkAccess.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,48 @@ describe("desktopNetworkAccessState", () => {
5151
registry.dispose();
5252
});
5353

54+
it("revalidates when the settings screen remounts after the snapshot is stale", async () => {
55+
vi.useFakeTimers({ toFake: ["Date"] });
56+
try {
57+
const getServerExposureState = vi.fn(async () => serverExposureState);
58+
const getAdvertisedEndpoints = vi.fn(async () => advertisedEndpoints);
59+
const atom = createDesktopNetworkAccessStateAtom(() => ({
60+
getAdvertisedEndpoints,
61+
getServerExposureState,
62+
}));
63+
const registry = AtomRegistry.make();
64+
65+
const unmount = registry.mount(atom);
66+
await vi.waitFor(() => {
67+
expect(AsyncResult.value(registry.get(atom))).toEqual(
68+
expect.objectContaining({ _tag: "Some" }),
69+
);
70+
});
71+
unmount();
72+
// Leaving the screen releases the SWR wrapper; the loaded snapshot stays alive.
73+
await vi.waitFor(() => expect(registry.getNodes().has(atom)).toBe(false));
74+
75+
vi.advanceTimersByTime(30_001);
76+
77+
const remount = registry.mount(atom);
78+
expect(AsyncResult.value(registry.get(atom))).toEqual(
79+
expect.objectContaining({
80+
_tag: "Some",
81+
value: { advertisedEndpoints, serverExposureState },
82+
}),
83+
);
84+
await vi.waitFor(() => {
85+
expect(getServerExposureState).toHaveBeenCalledTimes(2);
86+
expect(getAdvertisedEndpoints).toHaveBeenCalledTimes(2);
87+
});
88+
89+
remount();
90+
registry.dispose();
91+
} finally {
92+
vi.useRealTimers();
93+
}
94+
});
95+
5496
it.each([
5597
{
5698
cause: serverExposureLoadCause,

‎apps/web/src/state/desktopNetworkAccess.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ export function createDesktopNetworkAccessStateAtom(
7979
} satisfies DesktopNetworkAccessSnapshot;
8080
});
8181

82+
// Keep the loaded snapshot alive, but let the SWR wrapper unmount so reopening
83+
// Connections after the stale period revalidates while showing the old snapshot.
8284
return Atom.make(loadDesktopNetworkAccess()).pipe(
85+
Atom.keepAlive,
8386
Atom.swr({
8487
staleTime: DESKTOP_NETWORK_ACCESS_STALE_TIME_MS,
8588
revalidateOnMount: true,
8689
}),
87-
Atom.keepAlive,
8890
Atom.withLabel("desktop:network-access"),
8991
);
9092
}

0 commit comments

Comments
 (0)