Skip to content

Commit 7d2cd55

Browse files
fix(studio): wire onTrySdkPersist to sdkCutoverPersist (cutover was unwired)
Stage 7 s7.5 removed the feature flag and declared cutover 'always-on', but onTrySdkPersist was never actually passed to useDomEditCommits — the sdkCutoverPersist function was dead code in production. Thread sdkSession through useDomEditSession params, build the onTrySdkPersist closure there (all CutoverDeps are already in scope), and pass sdkSession from App.tsx. Style/text/attribute/html-attribute commits now route through SDK dispatch instead of the server patch path. Co-authored-by: Miguel Ángel <miguel07alm@protonmail.com>
1 parent 4ee174e commit 7d2cd55

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

packages/studio/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export function StudioApp() {
302302
openSourceForSelection: fileManager.openSourceForSelection,
303303
selectSidebarTab: selectSidebarTabStable,
304304
getSidebarTab: getSidebarTabStable,
305+
sdkSession: sdkHandle.session,
305306
});
306307
domEditSelectionBridgeRef.current = domEditSession.domEditSelection;
307308
clearDomSelectionRef.current = domEditSession.clearDomSelection;

packages/studio/src/hooks/useDomEditCommits.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ export interface UseDomEditCommitsParams {
7777
onDomEditPersisted?: (selection: DomEditSelection, operations: PatchOperation[]) => void;
7878
/** Stage 7 Step 3b: called after a successful server-side element delete. */
7979
onElementDeleted?: (selection: DomEditSelection) => void;
80+
/** Stage 7 Step 3c: called before the server-side patch path; returns true if SDK handled it. */
81+
onTrySdkPersist?: (
82+
selection: DomEditSelection,
83+
operations: PatchOperation[],
84+
originalContent: string,
85+
targetPath: string,
86+
) => Promise<boolean>;
8087
}
8188

8289
export function useDomEditCommits({
@@ -99,6 +106,7 @@ export function useDomEditCommits({
99106
buildDomSelectionFromTarget,
100107
onDomEditPersisted,
101108
onElementDeleted,
109+
onTrySdkPersist,
102110
}: UseDomEditCommitsParams) {
103111
const resolveImportedFontAsset = useCallback(
104112
(fontFamilyValue: string): ImportedFontAsset | null => {
@@ -149,6 +157,18 @@ export function useDomEditCommits({
149157

150158
if (options?.shouldSave && !options.shouldSave()) return;
151159

160+
// Skip the SDK path when prepareContent is set (e.g. @font-face injection
161+
// for a custom font): sdkCutoverPersist serializes only the patched DOM
162+
// and would drop the injected content. Let the server path run prepareContent.
163+
if (
164+
onTrySdkPersist &&
165+
!options?.prepareContent &&
166+
(await onTrySdkPersist(selection, operations, originalContent, targetPath))
167+
) {
168+
// SDK handled it — its in-memory doc is already current.
169+
return;
170+
}
171+
152172
const patchTarget = buildDomEditPatchTarget(selection);
153173
const patchBody = { target: patchTarget, operations };
154174
const unsafeFields = findUnsafeDomPatchValues(patchBody);
@@ -235,6 +255,7 @@ export function useDomEditCommits({
235255
reloadPreview,
236256
showToast,
237257
onDomEditPersisted,
258+
onTrySdkPersist,
238259
],
239260
);
240261

packages/studio/src/hooks/useDomEditSession.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { EditHistoryKind } from "../utils/editHistory";
44
import type { RightPanelTab } from "../utils/studioHelpers";
55
import type { PatchTarget } from "../utils/sourcePatcher";
66
import type { SidebarTab } from "../components/sidebar/LeftSidebar";
7+
import type { Composition } from "@hyperframes/sdk";
8+
import { sdkCutoverPersist } from "../utils/sdkCutover";
79
import { useAskAgentModal } from "./useAskAgentModal";
810
import { useDomSelection } from "./useDomSelection";
911
import { usePreviewInteraction } from "./usePreviewInteraction";
@@ -58,6 +60,7 @@ export interface UseDomEditSessionParams {
5860
openSourceForSelection?: (sourceFile: string, target: PatchTarget) => void;
5961
selectSidebarTab?: (tab: SidebarTab) => void;
6062
getSidebarTab?: () => SidebarTab;
63+
sdkSession?: Composition | null;
6164
}
6265

6366
// ── Hook ──
@@ -96,6 +99,7 @@ export function useDomEditSession({
9699
openSourceForSelection,
97100
selectSidebarTab,
98101
getSidebarTab,
102+
sdkSession,
99103
}: UseDomEditSessionParams) {
100104
void _setRefreshKey;
101105
void _readProjectFile;
@@ -228,6 +232,15 @@ export function useDomEditSession({
228232
clearDomSelection,
229233
refreshDomEditSelectionFromPreview,
230234
buildDomSelectionFromTarget,
235+
onTrySdkPersist: sdkSession
236+
? (selection, operations, originalContent, targetPath) =>
237+
sdkCutoverPersist(selection, operations, originalContent, targetPath, sdkSession, {
238+
editHistory,
239+
writeProjectFile,
240+
reloadPreview,
241+
domEditSaveTimestampRef,
242+
})
243+
: undefined,
231244
});
232245

233246
// ── Wiring: selection sync, GSAP cache, preview sync, selection handlers ──

0 commit comments

Comments
 (0)