@@ -44,6 +44,20 @@ import { PluginStatusEnum } from '@fastgpt/global/core/plugin/type';
4444import { useConfirm } from '@fastgpt/web/hooks/useConfirm' ;
4545import { useToast } from '@fastgpt/web/hooks/useToast' ;
4646
47+ type QueryValue = string | string [ ] | undefined ;
48+ type QueryRecord = Record < string , QueryValue > ;
49+
50+ const getComparableQueryValue = ( value : QueryValue ) =>
51+ Array . isArray ( value ) ? value . join ( '\0' ) : ( value ?? '' ) ;
52+
53+ const isSameQuery = ( currentQuery : QueryRecord , nextQuery : QueryRecord ) => {
54+ const queryKeys = new Set ( [ ...Object . keys ( currentQuery ) , ...Object . keys ( nextQuery ) ] ) ;
55+
56+ return Array . from ( queryKeys ) . every (
57+ ( key ) => getComparableQueryValue ( currentQuery [ key ] ) === getComparableQueryValue ( nextQuery [ key ] )
58+ ) ;
59+ } ;
60+
4761// Custom hook for managing URL search params
4862const useSearchParams = ( ) => {
4963 const router = useRouter ( ) ;
@@ -88,6 +102,9 @@ const useSearchParams = () => {
88102 delete nextQuery . source ;
89103 }
90104
105+ // router.replace 会触发全局 NProgress。query 没变时直接跳过,避免浅路由空转循环。
106+ if ( isSameQuery ( router . query , nextQuery ) ) return ;
107+
91108 router . replace (
92109 {
93110 pathname : router . pathname ,
@@ -178,14 +195,14 @@ const ToolkitMarketplace = ({ marketplaceUrl }: { marketplaceUrl: string }) => {
178195
179196 // Control search box expansion based on focus and input value
180197 const [ isSearchExpanded , setIsSearchExpanded ] = useState ( false ) ;
181- const [ isFocused , setIsFocused ] = useState ( false ) ;
182- useEffect ( ( ) => {
183- if ( isFocused ) {
184- setIsSearchExpanded ( true ) ;
185- } else if ( ! inputValue ) {
198+ const handleSearchFocus = useCallback ( ( ) => {
199+ setIsSearchExpanded ( true ) ;
200+ } , [ ] ) ;
201+ const handleSearchBlur = useCallback ( ( ) => {
202+ if ( ! inputValue ) {
186203 setIsSearchExpanded ( false ) ;
187204 }
188- } , [ isFocused , inputValue ] ) ;
205+ } , [ inputValue ] ) ;
189206
190207 const {
191208 data : tools ,
@@ -681,8 +698,8 @@ const ToolkitMarketplace = ({ marketplaceUrl }: { marketplaceUrl: string }) => {
681698 placeholder = { t ( 'app:toolkit_marketplace_search_placeholder' ) }
682699 value = { inputValue }
683700 onChange = { ( e ) => setInputValue ( e . target . value ) }
684- onFocus = { ( ) => setIsFocused ( true ) }
685- onBlur = { ( ) => setIsFocused ( false ) }
701+ onFocus = { handleSearchFocus }
702+ onBlur = { handleSearchBlur }
686703 />
687704 { inputValue && (
688705 < MyIcon
@@ -793,8 +810,8 @@ const ToolkitMarketplace = ({ marketplaceUrl }: { marketplaceUrl: string }) => {
793810 placeholder = { t ( 'app:toolkit_marketplace_search_placeholder' ) }
794811 value = { inputValue }
795812 onChange = { ( e ) => setInputValue ( e . target . value ) }
796- onFocus = { ( ) => setIsFocused ( true ) }
797- onBlur = { ( ) => setIsFocused ( false ) }
813+ onFocus = { handleSearchFocus }
814+ onBlur = { handleSearchBlur }
798815 />
799816 </ InputGroup >
800817 </ Box >
0 commit comments