LibreChat/client/src/components
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
..
Agents 📐 style: Resolve Stale Active Sidebar Panel and Favorites Row Height (#12366) 2026-03-23 13:33:26 -04:00
Artifacts 🧩 feat: Redesign Tool Call UI with Contextual Icons, Smart Grouping, and Rich Output Rendering (#12163) 2026-03-25 12:31:39 -04:00
Audio ️ fix: Accessibility, UI consistency, dialog & avatar refactors (#9975) 2025-10-07 14:12:49 -04:00
Auth 🪃 fix: Prevent Recursive Login Redirect Loop (#11964) 2026-02-26 16:10:14 -05:00
Banners 🧠 style: Expanded Thinking footer, Banner links, and Copy Thoughts accessibility (#11142) 2025-12-29 13:49:18 -05:00
Bookmarks 🪄 refactor: UI Polish and Admin Dialog Unification (#11108) 2025-12-28 11:01:25 -05:00
Chat 🪝 fix: Safe Hook Fallbacks for Tool-Call Components in Search Route (#12423) 2026-03-26 16:40:37 -04:00
Conversations 📐 style: Resolve Stale Active Sidebar Panel and Favorites Row Height (#12366) 2026-03-23 13:33:26 -04:00
Endpoints 🎞️ refactor: Image Rendering with Preview Caching and Layout Reservation (#12114) 2026-03-06 19:09:52 -05:00
Files 🔇 fix: Hide Button Icons from Screen Readers (#10776) 2025-12-11 16:35:17 -05:00
Input 🪦 refactor: Remove Legacy Code (#10533) 2025-12-11 16:36:12 -05:00
MCP fix: Resolve Agent Provider Endpoint Type for File Upload Support (#12117) 2026-03-07 10:45:43 -05:00
MCPUIResource 🪝 fix: Safe Hook Fallbacks for Tool-Call Components in Search Route (#12423) 2026-03-26 16:40:37 -04:00
Messages 🧩 feat: Redesign Tool Call UI with Contextual Icons, Smart Grouping, and Rich Output Rendering (#12163) 2026-03-25 12:31:39 -04:00
Nav 🧩 feat: Redesign Tool Call UI with Contextual Icons, Smart Grouping, and Rich Output Rendering (#12163) 2026-03-25 12:31:39 -04:00
OAuth 🪟 feat: DataTable update + Various UI enhancements (#9698) 2025-12-11 16:39:06 -05:00
Plugins/Store 💎 fix: Gemini Image Gen Tool Vertex AI Auth and File Storage (#11923) 2026-02-24 08:21:02 -05:00
Prompts 📁 refactor: Prompts UI (#11570) 2026-03-22 16:56:22 -04:00
Share 🔄 refactor: Migrate to react-resizable-panels v4 with Artifacts Header polish (#12356) 2026-03-22 02:21:27 -04:00
SharePoint 🎨 style: Theming in SharePointPickerDialog, PrincipalAvatar, and PeoplePickerSearchItem 2025-08-13 16:24:23 -04:00
Sharing 🔧 refactor: Permission handling for Resource Sharing (#11283) 2026-01-10 14:02:56 -05:00
SidePanel 📐 style: Resolve Stale Active Sidebar Panel and Favorites Row Height (#12366) 2026-03-23 13:33:26 -04:00
System feat: Prevent Screen Sleep During Response Generation (#10597) 2025-11-21 09:14:32 -05:00
Tools ♻️ refactor: On-demand MCP connections: remove proactive reconnect, default to available (#11839) 2026-02-17 22:33:57 -05:00
ui 📁 refactor: Prompts UI (#11570) 2026-03-22 16:56:22 -04:00
UnifiedSidebar 📐 style: Resolve Stale Active Sidebar Panel and Favorites Row Height (#12366) 2026-03-23 13:33:26 -04:00
Web 🧩 feat: Redesign Tool Call UI with Contextual Icons, Smart Grouping, and Rich Output Rendering (#12163) 2026-03-25 12:31:39 -04:00
index.ts 🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety 2025-08-13 16:24:20 -04:00