mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix(studio): the first edit of a film without ids no longer reloads the preview (#8274)
* test(studio): the first save of a film without ids writes the ids the preview served * fix(studio): the first edit of a film without ids saves the preview's ids, so it does not reload
This commit is contained in:
@@ -698,6 +698,36 @@ describe("a file nothing has stamped yet", () => {
|
||||
it("leaves the file as it was when no element has the id, ids and all", () => {
|
||||
expect(applyPatchByTarget(ON_DISK, { hfId: "hf-gone" }, op)).toBe(ON_DISK);
|
||||
});
|
||||
|
||||
const hfIdOf = (html: string, id: string) =>
|
||||
/data-hf-id="([^"]+)"/.exec(
|
||||
new RegExp(`<[^>]*\\bid="${id}"[^>]*>`).exec(html)?.[0] ?? "",
|
||||
)?.[1] ?? "";
|
||||
|
||||
// fails without the fix: found by its id, the clip was patched into a file left without ids, and a later save
|
||||
// minted ids from the edited file, so they no longer matched the preview's and the preview reloaded.
|
||||
it("writes the ids the preview served, even when the element's own id finds it", () => {
|
||||
const film = `<div data-composition-id="main" data-duration="6"><div id="box" data-start="0" data-duration="3"></div></div>`;
|
||||
const served = ensureHfIds(film);
|
||||
const boxId = hfIdOf(served, "box");
|
||||
expect(boxId).toMatch(/^hf-/);
|
||||
const moved = { type: "attribute", property: "start", value: "0.5" } as const;
|
||||
const saved = applyPatchByTarget(film, { hfId: boxId, id: "box", selector: "#box" }, moved);
|
||||
const ids = (html: string) => [...html.matchAll(/data-hf-id="([^"]+)"/g)].map((m) => m[1]);
|
||||
expect(ids(saved)).toEqual(ids(served));
|
||||
expect(ensureHfIds(saved)).toBe(saved);
|
||||
});
|
||||
|
||||
it("writes a film that already has ids unchanged apart from the edit", () => {
|
||||
const film = ensureHfIds(
|
||||
`<div data-composition-id="main"><div id="box" data-start="0"></div></div>`,
|
||||
);
|
||||
const boxId = hfIdOf(film, "box");
|
||||
const moved = { type: "attribute", property: "start", value: "0.5" } as const;
|
||||
expect(applyPatchByTarget(film, { hfId: boxId, id: "box" }, moved)).toBe(
|
||||
film.replace('data-start="0"', 'data-start="0.5"'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("file names with special characters", () => {
|
||||
|
||||
@@ -279,7 +279,7 @@ function findTagByClass(html: string, target: PatchTarget): TagMatch | null {
|
||||
}
|
||||
|
||||
export function servedSource(html: string, target: PatchTarget): string {
|
||||
if (!target.hfId || findTagByTarget(html, target)) return html;
|
||||
if (!target.hfId || findTagByAttribute(html, "data-hf-id", target.hfId)) return html;
|
||||
const stamped = stampHfIdsInPlace(html);
|
||||
return findTagByTarget(stamped, target) ? stamped : html;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user