@@ -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(
393394const dispatch = useDispatch ( ) ;
394395const [ prevComp , setPrevComp ] = useState < Comp > ( ) ;
395396const [ prevJsonStr , setPrevJsonStr ] = useState < string > ( ) ;
397+ const [ prevQueryId , setPrevQueryId ] = useState < string > ( ) ;
398+ const queryId = query ?. id ;
396399
397400useEffect ( ( ) => {
398- if ( ! comp || comp === prevComp || ! query || ! comp ?. children . query . children . id . getView ( ) ) {
401+ if ( ! comp || comp === prevComp ) {
399402return ;
400403}
404+
401405const curJson = comp . toJsonValue ( ) ;
402406const 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+ }
403425if ( prevJsonStr === curJsonStr ) {
404426return ;
405427}
428+
406429// the first time is a normal change, the latter is the manual update
407430if ( prevComp ) {
408431query . name = comp . children . query . children . name . getView ( ) ;
@@ -411,5 +434,6 @@ function useSaveQueryLibrary(
411434}
412435setPrevComp ( comp ) ;
413436setPrevJsonStr ( curJsonStr ) ;
414- } , [ comp , query , prevComp , prevJsonStr , dispatch ] ) ;
437+ setPrevQueryId ( queryId ) ;
438+ } , [ comp , queryId , dispatch ] ) ;
415439}