Skip to content

Commit cd78176

Browse files
matt2eclaude
andcommitted
fix(navigation): dialogs never become Back/Forward destinations
Follow-up to 35eeda4, which kept "push on open, return on close" for the channel Members dialog. That rule still let Back while the list was open merely dismiss it. Reversed: a dialog is never a history visit. Back always leaves the page the dialog is on, whether or not it is open, and Members is in the chain in neither direction. Enforced centrally so page code cannot push a dialog visit at all: `createNavigationController.open` now writes any target that shares the current visit's page identity (`pageKey`: the parsed target minus a conversation's `panel`) with `replace`, whatever `options.replace` says. The address still carries `panel: "members"` while open, so reload and deep links restore the dialog. `pageKey` lives next to `targetKey` in targets.ts; non-conversation kinds have no presentation field and key as before. `ChannelsPage.setMembersOpen` opens and closes through `navigator.open(..., { replace: true })`; the opener-visit ref and its `returnTo` are gone. `Navigation.open`'s `returnTo` option stays for Settings' `leaveSettings`, which is unchanged: Settings is a multi-section modal where Back between sections is meaningful, and it already keeps a dismissed Settings out of back history. I do not think Settings should change: its sections are destinations in their own right, not presentation on one page. Consequence worth knowing: after Back leaves a channel whose list was open, Forward lands on that same channel visit with Members restored, because the visit's address is what reload and deep links rely on. The dialog never consumes a Back press; it is simply part of the page state Forward and reload bring back. Tests: controller case asserting a panel-only open and close are written in place even with `replace: false` (no forward branch created, Back leaves to the previous page, a different message of the same channel is still a push). `channel-members.spec.mjs` flips to: opening leaves history.length and canGoForward unchanged; Back while open lands on the previous channel; Forward returns to the channel visit; after Close, Back leaves the channel and Forward has nothing beyond it; reload restores Members from the address and Close after reload also replaces. The scoped routed-thread case now asserts Back after a cold dismissal lands on the visit before the conversation was opened. Docs state the final rule. Validation: `tsc --noEmit` clean; biome check on changed files clean; `vitest run src/features/navigation src/app/navigation src/bundled/channels/ChannelsPage src/app/App.profile src/app/Settings src/app/entity-navigation` 18 files, 292 passed. Playwright channel-members.spec.mjs: chromium first run 4 passed / 1 failed on an assertion I had placed behind the open modal (the draft textbox is hidden from role queries while the dialog is up, same ordering mistake as last time, not product behaviour); after moving that assertion past Escape, chromium 5/5 and webkit 5/5. Not exercised: the native desktop app or a human walkthrough. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 35eeda4 commit cd78176

7 files changed

Lines changed: 118 additions & 51 deletions

File tree

‎docs/channels.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -782,14 +782,14 @@ native acceptance.
782782

783783
## Member administration
784784

785-
**Members** has a scoped conversation history visit (`panel: "members"`)
786-
through the host navigation owner. Opening creates a visit; browser Back dismisses
787-
and Forward restores the list. Reload restores the same channel and Members,
788-
including the underlying message/thread address when present. Close, Escape and
789-
outside dismissal return to the visit that opened Members and never create a
790-
visit: Back then leaves the channel, while Forward can still restore the list.
791-
Without that opener in the current chain (reload, deep link), dismissal replaces
792-
the Members visit in place. Profile/DM handoffs dismiss Members without replacing the new
785+
**Members** is presentation on the channel's conversation visit, carried in its
786+
address as `panel: "members"` through the host navigation owner. It is never a
787+
history visit of its own: opening and dismissing (Close, Escape, outside click)
788+
rewrite the current visit in place, so browser Back always leaves the channel,
789+
whether or not the list is open, and Members is never a Back or Forward
790+
destination. Reload and deep links restore the same channel and Members,
791+
including the underlying message/thread address when present.
792+
Profile/DM handoffs dismiss Members without replacing the new
793793
destination, and history traversal never repeats a DM open or membership mutation.
794794
Search, role filters, menus and confirmations are transient, not address data.
795795
Scoped history still requires the original viewer, joined community and current

