33import type { AnyDocumentId , DocHandle , Repo } from '@automerge/automerge-repo' ;
44import { useRepo } from '@automerge/automerge-repo-react-hooks' ;
55import { Entity , Utils } from '@graphprotocol/hypergraph' ;
6- import { type DocumentContent , subscribeToDocumentChanges } from '@graphprotocol/hypergraph/Entity' ;
6+ import type { DocumentContent } from '@graphprotocol/hypergraph/Entity' ;
77import * as Schema from 'effect/Schema' ;
88import { type ReactNode , createContext , useContext , useEffect , useRef , useState , useSyncExternalStore } from 'react' ;
99
@@ -12,7 +12,6 @@ export type HypergraphContext = {
1212 repo : Repo ;
1313 id : AnyDocumentId ;
1414 handle : DocHandle < Entity . DocumentContent > ;
15- unsubscribeChangeListener : ( ) => void ;
1615} ;
1716
1817export const HypergraphReactContext = createContext < HypergraphContext | undefined > ( undefined ) ;
@@ -32,28 +31,17 @@ export function HypergraphProvider({ space, children }: { space: string; childre
3231
3332 let current = ref . current ;
3433 if ( current === undefined || space !== current . space || repo !== current . repo ) {
35- current ?. unsubscribeChangeListener ( ) ; // unsubscribe from the previous space when switching to a new space
36-
3734 const id = Utils . idToAutomergeId ( space ) as AnyDocumentId ;
3835 const handle = repo . find < DocumentContent > ( id ) ;
39- const unsubscribeChangeListener = subscribeToDocumentChanges ( handle ) ;
4036
4137 current = ref . current = {
4238 space,
4339 repo,
4440 id,
4541 handle,
46- unsubscribeChangeListener,
4742 } ;
4843 }
4944
50- // biome-ignore lint/correctness/useExhaustiveDependencies: no need for dependencies as the unsubscribe is called from the ref
51- useEffect ( ( ) => {
52- return ( ) => {
53- current ?. unsubscribeChangeListener ( ) ; // unsubscribe from the previous space when the component unmounts
54- } ;
55- } , [ ] ) ;
56-
5745 return < HypergraphReactContext . Provider value = { current } > { children } </ HypergraphReactContext . Provider > ;
5846}
5947
0 commit comments