Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(agent-sidebar): keep the profile entry visible while workspace access loads (#21333)

Nekoff5391f8687e
diff --git a/src/features/AgentSidebar/Header/Nav.test.tsx b/src/features/AgentSidebar/Header/Nav.test.tsx
index f43a9514644..1490b8490d3 100644
--- a/src/features/AgentSidebar/Header/Nav.test.tsx
+++ b/src/features/AgentSidebar/Header/Nav.test.tsx
@@ -22,8 +22,9 @@ const labMock = vi.hoisted(() => ({
enableSelfLearning: true,
enableGoals: true,
}));
+const resourceAccessMock = vi.hoisted(() => ({ canEditResource: true, isAccessResolved: true }));
vi.mock('@/features/ResourcePermission/useResourceAccess', () => ({
- useResourceAccess: () => ({ canEditResource: true, isAccessResolved: true }),
+ useResourceAccess: () => resourceAccessMock,
}));
vi.mock('react-router', async () => {
@@ -140,6 +141,8 @@ describe('Agent sidebar header nav', () => {
permissionMock.edit_own_content = true;
labMock.enableSelfLearning = true;
labMock.enableGoals = true;
+ resourceAccessMock.canEditResource = true;
+ resourceAccessMock.isAccessResolved = true;
useParamsMock.mockReturnValue({ aid: 'agt_eH4zL98zBx5u', topicId: 'tpc_2FCHvjS7d4CA' });
});
@@ -280,4 +283,29 @@ describe('Agent sidebar header nav', () => {
expect(labels.indexOf('tab.profile')).toBeLessThan(labels.indexOf('goalList.title'));
expect(labels.indexOf('goalList.title')).toBeLessThan(labels.indexOf('tab.tasks'));
});
+
+ // r1018 issue 7: in a workspace, `useResourceAccess` reports the edit check as
+ // permissive while `getGeneralAccess` is in flight (`canEditResource: true`,
+ // `isAccessResolved: false`). The profile entry must not vanish for that
+ // window — it used to disappear right after opening an agent and only
+ // reappear once the batched request returned.
+ it('keeps the profile entry visible while workspace resource access is still loading', () => {
+ resourceAccessMock.canEditResource = true;
+ resourceAccessMock.isAccessResolved = false;
+ usePathnameMock.mockReturnValue('/agent/agt_eH4zL98zBx5u');
+
+ render(<Nav />);
+
+ expect(screen.getByRole('button', { name: 'tab.profile' })).toBeInTheDocument();
+ });
+
+ it('hides the profile entry once the server confirms the member cannot edit the agent', () => {
+ resourceAccessMock.canEditResource = false;
+ resourceAccessMock.isAccessResolved = true;
+ usePathnameMock.mockReturnValue('/agent/agt_eH4zL98zBx5u');
+
+ render(<Nav />);
+
+ expect(screen.queryByRole('button', { name: 'tab.profile' })).toBeNull();
+ });
});
diff --git a/src/features/AgentSidebar/Header/Nav.tsx b/src/features/AgentSidebar/Header/Nav.tsx
index 978bb46ad10..f57fb501cf0 100644
--- a/src/features/AgentSidebar/Header/Nav.tsx
+++ b/src/features/AgentSidebar/Header/Nav.tsx
@@ -53,10 +53,14 @@ const Nav = memo(() => {
const router = useQueryRoute();
const { allowed: canCreateTopic } = usePermission('create_content');
const { allowed: canEditContent } = usePermission('edit_own_content');
- const { canEditResource, isAccessResolved } = useResourceAccess('agent', agentId);
+ const { canEditResource } = useResourceAccess('agent', agentId);
const { isAgentEditable } = useServerConfigStore(featureFlagsSelectors);
const toggleCommandMenu = useGlobalStore((s) => s.toggleCommandMenu);
- const hideProfile = !isAgentEditable || !isAccessResolved || !canEditContent || !canEditResource;
+ // Only a server-confirmed edit denial hides the entry. `canEditResource` stays
+ // permissive while workspace access is loading, so the entry no longer drops
+ // out each time an agent is opened; the profile page itself is still guarded by
+ // `ResourceConfigAccessGate`.
+ const hideProfile = !isAgentEditable || !canEditContent || !canEditResource;
const switchTopic = useChatStore((s) => s.switchTopic);
const [openNewTopicOrSaveTopic] = useChatStore((s) => [s.openNewTopicOrSaveTopic]);
const isNewTopicSendInFlight = useChatStore(topicSelectors.isNewTopicSendInFlight);