11import React , { useCallback } from 'react' ;
2- import { useNavigate } from 'react-router-dom' ;
2+ import { Link } from 'react-router-dom' ;
33import { QueryKeys } from 'librechat-data-provider' ;
44import { useQueryClient } from '@tanstack/react-query' ;
55import { TooltipAnchor , NewChatIcon , MobileSidebar , Sidebar , Button } from '@librechat/client' ;
@@ -24,7 +24,6 @@ export default function NewChat({
2424 const queryClient = useQueryClient ( ) ;
2525 /** Note: this component needs an explicit index passed if using more than one */
2626 const { newConversation : newConvo } = useNewConvo ( index ) ;
27- const navigate = useNavigate ( ) ;
2827 const localize = useLocalize ( ) ;
2928 const { conversation } = store . useCreateConversationAtom ( index ) ;
3029
@@ -36,21 +35,22 @@ export default function NewChat({
3635 } , 250 ) ;
3736 } , [ toggleNav ] ) ;
3837
39- const clickHandler : React . MouseEventHandler < HTMLButtonElement > = useCallback (
38+ const clickHandler : React . MouseEventHandler < HTMLAnchorElement > = useCallback (
4039 ( e ) => {
41- if ( e . button === 0 && ( e . ctrlKey || e . metaKey ) ) {
42- window . open ( '/c/new' , '_blank' ) ;
40+ // Let browser handle modified/non-left clicks (new tab, context menu, etc.)
41+ if ( e . button !== 0 || e . metaKey || e . ctrlKey || e . shiftKey || e . altKey ) {
4342 return ;
4443 }
44+
45+ e . preventDefault ( ) ;
4546 clearMessagesCache ( queryClient , conversation ?. conversationId ) ;
4647 queryClient . invalidateQueries ( [ QueryKeys . messages ] ) ;
4748 newConvo ( ) ;
48- navigate ( '/c/new' , { state : { focusChat : true } } ) ;
4949 if ( isSmallScreen ) {
5050 toggleNav ( ) ;
5151 }
5252 } ,
53- [ queryClient , conversation , newConvo , navigate , toggleNav , isSmallScreen ] ,
53+ [ queryClient , conversation , newConvo , toggleNav , isSmallScreen ] ,
5454 ) ;
5555
5656 return (
@@ -84,14 +84,16 @@ export default function NewChat({
8484 description = { localize ( 'com_ui_new_chat' ) }
8585 render = {
8686 < Button
87+ asChild
8788 size = "icon"
8889 variant = "outline"
8990 data-testid = "nav-new-chat-button"
9091 aria-label = { localize ( 'com_ui_new_chat' ) }
9192 className = "rounded-full border-none bg-transparent duration-0 hover:bg-surface-active-alt focus-visible:ring-inset focus-visible:ring-black focus-visible:ring-offset-0 dark:focus-visible:ring-white md:rounded-xl"
92- onClick = { clickHandler }
9393 >
94- < NewChatIcon className = "icon-lg text-text-primary" />
94+ < Link to = "/c/new" state = { { focusChat : true } } onClick = { clickHandler } >
95+ < NewChatIcon className = "icon-lg text-text-primary" />
96+ </ Link >
9597 </ Button >
9698 }
9799 />
0 commit comments