Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): the company sidebar shows the organization the page is on (#824)

lmlihengac9ca76890df
diff --git a/changelog/unreleased/2026-10-12-company-last-org-adoption.md b/changelog/unreleased/2026-10-12-company-last-org-adoption.md
new file mode 100644
index 00000000..86590dc2
--- /dev/null
+++ b/changelog/unreleased/2026-10-12-company-last-org-adoption.md
@@ -0,0 +1,25 @@
+# The company sidebar shows the organization the page is on
+
+- **Date:** 2026-10-12
+- **Type:** fix
+- **Scope:** `web`
+
+[中文版](2026-10-12-company-last-org-adoption.zh.md)
+
+Ported from upstream PenguinHarness (#824, commit `aedeac7e`).
+
+Opening an organization's page in company mode could leave the sidebar — its desks, its
+channels — on the organization opened *last time*, so the page said one company and the
+sidebar listed another's employees, and switching organizations looked as if the new one had
+no Sessions.
+
+## Details
+
+- The shell adopts the organization last opened (a stored preference) when no route names
+ one. That decision was taken on the values of the render that scheduled it; an organization
+ route sets the current organization in its own effect, which runs first in the same commit,
+ so the shell still saw "none" and adopted the stored one over the route's.
+- The decision is now a store method, `adoptLastOrg`, that reads the store as it is at that
+ moment: a route's choice stands, and the stored organization is adopted only while nothing
+ names one.
+- No API, wire format or stored data changes.
diff --git a/changelog/unreleased/2026-10-12-company-last-org-adoption.zh.md b/changelog/unreleased/2026-10-12-company-last-org-adoption.zh.md
new file mode 100644
index 00000000..a3131de9
--- /dev/null
+++ b/changelog/unreleased/2026-10-12-company-last-org-adoption.zh.md
@@ -0,0 +1,21 @@
+# 公司侧栏显示的是当前页面所在的组织
+
+- **Date:** 2026-10-12
+- **Type:** fix
+- **Scope:** `web`
+
+[English](2026-10-12-company-last-org-adoption.md)
+
+移植自上游 PenguinHarness(#824,提交 `aedeac7e`)。
+
+公司模式下打开某个组织的页面时,侧栏(工位、频道)可能停留在**上一次**打开的组织上:页面写着一家
+公司,侧栏列的却是另一家的员工,切换组织时看起来像新组织没有任何 Session。
+
+## 细节
+
+- 没有路由指明组织时,shell 会采用上次打开的组织(存在偏好设置里)。这个判断用的是发起它的那次
+ 渲染里的值;而组织路由在自己的 effect 里设置当前组织,同一次提交里它先执行,shell 看到的仍是
+ 「没有」,于是用存储的组织盖掉了路由指定的组织。
+- 现在这个判断是 store 的方法 `adoptLastOrg`,按当下的 store 状态决定:路由的选择优先,只在没有任何
+ 组织被指定时才采用存储的那个。
+- 接口、线上格式与已存数据都没有变化。
diff --git a/packages/web/src/state/company.tsx b/packages/web/src/state/company.tsx
index c0fd291d..f59cfb85 100644
--- a/packages/web/src/state/company.tsx
+++ b/packages/web/src/state/company.tsx
@@ -210,6 +210,8 @@ interface CompanyStoreState {
setPersonalEnabled: (enabled: boolean) => void;
applyPrefs: (prefs: UiPrefs) => void;
setCurrentOrg: (key: string | null) => void;
+ /** The last organization opened becomes the current one, unless a route already set one. */
+ adoptLastOrg: () => void;
reloadChannels: (projectId: string, orgId: string) => Promise<void>;
markChannelRead: (channelId: string) => void;
reloadOrganizations: (projectIds: readonly string[]) => Promise<void>;
@@ -358,6 +360,16 @@ export function createCompanyStore(options: { serverEnabled?: boolean } = {}) {
storeWorkMode(get().workMode);
},
+ /**
+ * Makes the last organization opened the current one — only while none is: a route that
+ * names an organization has the last word, whatever this shell remembered.
+ */
+ adoptLastOrg: () => {
+ const { currentOrgKey, lastOrgKey } = get();
+ if (currentOrgKey !== null || lastOrgKey === null) return;
+ get().setCurrentOrg(lastOrgKey);
+ },
+
setCurrentOrg: (key) => {
const prev = get();
if (key === prev.currentOrgKey) return;
@@ -781,8 +793,11 @@ export function CompanyProvider({ children }: { children: ReactNode }) {
const { workMode, personalEnabled, lastOrgKey } = state;
useEffect(() => {
if (!serverEnabled || !personalEnabled || workMode !== "company") return;
- if (currentOrgKey !== null || lastOrgKey === null) return;
- store.getState().setCurrentOrg(lastOrgKey);
+ // Decided on the store's state NOW, not on this render's: an organization route's own
+ // effect (OrgLayout, a child, so it runs first in the same commit) has often just set the
+ // current organization, and this render still shows it as null. Adopting the stored one on
+ // that stale view put the sidebar on the last organization while the page showed another.
+ store.getState().adoptLastOrg();
}, [store, serverEnabled, personalEnabled, workMode, currentOrgKey, lastOrgKey]);
useEffect(
diff --git a/packages/web/test/company-store.test.ts b/packages/web/test/company-store.test.ts
index 9b09053b..38874724 100644
--- a/packages/web/test/company-store.test.ts
+++ b/packages/web/test/company-store.test.ts
@@ -168,6 +168,24 @@ describe("company store event routing", () => {
expect(store.getState().orgChartError).toBeNull();
});
+ it("adopts the last organization only while none is current — a route's choice stands", () => {
+ // The shell adopts the organization last opened when nothing names one. An organization
+ // route names one in its own effect, which runs before the shell's in the same commit, so
+ // the shell must read the store as it is by then, not as the render saw it.
+ const store = createCompanyStore();
+ store.setState({ lastOrgKey: "p1/acme" });
+ store.getState().adoptLastOrg();
+ expect(store.getState().currentOrgKey).toBe("p1/acme");
+
+ store.setState({ currentOrgKey: "p1/other", lastOrgKey: "p1/acme", orgChart: null });
+ store.getState().adoptLastOrg();
+ expect(store.getState().currentOrgKey).toBe("p1/other");
+
+ store.setState({ currentOrgKey: null, lastOrgKey: null });
+ store.getState().adoptLastOrg();
+ expect(store.getState().currentOrgKey).toBeNull();
+ });
+
it("bumps the version of each family, and the organization list for the ones that change a summary", () => {
const store = createCompanyStore();
store.getState().applyCompanyEvent(