Repository navigation
fix(web): preserve newer navigation when reopening closed views #40516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juliusmarminge
merged 7 commits into
pingdotgg:main
from
StiensWout:t3/1266-reopening-a-browser-tab-can-switch-you-a
Nov 21, 2026
+245
−9
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
45a4bd1
test(web): cover navigation during Browser tab reopen
StiensWout c6cfca0
fix(web): preserve newer navigation when reopening closed views
StiensWout e6a6365
fix(web): follow queued reopens through deferred history commits
StiensWout b1cfb33
test(web): observe reopen history through the closed-view store
StiensWout 12713af
test(web): restore the original browser reopen scenario probe
StiensWout b2721d7
chore: credit the models that worked on this change
StiensWout 9d4682a
Merge remote-tracking branch 'origin/main' into t3/1266-reopening-a-b…
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
scripts/scenarios/reopening-browser-keeps-the-newer-thread.e2e.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /// <reference lib="dom" /> | ||
| import { expect } from "e2e"; | ||
|
|
||
| import { test, WEB } from "./t3.ts"; | ||
|
|
||
| interface ReopenGate { | ||
| readonly closed: Promise<void>; | ||
| readonly requested: Promise<void>; | ||
| readonly arm: () => void; | ||
| readonly release: () => Promise<void>; | ||
| } | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| reopenGate: ReopenGate; | ||
| } | ||
| } | ||
|
|
||
| test( | ||
| "A browser tab finishing its reopen leaves the newer conversation on screen", | ||
| WEB, | ||
| async ({ t3, app, browser, screen }) => { | ||
| const project = await t3.project("demo"); | ||
| const owner = await t3.thread({ project, title: "Browser owner", messages: ["first"] }); | ||
| await t3.thread({ | ||
| project, | ||
| title: "Newer conversation", | ||
| messages: ["Stay in this conversation"], | ||
| }); | ||
|
|
||
| await browser.addInitScript(() => { | ||
| const closed = Promise.withResolvers<void>(); | ||
| const requested = Promise.withResolvers<void>(); | ||
| const restored = Promise.withResolvers<void>(); | ||
| let hasClosedBrowser = false; | ||
| let armed = false; | ||
| let sendHeld = () => {}; | ||
| const setItem = Storage.prototype.setItem; | ||
| Storage.prototype.setItem = function (key, value) { | ||
| setItem.call(this, key, value); | ||
| if (key !== "t3code:closed-views:v2") return; | ||
| const hasBrowser = value.includes('"kind":"browser"'); | ||
| if (hasBrowser) closed.resolve(); | ||
| else if (hasClosedBrowser) restored.resolve(); | ||
| hasClosedBrowser = hasBrowser; | ||
| }; | ||
| const send = WebSocket.prototype.send; | ||
| WebSocket.prototype.send = function (data) { | ||
| if (!armed || typeof data !== "string") return send.call(this, data); | ||
| const parsed = JSON.parse(data); | ||
| const messages = [parsed].flat(); | ||
| const isOpen = (message: { _tag?: string; tag?: string }) => | ||
| message._tag === "Request" && message.tag === "preview.open"; | ||
| const previewOpens = messages.filter(isOpen); | ||
| if (previewOpens.length === 0) return send.call(this, data); | ||
| armed = false; | ||
| const others = messages.filter((message) => !isOpen(message)); | ||
| if (others.length > 0) send.call(this, JSON.stringify(others)); | ||
| sendHeld = () => | ||
| send.call(this, Array.isArray(parsed) ? JSON.stringify(previewOpens) : data); | ||
| requested.resolve(); | ||
| }; | ||
| window.reopenGate = { | ||
| closed: closed.promise, | ||
| requested: requested.promise, | ||
| arm: () => { | ||
| armed = true; | ||
| }, | ||
| release: () => { | ||
| sendHeld(); | ||
| return restored.promise; | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| await t3.open(owner); | ||
| await screen.getByRole("button", "Toggle right panel").tap(); | ||
| await screen.getByRole("button", "Browser B").tap(); | ||
| await screen.getByRole("button", "Close Browser", { exact: true }).tap(); | ||
| await browser.evaluate(async () => { | ||
| await window.reopenGate.closed; | ||
| window.reopenGate.arm(); | ||
| return null; | ||
| }); | ||
|
|
||
| await browser.keyboard.press("Control+Shift+t"); | ||
| await browser.evaluate(async () => { | ||
| await window.reopenGate.requested; | ||
| return null; | ||
| }); | ||
| await screen.getByRole("button", "Newer conversation", { exact: false }).tap(); | ||
| const newerMessage = screen.getByText("Stay in this conversation", { exact: true }); | ||
| await newerMessage.waitFor(); | ||
| const newerUrl = await browser.url(); | ||
| await browser.evaluate(async () => { | ||
| await window.reopenGate.release(); | ||
| return null; | ||
| }); | ||
|
|
||
| await app.screenshot("conversation-after-browser-reopens"); | ||
| await expect(browser).toHaveURL(newerUrl); | ||
| }, | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recheck the current location after a deferred blocker resolves, before the restore push.
When an allowing blocker defers the restore navigation, a newer navigation can commit first. This needs a blocker that allows the newer navigation while it defers the restore. The subscription then unsubscribes, but it does not cancel the pending navigation. When the blocker resolves, the history task pushes the restore destination without another location check. The newer conversation is displaced. The check at line 153 runs before the blocker wait, so it does not cover this window.
Skip the stale commit when the location has changed. The check must run after the blocker resolves and before the history push. Updating
request.locationalone does not cover this path.Add a regression test to
ReopenClosedViewShortcut.browser.test.tsx. Use a blocker that resolves later, and commit a newer navigation before it resolves. The existing blocker test usesblockerFn: () => false, so it does not exercise this ordering.