@@ -73,14 +73,17 @@ export interface UseDomEditCommitsParams {
7373 target : HTMLElement ,
7474 options ?: { preferClipAncestor ?: boolean } ,
7575 ) => Promise < DomEditSelection | null > ;
76- /** Stage 7 Step 3b: called after a successful server-side element patch. */
77- onDomEditPersisted ?: ( selection : DomEditSelection , operations : PatchOperation [ ] ) => void ;
76+ /** Resync the in-memory SDK session after a SERVER-side write (NOT the SDK
77+ * path, whose session is already current) so a later SDK edit doesn't
78+ * serialize the pre-write doc and revert the server's change. */
79+ forceReloadSdkSession ?: ( ) => void ;
7880 /** Stage 7 Step 3c: called before the server-side patch path; returns true if SDK handled it. */
7981 onTrySdkPersist ?: (
8082 selection : DomEditSelection ,
8183 operations : PatchOperation [ ] ,
8284 originalContent : string ,
8385 targetPath : string ,
86+ options ?: { label ?: string ; coalesceKey ?: string ; skipRefresh ?: boolean } ,
8487 ) => Promise < boolean > ;
8588 /** Stage 7 §3.1: called before the server-side delete path; returns true if SDK handled it. */
8689 onTrySdkDelete ?: ( hfId : string , originalContent : string , targetPath : string ) => Promise < boolean > ;
@@ -104,7 +107,7 @@ export function useDomEditCommits({
104107 clearDomSelection,
105108 refreshDomEditSelectionFromPreview,
106109 buildDomSelectionFromTarget,
107- onDomEditPersisted ,
110+ forceReloadSdkSession ,
108111 onTrySdkPersist,
109112 onTrySdkDelete,
110113} : UseDomEditCommitsParams ) {
@@ -156,7 +159,22 @@ export function useDomEditCommits({
156159 }
157160
158161 if ( options ?. shouldSave && ! options . shouldSave ( ) ) return ;
159-
162+ // Skip the SDK path when prepareContent is set (e.g. @font-face injection
163+ // for a custom font): sdkCutoverPersist serializes only the patched DOM
164+ // and would drop the injected content. Let the server path run prepareContent.
165+ if (
166+ onTrySdkPersist &&
167+ ! options ?. prepareContent &&
168+ ( await onTrySdkPersist ( selection , operations , originalContent , targetPath , {
169+ label : options ?. label ,
170+ coalesceKey : options ?. coalesceKey ,
171+ skipRefresh : options ?. skipRefresh ,
172+ } ) )
173+ ) {
174+ // SDK handled it — its in-memory doc is already current, so do NOT
175+ // forceReload (that would echo-reload the session we just wrote).
176+ return ;
177+ }
160178 const patchTarget = buildDomEditPatchTarget ( selection ) ;
161179 const patchBody = { target : patchTarget , operations } ;
162180 const unsafeFields = findUnsafeDomPatchValues ( patchBody ) ;
@@ -228,7 +246,7 @@ export function useDomEditCommits({
228246 coalesceKey : options ?. coalesceKey ,
229247 files : { [ targetPath ] : { before : originalContent , after : finalContent } } ,
230248 } ) ;
231- onDomEditPersisted ?.( selection , operations ) ;
249+ forceReloadSdkSession ?.( ) ;
232250
233251 if ( ! options ?. skipRefresh ) {
234252 reloadPreview ( ) ;
@@ -242,7 +260,8 @@ export function useDomEditCommits({
242260 domEditSaveTimestampRef ,
243261 reloadPreview ,
244262 showToast ,
245- onDomEditPersisted ,
263+ forceReloadSdkSession ,
264+ onTrySdkPersist ,
246265 ] ,
247266 ) ;
248267
@@ -304,6 +323,7 @@ export function useDomEditCommits({
304323 reloadPreview,
305324 clearDomSelection,
306325 onTrySdkDelete,
326+ forceReloadSdkSession,
307327 commitPositionPatchToHtml,
308328 onElementDeleted,
309329 } ) ;
0 commit comments