fix(native): 跨会话打开不再交给 openTabIn(),改为排队到上屏重放

对"本页从未显示过"的会话调用 openTab/openResource 时,打开会被静默丢弃:
runtime 只在该会话挂载过之后才 adopt 它的 rightbar store,而
openTabIn()/openResourceIn() 对这种会话是静默 no-op(不写、也不回报),
place() 却无条件 return true,于是 entry 永远进不了 pending,
flushPending() 也就永远不会重放它 —— 与模块头注释和指南 §0 承诺的
"目标会话未挂载时排队到上屏重放"相反。

- place() 对非在屏会话不再调用 openTabIn()/openResourceIn(),直接 return
  false 让 entry 入队,由既有 flushPending()(已订阅 session list)在该会话
  上屏时重放;在屏会话的路径不变
- 同步模块头注释与 NativeController 的成员说明(那两个面保留为将来宿主
  返回 boolean 时的接缝,closeIn 仍在用)
- 新增 tests/native-surface-cross-session.spec.ts 锁定该契约

关联 #694
This commit is contained in:
xiaochaZ committed 2026-09-16 23:15:53 +08:00
1 parent 1fcf43ccbe
commit f74b60aa37
2 files changed
+148 -13

No files matched your search

+19 -13
View File
@@ -10,10 +10,11 @@
*
* - the surface exists only while a session's panel is mounted, and the
* service's public face (`ISidebarRight`) writes only into THAT session.
* The controller also carries `openTabIn` / `openResourceIn` /
* `closeIn`, which act on any session whose store the runtime has minted;
* both are probed at call time, and an open for a session that has no
* store yet is QUEUED and replayed when that session comes on screen;
* The controller also carries `openTabIn` / `openResourceIn` / `closeIn`,
* but the two open faces are silent no-ops for a session whose store the
* runtime never minted or adopted — they report nothing back — so an open
* aimed at a session that is not on screen is NOT handed to them: it stays
* QUEUED and is replayed once that session comes on screen;
* - layout state is memory-only, so a queued open is not durable either.
*/
import type { Context } from '../../context-types.ts'
@@ -31,7 +32,12 @@ interface NativeController {
openTab(kind: string, options?: { params?: unknown; revealIfOpened?: boolean }): void
openResource(address: string, options?: { params?: unknown; revealIfOpened?: boolean }): void
close(tabId: string): void
/** Not part of `ISidebarRight`: the concrete controller's per-session writes. */
/**
* Not part of `ISidebarRight`: the concrete controller's per-session writes.
* The two open faces are kept as the seam a boolean-reporting host API would
* plug into, but `place()` deliberately does not use them: they cannot tell
* "written" from "no store adopted yet" (see the module header).
*/
openTabIn?(sessionId: string, kind: string, options?: { params?: unknown; revealIfOpened?: boolean }): void
openResourceIn?(sessionId: string, address: string, options?: { params?: unknown; revealIfOpened?: boolean }): void
closeIn?(sessionId: string, tabId: string): void
@@ -76,10 +82,12 @@ export function createNativeSurface(ctx: Context, records: NativeTabRecords): Na
api.openTab(entry.tabKind, options)
return true
}
if (api.openTabIn !== undefined) {
api.openTabIn(entry.sessionId, entry.tabKind, options)
return true
}
// Do not hand a non-current session's open to openTabIn(): for a session
// whose rightbar store the runtime never adopted (it was not opened since
// this page load) that call is a silent no-op that reports nothing back, so
// trusting it drops the open instead of queueing it as this module
// documents. Leave the entry queued — flushPending() replays it once that
// session comes on screen.
return false
}
const options = {
@@ -90,10 +98,8 @@ export function createNativeSurface(ctx: Context, records: NativeTabRecords): Na
api.openResource(entry.address, options)
return true
}
if (api.openResourceIn !== undefined) {
api.openResourceIn(entry.sessionId, entry.address, options)
return true
}
// Same as the tab branch: a session with no adopted rightbar store makes
// openResourceIn() a silent no-op, so queue instead.
return false
}