‎docs/plugin-architecture.md‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,12 +1219,14 @@ optional versioned JSON routes, and account/community-bound conversations.
12191219
Conversation targets may include `panel: "members"` to restore that channel’s
12201220
Members dialog without replacing its channel/message identity. Unknown panel
12211221
values are rejected; this is presentation state, never mutation or confirmation state.
1222-
A dialog may own a visit this way so reload, Forward and deep links restore it,
1223-
but dismissing it must never create a visit. Close it with
1224-
`open(target, { replace: true, returnTo })`, where `returnTo` is the id of the
1225-
visit that opened the dialog: the host traverses back to that visit while it is
1226-
in the current chain and otherwise replaces in place. Without `replace`, a
1227-
missing opener falls back to an ordinary push.
1222+
A dialog is reflected in the address so reload and deep links restore it, but it
1223+
never creates a history visit: the host writes a target that differs from the
1224+
current visit only in `panel` with `replace`, whatever the caller passes, so a
1225+
page cannot push a dialog as a Back/Forward destination and Back always leaves
1226+
the page the dialog is on. Open and close it with `open(target, { replace: true })`.
1227+
`returnTo` names the id of an earlier visit to traverse back to instead of
1228+
opening anew (Settings uses it to leave a multi-section modal); when that visit
1229+
is not in the current chain the target opens as usual.
12281230
The boundary copies, freezes and bounds route data; an address is never an access
12291231
grant. Scoped targets require the original viewer and an already joined community.
12301232
An explicit `scope: null` restores Personal space; omitted page scope leaves the

