fix(ui): derive tab selection from the url instead of syncing to it
My diagnosis in the previous commit was wrong. The component root was not being replaced by a reactive re-render: the client router owns popstate and swaps the whole page shell on back and forward, which discards component state entirely. Every mechanism that tried to push state into the component from outside was therefore doomed -- clicking a tab, announcing an event, tracking the last applied value. In url mode the query parameter is now simply the source of truth, read where the selection is computed. Whatever render happens next produces the right tab, with no listener to lose and nothing to keep in step. This deletes the runtime tab sync entirely -- 1590 bytes -- and fixes the back/forward cases that were previously broken. Verified in the showcase: click writes the url, two backs and two forwards each land on the right tab, and a ?tab= deep link opens on it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2678,6 +2678,16 @@ test("tabs in url mode declare the query parameter they sync to", async () => {
|
||||
const root = dom.querySelector(".wire-tabs") as HTMLElement;
|
||||
expect(root.getAttribute("data-mode")).toBe("url");
|
||||
expect(root.getAttribute("data-param")).toBe("tab");
|
||||
|
||||
/*
|
||||
* In url mode the query parameter is the source of truth rather than
|
||||
* component state. The client router owns popstate and swaps the whole page
|
||||
* on back and forward, discarding component state, so the selection has to
|
||||
* fall out of the URL for history to work at all.
|
||||
*/
|
||||
const source2 = readFileSync(uiComponentPath("Tabs"), "utf8");
|
||||
expect(source2).toContain("URLSearchParams(window.location.search)");
|
||||
expect(source2).toContain("history.pushState");
|
||||
});
|
||||
|
||||
test("tabs vertical orientation switches the roving axis", async () => {
|
||||
|
||||
Reference in New Issue
Block a user