Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/app/src/pages/collab/session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,35 @@ function CollabSessionInner(props: { me: Me }) {
void collab.setTyping(Boolean(data.typing))
return
}

// Native session switched inside the iframe (e.g. opencode's
// cross-session "go to session" popup). Swap the whole collab page —
// including the participant sidebar — to the collab session that owns
// that native session, so the left panel matches the conversation shown
// on the right.
if (data.type === "opencode:collab-session-changed") {
const nativeId = typeof data.sessionId === "string" ? data.sessionId : ""
if (!nativeId) return
// Already showing this native session → nothing to do (also breaks the
// post-navigation echo: the freshly-loaded iframe re-announces its id).
if (nativeId === collab.session()?.sessionId) return
void (async () => {
try {
const res = await fetch("/collab/session")
if (!res.ok) return
const list = (await res.json()) as Array<{ id: string; sessionId?: string | null }>
const target = list.find((s) => s.sessionId === nativeId)
if (target && target.id !== collab.session()?.id) {
// Full page nav so CollabProvider remounts with the new session
// (fresh participants + SSE) — same pattern as the Collab pill.
window.location.href = `/collab/${target.id}`
}
} catch {
/* best-effort — leave the page as-is if the lookup fails */
}
})()
return
}
}
window.addEventListener("message", onIframeMessage)
onCleanup(() => window.removeEventListener("message", onIframeMessage))
Expand Down
24 changes: 24 additions & 0 deletions packages/app/src/pages/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ export default function Layout(props: ParentProps) {
let dialogDead = false

const params = useParams()

// Collab embed: when the iframe's active native session changes — e.g. via
// opencode's lower-right "go to session" cross-session popup — tell the
// parent collab page so it can swap to the matching collab session and
// refresh the participant sidebar. `params.id` is the native session id;
// `defer` skips the initial mount (the parent is already on the right
// session then) and prevents an echo loop after the parent navigates.
if (isCollabEmbed()) {
createEffect(
on(
() => params.id,
(sessionId) => {
if (!sessionId) return
try {
window.parent.postMessage({ type: "opencode:collab-session-changed", sessionId }, window.location.origin)
} catch {
/* same-origin postMessage shouldn't throw; ignore if it does */
}
},
{ defer: true },
),
)
}

const globalSDK = useGlobalSDK()
const globalSync = useGlobalSync()
const layout = useLayout()
Expand Down
Loading