@@ -47,6 +47,7 @@ import { registryDataSourcePlugin } from "constants/queryConstants";
4747import { messageInstance } from "lowcoder-design/src/components/GlobalInstances" ;
4848import { Helmet } from "react-helmet" ;
4949import { fetchQLPaginationByOrg } from "@lowcoder-ee/util/pagination/axios" ;
50+ import { isEmpty } from "lodash" ;
5051
5152const Wrapper = styled . div `
5253 display: flex;
@@ -393,16 +394,38 @@ function useSaveQueryLibrary(
393394 const dispatch = useDispatch ( ) ;
394395 const [ prevComp , setPrevComp ] = useState < Comp > ( ) ;
395396 const [ prevJsonStr , setPrevJsonStr ] = useState < string > ( ) ;
397+ const [ prevQueryId , setPrevQueryId ] = useState < string > ( ) ;
398+ const queryId = query ?. id ;
396399
397400 useEffect ( ( ) => {
398- if ( ! comp || comp === prevComp || ! query || ! comp ?. children . query . children . id . getView ( ) ) {
401+ if ( ! comp || comp === prevComp ) {
399402 return ;
400403 }
404+
401405 const curJson = comp . toJsonValue ( ) ;
402406 const curJsonStr = JSON . stringify ( curJson ) ;
407+
408+ if ( isEmpty ( curJson ?. query ?. comp ) ) {
409+ return ;
410+ }
411+ if ( ! Boolean ( prevQueryId ) && Boolean ( queryId ) ) {
412+ setPrevComp ( comp ) ;
413+ setPrevJsonStr ( curJsonStr ) ;
414+ return setPrevQueryId ( queryId ) ;
415+ }
416+ if ( prevQueryId !== queryId ) {
417+ setPrevComp ( comp ) ;
418+ setPrevJsonStr ( curJsonStr ) ;
419+ return setPrevQueryId ( queryId ) ;
420+ }
421+ if ( ! Boolean ( prevJsonStr ) && Boolean ( curJsonStr ) ) {
422+ setPrevComp ( comp )
423+ return setPrevJsonStr ( curJsonStr ) ;
424+ }
403425 if ( prevJsonStr === curJsonStr ) {
404426 return ;
405427 }
428+
406429 // the first time is a normal change, the latter is the manual update
407430 if ( prevComp ) {
408431 query . name = comp . children . query . children . name . getView ( ) ;
@@ -411,5 +434,6 @@ function useSaveQueryLibrary(
411434 }
412435 setPrevComp ( comp ) ;
413436 setPrevJsonStr ( curJsonStr ) ;
414- } , [ comp , query , prevComp , prevJsonStr , dispatch ] ) ;
437+ setPrevQueryId ( queryId ) ;
438+ } , [ comp , queryId , dispatch ] ) ;
415439}
0 commit comments