fix: defer AI chat loading until AI tab opens#3956
fix: defer AI chat loading until AI tab opens#3956ahmedhesham6 wants to merge 1 commit intosuperplanehq:mainfrom
Conversation
What changed: - defer loading AI chat sessions and messages until the AI Builder tab is opened - preserve loaded AI chat state when switching between Components and AI Builder - reset AI chat state when the canvas changes - add regression tests covering lazy loading, tab reopen behavior, and canvas changes Why: - avoid unnecessary agent connection attempts during sidebar render when the agent is not configured - prevent the noisy console error reported in issue superplanehq#3837 How: - gate the AI session and conversation effects behind a hasOpenedAiTab flag and showAiBuilderTab - clear sidebar AI state only when the canvas changes - add focused sidebar tests for the affected state transitions Related issues: - Refs superplanehq#3837 Test plan: - cd web_src && npx eslint src/ui/BuildingBlocksSidebar/index.tsx src/ui/BuildingBlocksSidebar/index.spec.tsx - cd web_src && npx prettier --check src/ui/BuildingBlocksSidebar/index.tsx src/ui/BuildingBlocksSidebar/index.spec.tsx - cd web_src && npm run test:run -- src/ui/BuildingBlocksSidebar/index.spec.tsx - make check.build.ui Signed-off-by: Ahmed Hesham Abdelkader <23265119+ahmedhesham6@users.noreply.github.com>
|
👋 Commands for maintainers:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 06e4f19. Configure here.
| cancelled = true; | ||
| }; | ||
| }, [canvasId, organizationId]); | ||
| }, [canvasId, hasOpenedAiTab, organizationId, showAiBuilderTab]); |
There was a problem hiding this comment.
Stale state triggers unnecessary API calls on canvas change
Low Severity
When canvasId changes while hasOpenedAiTab is true, the canvas-reset effect (line 429) and the session/conversation loading effects (lines 458, 500) run in the same React commit. The loading effects see the stale hasOpenedAiTab = true from the previous render — the batched setHasOpenedAiTab(false) from the reset effect hasn't committed yet. This causes loadChatSessions and potentially loadChatConversation to fire unnecessary API calls that are subsequently cancelled on the next render. This contradicts the PR's goal of avoiding unnecessary requests when the AI tab hasn't been opened for the current canvas.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 06e4f19. Configure here.


What changed:
Why:
How:
Related issues:
Test plan: