mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
fix(studio): a GSAP read that throws still leaves the layer as it was (#8759)
This commit is contained in:
@@ -308,6 +308,21 @@ describe("withoutGsapTakeover", () => {
|
||||
expect(title._gsap!.origin).toBe(origin);
|
||||
});
|
||||
|
||||
it("puts back what a read changed when the read throws", () => {
|
||||
document.body.innerHTML = `<h1 id="title" style="translate: 0 -200px">Title</h1>`;
|
||||
const title = document.getElementById("title")! as HTMLElement & Cached;
|
||||
title._gsap = { x: 0 };
|
||||
expect(() =>
|
||||
withoutGsapTakeover(title, () => {
|
||||
title.style.translate = "none";
|
||||
title._gsap!.renderTransform = () => {};
|
||||
throw new Error("GSAP failed");
|
||||
}),
|
||||
).toThrow("GSAP failed");
|
||||
expect(title.getAttribute("style")).toBe("translate: 0 -200px");
|
||||
expect(title._gsap).toEqual({ x: 0 });
|
||||
});
|
||||
|
||||
it("drops a GSAP cache the read created", () => {
|
||||
document.body.innerHTML = `<h1 id="title">Title</h1>`;
|
||||
const title = document.getElementById("title")! as HTMLElement & Cached;
|
||||
|
||||
@@ -198,10 +198,12 @@ export function withoutGsapTakeover<T>(element: Element, read: () => T): T {
|
||||
const cache = host._gsap;
|
||||
const restoreCache = cache ? keptFields(cache) : () => Reflect.deleteProperty(host, "_gsap");
|
||||
const restoreAttributes = keptAttributes(element);
|
||||
const value = read();
|
||||
restoreAttributes();
|
||||
restoreCache();
|
||||
return value;
|
||||
try {
|
||||
return read();
|
||||
} finally {
|
||||
restoreAttributes();
|
||||
restoreCache();
|
||||
}
|
||||
}
|
||||
|
||||
export type EditingGestureBase = {
|
||||
|
||||
@@ -78,8 +78,8 @@ export const composeTranslate = (original: string, x: string, y: string): string
|
||||
* the edit translate is written. GSAP folds a CSS `translate` it sees at an
|
||||
* element's first parse into its cached transform (losing it per-axis on
|
||||
* absolute tweens); once the cache exists, later tweens and positioned set()s
|
||||
* reuse it and never read the translate again. gsap.getProperty parses
|
||||
* without mutating the element. Best-effort — absent or failing GSAP is fine.
|
||||
* reuse it and never read the translate again. The parse also writes the
|
||||
* folded transform onto the element. Best-effort — absent or failing GSAP is fine.
|
||||
*/
|
||||
const primeGsapTransformCache = (el: StylableElement): void => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user