Skip to content

Commit 6c0ee41

Browse files
fix(lint): flag autoAlpha on clip elements (#3692)
1 parent c5b7f6a commit 6c0ee41

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

‎packages/lint/src/rules/gsap.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,53 @@ describe("GSAP rules", () => {
481481
expect(finding?.message).toContain("visibility");
482482
});
483483

484+
it("ERRORS when GSAP animates autoAlpha on a clip element", async () => {
485+
const html = `
486+
<html><body>
487+
<div data-composition-id="c1" data-width="1920" data-height="1080">
488+
<div id="incoming" class="clip" data-start="1.01" data-duration="5" data-track-index="1">
489+
<p>Incoming scene</p>
490+
</div>
491+
</div>
492+
<script>
493+
window.__timelines = window.__timelines || {};
494+
const tl = gsap.timeline({ paused: true });
495+
tl.fromTo("#incoming", { autoAlpha: 0 }, { autoAlpha: 1, duration: 0.3 }, 1.01);
496+
window.__timelines["c1"] = tl;
497+
</script>
498+
</body></html>`;
499+
500+
const result = await lintHyperframeHtml(html);
501+
const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
502+
503+
expect(finding).toBeDefined();
504+
expect(finding?.severity).toBe("error");
505+
expect(finding?.message).toContain("autoAlpha");
506+
expect(finding?.fixHint).toContain("child");
507+
});
508+
509+
it("does NOT flag autoAlpha on content inside a clip", async () => {
510+
const html = `
511+
<html><body>
512+
<div data-composition-id="c1" data-width="1920" data-height="1080">
513+
<div id="incoming" class="clip" data-start="1.01" data-duration="5" data-track-index="1">
514+
<p id="content">Incoming scene</p>
515+
</div>
516+
</div>
517+
<script>
518+
window.__timelines = window.__timelines || {};
519+
const tl = gsap.timeline({ paused: true });
520+
tl.fromTo("#content", { autoAlpha: 0 }, { autoAlpha: 1, duration: 0.3 }, 1.01);
521+
window.__timelines["c1"] = tl;
522+
</script>
523+
</body></html>`;
524+
525+
const result = await lintHyperframeHtml(html);
526+
const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
527+
528+
expect(finding).toBeUndefined();
529+
});
530+
484531
it("ERRORS when GSAP animates display on a clip element", async () => {
485532
const html = `
486533
<html><body>

‎packages/lint/src/rules/gsap.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,24 +1365,25 @@ export const gsapRules: LintRule<LintContext>[] = [
13651365
});
13661366
}
13671367

1368-
// gsap_animates_clip_element — only error when GSAP animates visibility/display
1368+
// gsap_animates_clip_element — GSAP must not compete with the framework's
1369+
// clip visibility window. autoAlpha owns visibility as well as opacity.
13691370
for (const win of gsapWindows) {
13701371
const sel = win.targetSelector;
13711372
const clipInfo = clipIds.get(sel) || clipClasses.get(sel);
13721373
if (!clipInfo) continue;
13731374
const conflictingProps = win.properties.filter(
1374-
(p) => p === "visibility" || p === "display",
1375+
(p) => p === "visibility" || p === "display" || p === "autoAlpha",
13751376
);
13761377
if (conflictingProps.length === 0) continue;
13771378
const elDesc = `<${clipInfo.tag}${clipInfo.id ? ` id="${clipInfo.id}"` : ""} class="${clipInfo.classes}">`;
13781379
findings.push({
13791380
code: "gsap_animates_clip_element",
13801381
severity: "error",
1381-
message: `GSAP animation sets ${conflictingProps.join(", ")} on a clip element. Selector "${sel}" resolves to element ${elDesc}. The framework manages clip visibility via ${conflictingProps.join("/")} — do not animate these properties on clip elements.`,
1382+
message: `GSAP animation sets ${conflictingProps.join(", ")} on a clip element. Selector "${sel}" resolves to element ${elDesc}. The framework manages clip visibility, and autoAlpha writes visibility as well as opacity — do not animate these properties on clip elements.`,
13821383
selector: sel,
13831384
elementId: clipInfo.id || undefined,
13841385
fixHint:
1385-
"Remove the visibility/display tween, or move the content into a child <div> and target that instead.",
1386+
"Remove the visibility/display/autoAlpha tween, or move the content into a child <div> and target that instead.",
13861387
snippet: truncateSnippet(win.raw),
13871388
});
13881389
}

0 commit comments

Comments
 (0)