Skip to content

Commit 95525ca

Browse files
authored
Fix soft navigation subscription cleanup. (#219)
1 parent 5ac1dad commit 95525ca

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

.changeset/breezy-rockets-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'electron-trpc': minor
3+
---
4+
5+
Fix bug where soft-navigation events would cause subscription cleanup

packages/electron-trpc/src/main/createIPCHandler.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,19 @@ class IPCHandler<TRouter extends AnyRouter> {
7979
}
8080

8181
#attachSubscriptionCleanupHandlers(win: BrowserWindow) {
82-
win.webContents.on('did-start-navigation', ({ frame }) => {
83-
debug(
84-
'Handling webContents `did-start-navigation` event',
85-
`webContentsId: ${win.webContents.id}`,
86-
`frameRoutingId: ${frame.routingId}`
87-
);
88-
this.#cleanUpSubscriptions({
89-
webContentsId: win.webContents.id,
90-
frameRoutingId: frame.routingId,
91-
});
82+
win.webContents.on('did-start-navigation', ({ isSameDocument, frame }) => {
83+
// Check if it's a hard navigation
84+
if (!isSameDocument) {
85+
debug(
86+
'Handling hard navigation event',
87+
`webContentsId: ${win.webContents.id}`,
88+
`frameRoutingId: ${frame.routingId}`
89+
);
90+
this.#cleanUpSubscriptions({
91+
webContentsId: win.webContents.id,
92+
frameRoutingId: frame.routingId,
93+
});
94+
}
9295
});
9396
win.webContents.on('destroyed', () => {
9497
debug('Handling webContents `destroyed` event');

0 commit comments

Comments
 (0)