fix(app): resolve target session lineage outside router transition (#34838)

This commit is contained in:
Luke Parker 2026-07-02 14:24:39 +10:00 committed by GitHub
commit 39dfbb53d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 243 additions and 35 deletions

View file

@ -1,13 +1,6 @@
import { describe, expect, test } from "bun:test"
import { ServerConnection } from "@/context/server"
import {
legacySessionHref,
legacySessionServer,
requireServerKey,
rootSession,
selectSessionLineage,
sessionHref,
} from "./session-route"
import { legacySessionHref, legacySessionServer, requireServerKey, rootSession, sessionHref } from "./session-route"
describe("session routes", () => {
test("uses the unique persisted server for a legacy session route", () => {
@ -75,10 +68,4 @@ describe("session routes", () => {
expect(rootSession(sessions.child, async (id) => sessions[id]!)).rejects.toThrow("Session parent cycle: child")
})
test("ignores a resolved lineage retained from the previous route", () => {
const previous = { session: { id: "A" }, root: { id: "A" } }
expect(selectSessionLineage("B", undefined, previous)).toBeUndefined()
})
})

View file

@ -27,15 +27,6 @@ export function legacySessionServer(
type SessionParent = { id: string; parentID?: string }
export function selectSessionLineage<T extends { session: { id: string } }>(
sessionID: string,
cached: T | undefined,
resolved: T | undefined,
) {
if (cached?.session.id === sessionID) return cached
if (resolved?.session.id === sessionID) return resolved
}
export async function rootSession<T extends SessionParent>(session: T, get: (sessionID: string) => Promise<T>) {
const seen = new Set([session.id])
let current = session