Skip to content

test: reproduce #1637 — browser pane reloads on tab switch#1638

Closed
github-actions[bot] wants to merge 1 commit into
mainfrom
triage/issue-1637-22239589694
Closed

test: reproduce #1637 — browser pane reloads on tab switch#1638
github-actions[bot] wants to merge 1 commit into
mainfrom
triage/issue-1637-22239589694

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

What the bug is

When a user navigates away from a tab containing a browser pane and then switches back, the in-app browser reloads its page from scratch, losing all state (scroll position, form inputs, etc.).

What code is affected and why

The root cause is in usePersistentWebview.ts. The hook manages a module-level webviewRegistry (a Map<paneId, WebviewTag>) and an off-screen hiddenContainer. When BrowserPane unmounts (tab switch away), its useEffect cleanup appends the <webview> element to the hidden container:

// cleanup (line ~323)
getHiddenContainer().appendChild(wv);

When BrowserPane remounts (tab switch back), the effect "reclaims" the webview:

// effect (line ~136)
container.appendChild(webview); // "Reclaim from hidden container"

In Electron, appending a <webview> element to a different parent destroys and recreates its renderer process, which fully reloads the page. The code even acknowledges this implicitly — the handleDomReady handler re-registers a new webContentsId after "DOM reparenting" — but no attempt is made to prevent the reparenting in the first place.

What the test does

usePersistentWebview.test.ts contains:

  1. 8 passing sanitizeUrl tests — baseline coverage for the URL-normalization helper (also exported so it can be tested directly).

  2. 1 failing bug-reproduction test — simulates the three-step DOM lifecycle that causes the reload:

    The test asserts parentHistory should equal ["active-container"] (i.e., no reparenting ever). It fails because parentHistory is ["active-container", "hidden-container", "active-container"], proving the reparenting — and therefore the reload — occurs.

The fix will need to keep the webview in a single parent and toggle CSS display/visibility instead of moving it between containers.

Closes #1637

Add a failing test that proves usePersistentWebview reparents the
<webview> element between an active container and a hidden off-screen
container each time a tab is switched away and back. In Electron,
reparenting a <webview> element triggers a full page reload, which
loses all page state (scroll position, form inputs, etc.).

Also export `sanitizeUrl` to enable direct unit testing; add 8 passing
tests covering the URL-normalisation logic.

Closes #1637
@Kitenite Kitenite marked this pull request as draft March 4, 2026 17:14
@Kitenite
Copy link
Copy Markdown
Collaborator

Closing: stale bot-generated test reproduction stub with no follow-up activity.

@Kitenite Kitenite closed this Mar 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor Author

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

@Kitenite Kitenite deleted the triage/issue-1637-22239589694 branch March 15, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Browser pane reloads page every time you switch away and back

1 participant