@@ -76,14 +76,17 @@ export interface UseDomEditCommitsParams {
7676 target : HTMLElement ,
7777 options ?: { preferClipAncestor ?: boolean } ,
7878 ) => Promise < DomEditSelection | null > ;
79- /** Stage 7 Step 3b: called after a successful server-side element patch. */
80- onDomEditPersisted ?: ( selection : DomEditSelection , operations : PatchOperation [ ] ) => void ;
79+ /** Resync the in-memory SDK session after a SERVER-side write (NOT the SDK
80+ * path, whose session is already current) so a later SDK edit doesn't
81+ * serialize the pre-write doc and revert the server's change. */
82+ forceReloadSdkSession ?: ( ) => void ;
8183 /** Stage 7 Step 3c: called before the server-side patch path; returns true if SDK handled it. */
8284 onTrySdkPersist ?: (
8385 selection : DomEditSelection ,
8486 operations : PatchOperation [ ] ,
8587 originalContent : string ,
8688 targetPath : string ,
89+ options ?: { label ?: string ; coalesceKey ?: string ; skipRefresh ?: boolean } ,
8790 ) => Promise < boolean > ;
8891 /** Stage 7 §3.1: called before the server-side delete path; returns true if SDK handled it. */
8992 onTrySdkDelete ?: ( hfId : string , originalContent : string , targetPath : string ) => Promise < boolean > ;
@@ -107,7 +110,7 @@ export function useDomEditCommits({
107110 clearDomSelection,
108111 refreshDomEditSelectionFromPreview,
109112 buildDomSelectionFromTarget,
110- onDomEditPersisted ,
113+ forceReloadSdkSession ,
111114 onTrySdkPersist,
112115 onTrySdkDelete,
113116} : UseDomEditCommitsParams ) {
@@ -157,11 +160,20 @@ export function useDomEditCommits({
157160 throw new Error ( `Missing file contents for ${ targetPath } ` ) ;
158161 }
159162 if ( options ?. shouldSave && ! options . shouldSave ( ) ) return ;
163+ // Skip the SDK path when prepareContent is set (e.g. @font-face injection
164+ // for a custom font): sdkCutoverPersist serializes only the patched DOM
165+ // and would drop the injected content. Let the server path run prepareContent.
160166 if (
161167 onTrySdkPersist &&
162- ( await onTrySdkPersist ( selection , operations , originalContent , targetPath ) )
168+ ! options ?. prepareContent &&
169+ ( await onTrySdkPersist ( selection , operations , originalContent , targetPath , {
170+ label : options ?. label ,
171+ coalesceKey : options ?. coalesceKey ,
172+ skipRefresh : options ?. skipRefresh ,
173+ } ) )
163174 ) {
164- onDomEditPersisted ?.( selection , operations ) ;
175+ // SDK handled it — its in-memory doc is already current, so do NOT
176+ // forceReload (that would echo-reload the session we just wrote).
165177 return ;
166178 }
167179 const patchTarget = buildDomEditPatchTarget ( selection ) ;
@@ -234,7 +246,7 @@ export function useDomEditCommits({
234246 coalesceKey : options ?. coalesceKey ,
235247 files : { [ targetPath ] : { before : originalContent , after : finalContent } } ,
236248 } ) ;
237- onDomEditPersisted ?.( selection , operations ) ;
249+ forceReloadSdkSession ?.( ) ;
238250
239251 if ( ! options ?. skipRefresh ) {
240252 reloadPreview ( ) ;
@@ -248,7 +260,7 @@ export function useDomEditCommits({
248260 domEditSaveTimestampRef ,
249261 reloadPreview ,
250262 showToast ,
251- onDomEditPersisted ,
263+ forceReloadSdkSession ,
252264 onTrySdkPersist ,
253265 ] ,
254266 ) ;
@@ -310,6 +322,7 @@ export function useDomEditCommits({
310322 reloadPreview,
311323 clearDomSelection,
312324 onTrySdkDelete,
325+ forceReloadSdkSession,
313326 commitPositionPatchToHtml,
314327 } ) ;
315328
0 commit comments