‎src/bundled/channels/ChannelsPage.tsx‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ function ChannelWorkspace({
238238
const [membersChannel, setMembersChannel] = useState<string>();
239239
const membersTrigger = useRef<HTMLButtonElement>(null);
240240
const membersHeaderTrigger = useRef<HTMLButtonElement>(null);
241-
const membersOpener = useRef<string | undefined>(undefined);
242241
useEffect(() => {
243242
void queries.emoji.ensure();
244243
}, [queries]);
@@ -537,17 +536,11 @@ function ChannelWorkspace({
537536
return;
538537
// A profile keeps this conversation; a DM already owns a different visit.
539538
// Modal cleanup must not overwrite that destination or its exact address.
539+
// Members is presentation on this visit, never a Back/Forward destination:
540+
// the address carries the panel for reload and deep links, written in place.
540541
const { panel: _panel, ...target } = navigation.target;
541-
if (open) {
542-
membersOpener.current = navigation.entryId;
543-
void navigator.open({ ...target, panel: "members" });
544-
return;
545-
}
546-
// Dismissal returns to the opener's visit and never pushes one; a reload or
547-
// deep link has no opener in this chain, so it replaces Members in place.
548-
void navigator.open(target, {
542+
void navigator.open(open ? { ...target, panel: "members" } : target, {
549543
replace: true,
550-
returnTo: membersOpener.current,
551544
});
552545
};
553546
const openMembers = (trigger: HTMLButtonElement) => {

‎src/features/navigation/controller.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,46 @@ describe("navigation attempts over one history driver", () => {
232232
host.dispose();
233233
await expect(third).resolves.toEqual({ status: "cancelled" });
234234
});
235+
it("writes a presentation-only change to the current visit in place, even when asked to push", async () => {
236+
const { host, navigation: nav } = setup();
237+
const conversation: OpenTarget = {
238+
version: 1,
239+
kind: "conversation",
240+
scope: {
241+
viewer: "a".repeat(64),
242+
communityOrigin: "https://relay.example",
243+
},
244+
channelId: "alpha",
245+
};
246+
const members: OpenTarget = { ...conversation, panel: "members" };
247+
void nav.open(settings);
248+
void nav.open(conversation);
249+
const channel = nav.snapshot().entry;
250+
// Opening the dialog is not a visit: the address changes, the chain does not.
251+
const opened = nav.open(members, { replace: false });
252+
expect(nav.snapshot().entry.target).toEqual(members);
253+
expect(nav.snapshot().entry.id).not.toBe(channel.id);
254+
expect(nav.snapshot().canGoForward).toBe(false);
255+
host.complete(nav.snapshot().attempt, { status: "opened" });
256+
await expect(opened).resolves.toEqual({ status: "opened" });
257+
nav.back();
258+
expect(nav.snapshot().entry.target).toEqual(settings);
259+
nav.forward();
260+
expect(nav.snapshot().entry.target).toEqual(members);
261+
// Closing it is not a visit either: Back still leaves the page.
262+
void nav.open(conversation);
263+
expect(nav.snapshot().entry.target).toEqual(conversation);
264+
expect(nav.snapshot().canGoForward).toBe(false);
265+
nav.back();
266+
expect(nav.snapshot().entry.target).toEqual(settings);
267+
nav.forward();
268+
expect(nav.snapshot().entry.target).toEqual(conversation);
269+
expect(nav.snapshot().canGoForward).toBe(false);
270+
// A different page of the same channel is still a new visit.
271+
void nav.open({ ...members, messageId: "b".repeat(64) });
272+
nav.back();
273+
expect(nav.snapshot().entry.target).toEqual(conversation);
274+
});
235275
it("uses driver-initiated traversal and bounds the memory driver without inventing history", () => {
236276
const { navigation: nav, history } = setup(2);
237277
void nav.open(settings);

‎src/features/navigation/controller.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { parseOpenTarget, targetKey, type OpenTarget } from "./targets";
1+
import {
2+
pageKey,
3+
parseOpenTarget,
4+
targetKey,
5+
type OpenTarget,
6+
} from "./targets";
27
import type { NavigationEntry, NavigationHistory } from "./history";
38

49
/**
@@ -262,13 +267,20 @@ export function createNavigationController(
262267
returning = { id: returnTo, resolve };
263268
});
264269
}
270+
const { current, invalidAddress } = history.snapshot();
265271
if (
266-
!history.snapshot().invalidAddress &&
267-
targetKey(target) === targetKey(history.snapshot().current.target)
272+
!invalidAddress &&
273+
targetKey(target) === targetKey(current.target)
268274
)
269275
return start(options?.focus);
270276
openingFocus = options?.focus;
271-
if (options?.replace) history.replace(target);
277+
// Opening or closing a dialog on the current page changes presentation,
278+
// not the visit: write it in place (so reload and deep links restore it)
279+
// and never let a page push a Back/Forward destination for it.
280+
const replace =
281+
options?.replace ||
282+
(!invalidAddress && pageKey(target) === pageKey(current.target));
283+
if (replace) history.replace(target);
272284
else history.push(target);
273285
return active.promise;
274286
} catch {

‎src/features/navigation/targets.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,13 @@ export function parseOpenTarget(input: unknown): OpenTarget {
220220
export function targetKey(target: OpenTarget): string {
221221
return JSON.stringify(parseOpenTarget(target));
222222
}
223+
/**
224+
* What a visit shows, without presentation such as a conversation's `panel`.
225+
* Targets sharing a page key are one visit: a dialog is never a history destination.
226+
*/
227+
export function pageKey(target: OpenTarget): string {
228+
const parsed = parseOpenTarget(target);
229+
if (parsed.kind !== "conversation") return JSON.stringify(parsed);
230+
const { panel: _panel, ...page } = parsed;
231+
return JSON.stringify(page);
232+
}

‎tests/browser/channel-members.spec.mjs‎

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ test("channel members opens from the header, fits each viewport, and returns key
127127

128128
// Native history traversal/reload plus the real channel tab owner cannot be
129129
// represented by a dialog-only jsdom test. No member mutations are performed.
130-
test("Members has a reloadable history visit without replacing channel tabs or drafts", async ({
130+
test("Members is reloadable but never a Back/Forward destination, and keeps channel tabs and drafts", async ({
131131
page,
132132
app,
133133
}) => {
@@ -150,6 +150,9 @@ test("Members has a reloadable history visit without replacing channel tabs or d
150150
exact: true,
151151
});
152152
const entry = () => page.evaluate(() => history.state.buzzNavigationV1.entry);
153+
const canGoForward = () =>
154+
page.evaluate(() => window.fixtureNavigation.snapshot().canGoForward);
155+
const length = () => page.evaluate(() => history.length);
153156
// Give the channel a known predecessor so "Back leaves the channel" is observable.
154157
await page.locator('button[data-channel-id="beta"]').click();
155158
await expect(beta).toBeVisible();
@@ -162,61 +165,65 @@ test("Members has a reloadable history visit without replacing channel tabs or d
162165
.getByRole("tab", { name: "Channel settings", exact: true });
163166
await expect(settings).toHaveAttribute("aria-selected", "true");
164167
const before = await entry();
168+
const chain = await length();
165169
await trigger.click();
166170
const dialog = page.getByRole("dialog", {
167171
name: "Manage members",
168172
exact: true,
169173
});
170174
await expect(dialog.getByRole("searchbox")).toBeFocused();
175+
// Opening writes the panel into the channel's address in place: no new visit.
171176
const members = await entry();
172-
expect(members.id).not.toBe(before.id);
173177
expect(members.target).toEqual({ ...before.target, panel: "members" });
178+
expect(await length()).toBe(chain);
179+
expect(await canGoForward()).toBe(false);
174180
await dialog.getByRole("searchbox").fill("not-persisted");
181+
// Back while Members is open leaves the channel; a dialog never consumes it.
175182
await page.goBack();
183+
await expect(beta).toBeVisible();
176184
await expect(dialog).toHaveCount(0);
177-
expect((await entry()).id).toBe(before.id);
178-
await expect(trigger).toBeFocused();
179-
await expect(composer).toHaveText("Keep this draft");
180-
await expect(settings).toHaveAttribute("aria-selected", "true");
185+
// Forward returns to the channel visit; its address still carries the panel.
181186
await page.goForward();
182187
await expect(dialog.getByRole("searchbox")).toBeFocused();
183188
expect((await entry()).id).toBe(members.id);
184189
await expect(dialog.getByRole("searchbox")).toHaveValue("");
185-
// Explicit dismissal returns to the opener's visit instead of pushing one:
186-
// Back then leaves the channel, while Forward can still restore the list.
190+
expect(await canGoForward()).toBe(false);
191+
// Explicit dismissal rewrites the same visit: Back leaves the channel and
192+
// Members is in the chain in neither direction.
187193
await page.keyboard.press("Escape");
188194
await expect(dialog).toHaveCount(0);
189195
await expect(trigger).toBeFocused();
190-
expect((await entry()).id).toBe(before.id);
196+
expect((await entry()).target).toEqual(before.target);
197+
expect(await length()).toBe(chain);
198+
expect(await canGoForward()).toBe(false);
191199
await expect(composer).toHaveText("Keep this draft");
200+
await expect(settings).toHaveAttribute("aria-selected", "true");
192201
await page.goBack();
193202
await expect(beta).toBeVisible();
194203
await expect(dialog).toHaveCount(0);
195204
await page.goForward();
196205
await expect(composer).toBeVisible();
197-
expect((await entry()).id).toBe(before.id);
198-
await page.goForward();
206+
await expect(dialog).toHaveCount(0);
207+
expect((await entry()).target).toEqual(before.target);
208+
expect(await canGoForward()).toBe(false);
209+
// Reload restores Members from the address.
210+
await trigger.click();
199211
await expect(dialog.getByRole("searchbox")).toBeFocused();
200-
expect((await entry()).id).toBe(members.id);
212+
const reopened = await entry();
201213
await page.reload();
202214
await expect(dialog.getByRole("searchbox")).toBeFocused();
203-
expect((await entry()).id).toBe(members.id);
204-
// A reloaded document has no opener visit to return to, so dismissal replaces
205-
// the Members visit in place rather than creating one.
206-
const length = await page.evaluate(() => history.length);
215+
expect((await entry()).id).toBe(reopened.id);
207216
await page.keyboard.press("Escape");
208217
await expect(dialog).toHaveCount(0);
209218
await expect(trigger).toBeFocused();
210219
// Tabs remain session-owned; reload creates a new relay session. Their disk
211220
// persistence is deliberately not part of the Members route.
212221
await expect(composer).toHaveText("Keep this draft");
213222
expect((await entry()).target).toEqual(before.target);
214-
expect((await entry()).id).not.toBe(members.id);
215-
expect(await page.evaluate(() => history.length)).toBe(length);
223+
expect(await length()).toBe(chain);
216224
await page.goBack();
217-
await expect(composer).toBeVisible();
225+
await expect(beta).toBeVisible();
218226
await expect(dialog).toHaveCount(0);
219-
expect((await entry()).id).toBe(before.id);
220227
});
221228

222229
// Members must not compete with an exact-message reveal for modal focus.
@@ -270,6 +277,9 @@ test.describe("scoped Members history", () => {
270277
}) => {
271278
await page.goto(app.origin);
272279
await openPage(page, "Messages");
280+
const origin = await page.evaluate(
281+
() => history.state.buzzNavigationV1.entry,
282+
);
273283
const target = {
274284
version: 1,
275285
kind: "conversation",
@@ -319,12 +329,12 @@ test.describe("scoped Members history", () => {
319329
.getByRole("region", { name: "Thread messages", exact: true })
320330
.locator(`[data-message-id="${target.messageId}"]`),
321331
).toBeFocused();
322-
// Cold dismissal replaced the Members visit, so Back cannot restore it.
332+
// Members was never a visit: Back leaves the conversation it was shown on.
323333
await page.goBack();
324334
await expect(dialog).toHaveCount(0);
325335
expect(
326-
(await page.evaluate(() => history.state.buzzNavigationV1.entry)).target,
327-
).toEqual(target);
336+
(await page.evaluate(() => history.state.buzzNavigationV1.entry)).id,
337+
).toBe(origin.id);
328338
expect(
329339
await page.evaluate((target) => window.fixtureNavigation.open(target), {
330340
...entry.target,

0 commit comments

Comments
 (0)