[PR #5381] [MERGED] fix(desktop): window lifecycle for instance switch #5180

Closed
opened 2026-03-17 02:39:01 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5381
Author: @CuriousCorrelation
Created: 9/9/2025
Status: Merged
Merged: 9/22/2025
Merged by: @jamesgeorge007

Base: nextHead: desktop-fix-window-lifecycle-management


📝 Commits (2)

  • aba26c0 fix(desktop): window lifecycle for instance switch
  • 2b51f5a chore: resolve lint errors

📊 Changes

3 files changed (+56 additions, -19 deletions)

View changed files

📝 packages/hoppscotch-common/package.json (+1 -1)
📝 packages/hoppscotch-common/src/services/instance-switcher.service.ts (+53 -8)
📝 pnpm-lock.yaml (+2 -10)

📄 Description

This resolves window accumulation during instance switching by implementing proper window lifecycle management using Tauri's WebviewWindow APIs.

Closes FE-1015

Issue

When switching between server instances and vendored instances,
previous windows remained open instead of closing automatically.

This creates multiple windows for what should be a single-window
experience and eventually blocks further instance switching (> 3 at the
moment) mainly due to window label conflicts.

The new close method was introduced as part of the portable phase-2,
and while it works for the portable version, this patch reinforces the
backwards compatibility for current switcher until the complete
switcher service rewrite planned for upcoming phases.

The current issue is a byproduct of that refactor that manifests as:

  • Switching from vendored → server => vendored window closed correctly
  • Switching from server → vendored => server window remained open
  • Switching between servers => previous server windows remained open

Cause & Context

The InstanceSwitcherService was missing window lifecycle management.
While the service handled connection state and data persistence, it did
not close the current window after successfully loading a new instance,
as oppose to the similar service implementation in Home.vue.

The correct sequence:

  1. Load new window (creates new execution context)
  2. Close current window (from original execution context)
  3. Update state and complete transition
    • Updating happens in the prior window
    • Sync happens with the store files
    • New window re-gathers the state from the store file

Fix

  • Uses Tauri's WebviewWindow APIs (getCurrentWebviewWindow, getAllWebviewWindows)
  • Plus, includes safeguards to prevent closing the last remaining window

Updated both connectToVendoredInstance() and
connectToServerInstance() to call window cleanup after successful
load operations using fire-and-forget (no await) pattern to avoid
execution context issues.

Testing

  • Vendored → Server switching: Only target window remains
  • Server → Vendored switching: Only target window remains
  • Server → Server switching: Only target window remains
  • Multiple rapid switches: No window accumulation

Implementation Notes

Uses non-awaited closeCurrentWindow()
calls because window closing must happen from the current execution
context before it terminates. Awaiting the close operation would create
timing issues.

Uses getCurrentWebviewWindow() and
getAllWebviewWindows() instead of deprecated v1/v2 APIs, with
sync label property access.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5381 **Author:** [@CuriousCorrelation](https://github.com/CuriousCorrelation) **Created:** 9/9/2025 **Status:** ✅ Merged **Merged:** 9/22/2025 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `next` ← **Head:** `desktop-fix-window-lifecycle-management` --- ### 📝 Commits (2) - [`aba26c0`](https://github.com/hoppscotch/hoppscotch/commit/aba26c03c294536c2e9a36742720ae567af5fb3b) fix(desktop): window lifecycle for instance switch - [`2b51f5a`](https://github.com/hoppscotch/hoppscotch/commit/2b51f5a218d46fbc9ac49125ec6ae83a17ca1f38) chore: resolve lint errors ### 📊 Changes **3 files changed** (+56 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/package.json` (+1 -1) 📝 `packages/hoppscotch-common/src/services/instance-switcher.service.ts` (+53 -8) 📝 `pnpm-lock.yaml` (+2 -10) </details> ### 📄 Description This resolves window accumulation during instance switching by implementing proper window lifecycle management using Tauri's WebviewWindow APIs. Closes FE-1015 ## Issue When switching between server instances and vendored instances, previous windows remained open instead of closing automatically. This creates multiple windows for what should be a single-window experience and eventually blocks further instance switching (> 3 at the moment) mainly due to window label conflicts. The new `close` method was introduced as part of the portable phase-2, and while it works for the portable version, this patch reinforces the backwards compatibility for current switcher until the complete switcher service rewrite planned for upcoming phases. The current issue is a byproduct of that refactor that manifests as: - Switching from vendored → server => vendored window closed correctly - Switching from server → vendored => server window remained open - Switching between servers => previous server windows remained open ## Cause & Context The `InstanceSwitcherService` was missing window lifecycle management. While the service handled connection state and data persistence, it did not close the current window after successfully loading a new instance, as oppose to the similar service implementation in `Home.vue`. The correct sequence: 1. Load new window (creates new execution context) 2. Close current window (from original execution context) 3. Update state and complete transition - Updating happens in the prior window - Sync happens with the store files - New window re-gathers the state from the store file ## Fix - Uses Tauri's WebviewWindow APIs (`getCurrentWebviewWindow`, `getAllWebviewWindows`) - Plus, includes safeguards to prevent closing the last remaining window Updated both `connectToVendoredInstance()` and `connectToServerInstance()` to call window cleanup after successful load operations using fire-and-forget (no `await`) pattern to avoid execution context issues. ## Testing - Vendored → Server switching: Only target window remains - Server → Vendored switching: Only target window remains - Server → Server switching: Only target window remains - Multiple rapid switches: No window accumulation ## Implementation Notes Uses non-awaited `closeCurrentWindow()` calls because window closing must happen from the current execution context before it terminates. Awaiting the close operation would create timing issues. Uses `getCurrentWebviewWindow()` and `getAllWebviewWindows()` instead of deprecated v1/v2 APIs, with sync `label` property access. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:39:01 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5180
No description provided.