@@ -15,8 +15,11 @@ export const Preview = ({ config, data, error, loading, project }) => {
1515 const lsf = useRef ( null ) ;
1616 const resolvingEditor = useMemo ( loadDependencies ) ;
1717 const rootRef = useRef ( ) ;
18+ const projectRef = useRef ( project ) ;
1819 const api = useAPI ( ) ;
1920
21+ projectRef . current = project ;
22+
2023 const currentTask = useMemo ( ( ) => {
2124 return {
2225 id : 1 ,
@@ -37,7 +40,7 @@ export const Preview = ({ config, data, error, loading, project }) => {
3740 // return same url if http(s)
3841 if ( [ "http:" , "https:" ] . includes ( parsedUrl . protocol ) ) return url ;
3942
40- const projectId = project . id ;
43+ const projectId = projectRef . current . id ;
4144
4245 const fileuri = btoa ( url ) ;
4346
@@ -101,18 +104,7 @@ export const Preview = ({ config, data, error, loading, project }) => {
101104 lsf . current = ls ;
102105 } ) ;
103106 }
104-
105- return ( ) => {
106- if ( lsf . current ) {
107- console . info ( "Destroying LSF" ) ;
108- // there is can be weird error from LSF, but we can just skip it for now
109- try {
110- lsf . current . destroy ( ) ;
111- } catch ( e ) { }
112- lsf . current = null ;
113- }
114- } ;
115- } , [ initLabelStudio , currentConfig , currentTask ] ) ;
107+ } , [ currentConfig , currentTask ] ) ;
116108
117109 useEffect ( ( ) => {
118110 if ( lsf . current ?. store ) {
@@ -138,6 +130,19 @@ export const Preview = ({ config, data, error, loading, project }) => {
138130 }
139131 } , [ currentTask ] ) ;
140132
133+ useEffect ( ( ) => {
134+ return ( ) => {
135+ if ( lsf . current ) {
136+ console . info ( "Destroying LSF" ) ;
137+ // there can be weird error from LSF, but we can just skip it for now
138+ try {
139+ lsf . current . destroy ( ) ;
140+ } catch ( e ) { }
141+ lsf . current = null ;
142+ }
143+ } ;
144+ } , [ ] ) ;
145+
141146 return (
142147 < div className = { configClass . elem ( "preview" ) } >
143148 < h3 > UI Preview</ h3 >
0 commit comments