Skip to content

WIP - Refactor/state duplicates#273

Closed
mschead wants to merge 2 commits intomainfrom
refactor/state-duplicates
Closed

WIP - Refactor/state duplicates#273
mschead wants to merge 2 commits intomainfrom
refactor/state-duplicates

Conversation

@mschead
Copy link
Copy Markdown
Contributor

@mschead mschead commented Mar 6, 2026

Summary by CodeRabbit

  • Refactor
    • Improved chat mode selection with dedicated ask and agent mode controls.
    • Simplified temporary chat state management using URL parameters.
    • Enhanced mode constraints enforcement—agent mode is automatically disabled when temporary chats are enabled.
    • Streamlined chat state synchronization and persistence.

mschead added 2 commits March 5, 2026 22:56
…y chats

- Replace setChatMode(mode) with selectAskMode() / selectAgentMode();
  enforce free subscription and temporary-chats constraints inside
  selectAgentMode(); expose effectiveChatMode for model persistence.
- Make temporary chats URL source of truth via useSearchParams();
  replace setTemporaryChatsEnabled(bool) with enableTemporaryChats() /
  disableTemporaryChats() that update query via Next router.
- Remove redundant typeof window checks in URL-sync effects.
- Update ChatHeader, ChatInput, ChatModeSelector, ModeSelectorContent,
  SidebarHeader, and chat.tsx to use new APIs; remove ChatInput
  useEffects that forced ask mode (logic lives in GlobalState).

Made-with: Cursor
… state

- Derive chatId and isExistingChat from route (routeChatId); remove
  local chatId/isExistingChat state and URL sync effect. Use stable
  local ref for new-chat id when route has no id.
- On new-chat reset call router.replace("/"); update URL to /c/[id]
  in send handler when sending first message (not in onFinish).
- Clear message queue in selectAskMode and on chatId change (cleanup);
  remove separate clear-when-switching-to-Ask effect.
- Require chatId === routeChatId for isChatNotFound to avoid flash
  during new-chat transition; simplify sandbox init and hasSavedSandboxType.

Made-with: Cursor
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hackerai Error Error Mar 7, 2026 7:24pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c9727a74-4a61-426e-a251-fe933bc3501f

📥 Commits

Reviewing files that changed from the base of the PR and between 18999f9 and aae8ab4.

📒 Files selected for processing (8)
  • app/components/ChatHeader.tsx
  • app/components/ChatInput/ChatInput.tsx
  • app/components/ChatInput/ChatModeSelector.tsx
  • app/components/ChatInput/ModeSelectorMenu/ModeSelectorContent.tsx
  • app/components/SidebarHeader.tsx
  • app/components/chat.tsx
  • app/contexts/GlobalState.tsx
  • app/hooks/useChatHandlers.ts
💤 Files with no reviewable changes (1)
  • app/components/ChatInput/ChatInput.tsx

📝 Walkthrough

Walkthrough

This PR refactors the GlobalState API to replace generic setter functions with specific action functions (selectAskMode/selectAgentMode, enableTemporaryChats/disableTemporaryChats). Temporary chats are now URL-driven, and the chat component logic is simplified by removing redundant state management and effects.

Changes

Cohort / File(s) Summary
Global State Architecture
app/contexts/GlobalState.tsx, app/components/chat.tsx
Major refactoring: replaced setChatMode setter with selectAskMode and selectAgentMode actions; replaced setTemporaryChatsEnabled with enableTemporaryChats and disableTemporaryChats functions. Temporary chats now URL-driven. Chat component simplified: removed local chat ID state management, stale closure helpers, redundant route-sync effects; now derives state from route parameters. Adopted effectiveChatMode to enforce constraints when temporary chats enabled.
Chat Mode Selection UI
app/components/ChatInput/ChatModeSelector.tsx, app/components/ChatInput/ModeSelectorMenu/ModeSelectorContent.tsx
Updated to use new mode-selection actions: selectAskMode and selectAgentMode. Changed ModeSelectorContent prop from setChatMode callback to onSelectAskMode function. Removed ChatMode type import from ModeSelectorContent.
Chat Input Logic
app/components/ChatInput/ChatInput.tsx
Removed two useEffect blocks: one handling auto-switch to "ask" mode for inactive pro plans, another for temporary chats enablement. Removed useEffect import and related state destructuring.
Temporary Chats Management
app/components/ChatHeader.tsx, app/components/SidebarHeader.tsx
Updated to use new API functions enableTemporaryChats and disableTemporaryChats instead of setTemporaryChatsEnabled toggle. Calls now conditionally invoke appropriate function based on current state.
Documentation & Comments
app/hooks/useChatHandlers.ts
Added clarifying comment explaining immediate URL update rationale when sending new messages. No functional behavior changes.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • rossmanko

Poem

🐰 Through URLs now flows the temporary chat,
No more direct toggles—intent-based, that's where it's at!
Ask or Agent, each with their own clear call,
Simpler state, cleaner code—we've fixed it all!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'WIP - Refactor/state duplicates' is vague and generic, using non-descriptive terms that don't convey meaningful information about the specific changes. Replace the generic 'WIP' prefix and vague 'state duplicates' with a clear, specific description of the main change, e.g., 'Replace setChatMode setter with selectAskMode/selectAgentMode actions' or similar.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/state-duplicates

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ross0x01 ross0x01 closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants