LibreChat/client/src/Providers
Danny Avila 083042e56c
🪝 fix: Safe Hook Fallbacks for Tool-Call Components in Search Route (#12423)
* fix: add useOptionalMessagesOperations hook for context-safe message operations

Add a variant of useMessagesOperations that returns no-op functions
when MessagesViewProvider is absent instead of throwing, enabling
shared components to render safely outside the chat route.

* fix: use optional message operations in ToolCallInfo and UIResourceCarousel

Switch ToolCallInfo and UIResourceCarousel from useMessagesOperations
to useOptionalMessagesOperations so they no longer crash when rendered
in the /search route, which lacks MessagesViewProvider.

* fix: update test mocks to use useOptionalMessagesOperations

* fix: consolidate noops and narrow useMemo dependency in useOptionalMessagesOperations

- Replace three noop variants (noopAsync, noopReturn, noop) with a single
  `const noop = () => undefined` that correctly returns void/undefined
- Destructure individual fields from context before the useMemo so the
  dependency array tracks stable operation references, not the full
  context object (avoiding unnecessary re-renders on unrelated state changes)
- Add useOptionalMessagesConversation for components that need conversation
  data outside MessagesViewProvider

* fix: use optional hooks in MCPUIResource components to prevent search crash

MCPUIResource and MCPUIResourceCarousel render inside Markdown prose and
can appear in the /search route. Switch them from the strict
useMessagesOperations/useMessagesConversation hooks to the optional
variants that return safe defaults when MessagesViewProvider is absent.

* test: update test mocks for optional hook renames

* fix: update ToolCallInfo and UIResourceCarousel test mocks to useOptionalMessagesOperations

* fix: use optional message operations in useConversationUIResources

useConversationUIResources internally called the strict
useMessagesOperations(), which still threw when MCPUIResource rendered
outside MessagesViewProvider. Switch to useOptionalMessagesOperations
so the entire MCPUIResource render chain is safe in the /search route.

* style: fix import order per project conventions

* fix: replace as-unknown-as casts with typed NOOP_OPS stubs

- Define OptionalMessagesOps type and NOOP_OPS constant with properly
  typed no-op functions, eliminating all `as unknown as T` casts
- Use conversationId directly from useOptionalMessagesConversation
  instead of re-deriving it from conversation object
- Update JSDoc to reflect search route support

* test: add no-provider regression tests for optional message hooks

Verify useOptionalMessagesOperations and useOptionalMessagesConversation
return safe defaults when rendered outside MessagesViewProvider, covering
the core crash path this PR fixes.
2026-03-26 16:40:37 -04:00
..
__tests__ 🪝 fix: Safe Hook Fallbacks for Tool-Call Components in Search Route (#12423) 2026-03-26 16:40:37 -04:00
ActivePanelContext.tsx 📐 style: Resolve Stale Active Sidebar Panel and Favorites Row Height (#12366) 2026-03-23 13:33:26 -04:00
AddedChatContext.tsx ⏸ refactor: Improve UX for Parallel Streams (Multi-Convo) (#11096) 2025-12-25 01:43:54 -05:00
AgentPanelContext.tsx 🏗️ feat: Dynamic MCP Server Infrastructure with Access Control (#10787) 2025-12-11 16:38:37 -05:00
AgentsContext.tsx feat: Agent Panel UI Enhancements (#7800) 2025-06-13 15:47:41 -04:00
AgentsMapContext.tsx 🚧 chore: merge latest dev build to main repo (#3844) 2024-08-31 16:33:51 -04:00
AnnouncerContext.tsx v0.7.5-rc2 (#3976) 2024-09-10 19:00:27 -04:00
ArtifactContext.tsx 🚀 feat: Artifact Editing & Downloads (#5428) 2025-01-23 18:19:04 -05:00
ArtifactsContext.tsx refactor: Optimize Message Re-renders (#12097) 2026-03-06 00:03:32 -05:00
AssistantsContext.tsx feat: Assistants API, General File Support, Side Panel, File Explorer (#1696) 2024-02-13 20:42:27 -05:00
AssistantsMapContext.tsx feat: Assistants API, General File Support, Side Panel, File Explorer (#1696) 2024-02-13 20:42:27 -05:00
BadgeRowContext.tsx 🗂️ refactor: Artifacts via Model Specs & Scope Badge Persistence by Spec Context (#11796) 2026-02-14 13:56:50 -05:00
BookmarkContext.tsx 🔖 feat: Conversation Bookmarks (#3344) 2024-07-29 10:45:59 -04:00
ChatContext.tsx 🎨 refactor: Redesign Sidebar with Unified Icon Strip Layout (#12013) 2026-03-22 01:15:20 -04:00
ChatFormContext.tsx 🗨️ feat: Prompts (#3131) 2024-06-20 20:24:32 -04:00
CodeBlockContext.tsx 🚀 feat: Artifact Editing & Downloads (#5428) 2025-01-23 18:19:04 -05:00
CustomFormContext.tsx 🗨️ feat: Prompts (#3131) 2024-06-20 20:24:32 -04:00
DashboardContext.tsx 🗨️ feat: Prompts (#3131) 2024-06-20 20:24:32 -04:00
DragDropContext.tsx fix: Resolve Agent Provider Endpoint Type for File Upload Support (#12117) 2026-03-07 10:45:43 -05:00
EditorContext.tsx feat: Artifact Management Enhancements, Version Control, and UI Refinements (#10318) 2025-11-12 13:32:47 -05:00
FileMapContext.tsx feat: Assistants API, General File Support, Side Panel, File Explorer (#1696) 2024-02-13 20:42:27 -05:00
index.ts 🎨 refactor: Redesign Sidebar with Unified Icon Strip Layout (#12013) 2026-03-22 01:15:20 -04:00
MessageContext.tsx 🎋 refactor: Improve Message UI State Handling (#9678) 2025-09-17 13:07:56 -04:00
MessagesViewContext.tsx 🪝 fix: Safe Hook Fallbacks for Tool-Call Components in Search Route (#12423) 2026-03-26 16:40:37 -04:00
PromptGroupsContext.tsx 📁 refactor: Prompts UI (#11570) 2026-03-22 16:56:22 -04:00
SearchContext.tsx 🔎 feat: Native Web Search with Citation References (#7516) 2025-05-23 17:40:40 -04:00
SetConvoContext.tsx ♻️ refactor: Logout UX, Improved State Teardown, & Remove Unused Code (#5292) 2025-01-12 12:57:10 -05:00
ShareContext.tsx 🚀 feat: Shared Links (#2772) 2024-05-17 18:13:32 -04:00
ToolCallsMapContext.tsx 🎉 feat: Code Interpreter API and Agents Release (#4860) 2024-12-04 15:48:13 -05:00