@@ -14,18 +14,19 @@ import { SyncApi } from "../client";
1414// How many steps we will attempt to sync in one request.
1515const MAX_STEPS_SYNC = 1000 ;
1616const SNAPSHOT_DEBOUNCE_MS = 1000 ;
17- const log : typeof console . log = console . debug ;
1817
1918type UseSyncOptions = {
2019 onSyncError ?: ( error : Error ) => void ;
2120 snapshotDebounceMs ?: number ;
21+ debug ?: boolean ;
2222} ;
2323
2424export function useTiptapSync (
2525 syncApi : SyncApi ,
2626 id : string ,
2727 opts ?: UseSyncOptions
2828) {
29+ const log : typeof console . log = opts ?. debug ? console . debug : ( ) => { } ;
2930 const convex = useConvex ( ) ;
3031 const initial = useInitialState ( syncApi , id ) ;
3132 const extension = useMemo ( ( ) => {
@@ -105,6 +106,7 @@ export function syncExtension(
105106 initialState : InitialState ,
106107 opts ?: UseSyncOptions
107108) {
109+ const log : typeof console . log = opts ?. debug ? console . debug : ( ) => { } ;
108110 let snapshotTimer : NodeJS . Timeout | undefined ;
109111 const trySubmitSnapshot = ( version : number , content : string ) => {
110112 if ( snapshotTimer ) {
@@ -148,7 +150,15 @@ export function syncExtension(
148150
149151 try {
150152 if (
151- await doSync ( editor , convex , syncApi , id , serverVersion , initialState )
153+ await doSync (
154+ editor ,
155+ convex ,
156+ syncApi ,
157+ id ,
158+ serverVersion ,
159+ initialState ,
160+ opts ?. debug
161+ )
152162 ) {
153163 const version = collab . getVersion ( editor . state ) ;
154164 const content = JSON . stringify ( editor . state . doc . toJSON ( ) ) ;
@@ -219,8 +229,10 @@ async function doSync(
219229 syncApi : SyncApi ,
220230 id : string ,
221231 serverVersion : number | null ,
222- initialState : InitialState
232+ initialState : InitialState ,
233+ debug ?: boolean
223234) {
235+ const log : typeof console . log = debug ? console . debug : ( ) => { } ;
224236 if ( serverVersion === null ) {
225237 if ( initialState . initialVersion <= 1 ) {
226238 // This is a new document, so we can create it on the server.
0 commit comments