Skip to content

Commit 5c0cf9b

Browse files
vanceingallsclaude
andcommitted
fix(core): clear data-hf-id on split clone to prevent dual-match (R7 review)
cloneNode(true) copies all attributes including data-hf-id. Without clearing it, both halves of a split share the same hf-id; the server's findByHfId picks the first match and silently patches the wrong clip. Remove the attribute from the clone so write-back re-mints a fresh id on the next preview load. Adds a test: splitElementInHtml — hfId clone isolation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent be23752 commit 5c0cf9b

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

packages/core/src/studio-api/helpers/sourceMutation.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
removeElementFromHtml,
44
patchElementInHtml,
55
probeElementInSource,
6+
splitElementInHtml,
67
} from "./sourceMutation.js";
78

89
describe("removeElementFromHtml", () => {
@@ -455,3 +456,14 @@ describe("T7 — data-hf-id targeting (spec for R1)", () => {
455456
expect(html).toContain('data-hf-id="hf-a1b2"');
456457
});
457458
});
459+
460+
describe("splitElementInHtml — hfId clone isolation", () => {
461+
it("does not copy data-hf-id to the cloned second half", () => {
462+
const source = `<html><body><div data-composition-id="root"><div id="clip1" class="clip" data-start="0" data-duration="10" data-hf-id="hf-abc123"></div></div></body></html>`;
463+
const { html, matched } = splitElementInHtml(source, { id: "clip1" }, 5, "clip2");
464+
465+
expect(matched).toBe(true);
466+
const occurrences = (html.match(/data-hf-id="hf-abc123"/g) ?? []).length;
467+
expect(occurrences).toBe(1);
468+
});
469+
});

packages/core/src/studio-api/helpers/sourceMutation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ export function splitElementInHtml(
275275

276276
const clone = el.cloneNode(true) as HTMLElement;
277277
clone.setAttribute("id", newId);
278+
clone.removeAttribute("data-hf-id");
278279
clone.setAttribute("data-start", String(Math.round(splitTime * 1000) / 1000));
279280
clone.setAttribute("data-duration", String(Math.round(secondDuration * 1000) / 1000));
280281

0 commit comments

Comments
 (0)