11import equal from "fast-deep-equal" ;
2- import { type ReactNode , useCallback , useMemo , useRef , useState } from "react" ;
2+ import {
3+ type ReactNode ,
4+ useCallback ,
5+ useEffect ,
6+ useMemo ,
7+ useRef ,
8+ useState ,
9+ } from "react" ;
310
411import { type UndoRedo , useUndoRedo } from "@/hooks/useUndoRedo" ;
12+ import { generateDigest } from "@/services/componentService" ;
513import { loadPipelineByName } from "@/services/pipelineService" ;
614import { USER_PIPELINES_LIST_NAME } from "@/utils/constants" ;
715import { prepareComponentRefForEditor } from "@/utils/prepareComponentRefForEditor" ;
@@ -42,6 +50,7 @@ interface ComponentSpecContextType {
4250 graphSpec : GraphSpec ;
4351 currentGraphSpec : GraphSpec ;
4452 currentSubgraphSpec : ComponentSpec ;
53+ digest : string ;
4554 isLoading : boolean ;
4655 isValid : boolean ;
4756 errors : string [ ] ;
@@ -73,6 +82,7 @@ export const ComponentSpecProvider = ({
7382 const [ componentSpec , setComponentSpec ] = useState < ComponentSpec > (
7483 spec ?? EMPTY_GRAPH_COMPONENT_SPEC ,
7584 ) ;
85+ const [ digest , setDigest ] = useState < string > ( "" ) ;
7686
7787 const [ isLoading , setIsLoading ] = useState ( ! ! spec ) ;
7888
@@ -105,6 +115,24 @@ export const ComponentSpecProvider = ({
105115 [ currentSubgraphSpec , isRootSubgraph ] ,
106116 ) ;
107117
118+ useEffect ( ( ) => {
119+ let isCancelled = false ;
120+
121+ const computeDigest = async ( ) => {
122+ const text = componentSpecToYaml ( componentSpec ) ;
123+ const newDigest = await generateDigest ( text ) ;
124+ if ( ! isCancelled ) {
125+ setDigest ( newDigest ) ;
126+ }
127+ } ;
128+
129+ computeDigest ( ) ;
130+
131+ return ( ) => {
132+ isCancelled = true ;
133+ } ;
134+ } , [ componentSpec ] ) ;
135+
108136 const clearComponentSpec = useCallback ( ( ) => {
109137 setComponentSpec ( EMPTY_GRAPH_COMPONENT_SPEC ) ;
110138 setIsLoading ( false ) ;
@@ -226,6 +254,7 @@ export const ComponentSpecProvider = ({
226254 graphSpec,
227255 currentGraphSpec,
228256 currentSubgraphSpec,
257+ digest,
229258 isLoading,
230259 isValid,
231260 errors,
@@ -247,6 +276,7 @@ export const ComponentSpecProvider = ({
247276 graphSpec ,
248277 currentGraphSpec ,
249278 currentSubgraphSpec ,
279+ digest ,
250280 isLoading ,
251281 isValid ,
252282 errors ,
0 commit comments