Skip to content

Commit 4616b88

Browse files
fix(sdk): addGsapTween resolves scoped id to bare leaf; validateOp checks target exists
- handleAddGsapTween: strip host prefix for scoped ids (hf-host/hf-leaf → selector [data-hf-id="hf-leaf"]) — DOM element carries only the leaf part - validateOp addGsapTween: call resolveScoped to surface E_TARGET_NOT_FOUND before the GSAP script checks (previously can() returned ok for missing targets) - patches.ts pathToKey: remove dead ?? null (decodePathSegment never returns undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Miguel Ángel <miguel07alm@protonmail.com>
1 parent 3ec2adc commit 4616b88

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

packages/sdk/src/engine/mutate.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,11 @@ function handleAddGsapTween(
597597
? ((tween.toProperties ?? {}) as Record<string, number | string>)
598598
: ((tween.toProperties ?? tween.properties ?? {}) as Record<string, number | string>);
599599

600+
// Scoped ids like "hf-host/hf-leaf" must use the bare leaf id in the GSAP
601+
// selector — only the leaf part is written as data-hf-id on the DOM element.
602+
const bareTarget = target.includes("/") ? (target.split("/").at(-1) ?? target) : target;
600603
const animation: Omit<GsapAnimation, "id"> = {
601-
targetSelector: `[data-hf-id="${target}"]`,
604+
targetSelector: `[data-hf-id="${bareTarget}"]`,
602605
method: tween.method,
603606
position: tween.position ?? 0,
604607
...(tween.duration !== undefined ? { duration: tween.duration } : {}),
@@ -792,6 +795,12 @@ export function validateOp(parsed: ParsedDocument, op: EditOp): CanResult {
792795
return CAN_OK;
793796
case "addGsapTween":
794797
case "addLabel": {
798+
if (op.type === "addGsapTween" && resolveScoped(parsed.document, op.target) === null)
799+
return canErr(
800+
"E_TARGET_NOT_FOUND",
801+
`Element not found: ${op.target}.`,
802+
"Verify the id against comp.getElements() or comp.find().",
803+
);
795804
const script = getGsapScript(parsed.document);
796805
if (!script)
797806
return canErr(

packages/sdk/src/engine/patches.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function pathToKey(path: string): string | null {
118118

119119
// /elements/{id} (whole element) → "{id}"
120120
const elemMatch = /^\/elements\/([^/]+)$/.exec(path);
121-
if (elemMatch) return decodePathSegment(elemMatch[1]!) ?? null;
121+
if (elemMatch) return decodePathSegment(elemMatch[1]!);
122122

123123
// /variables/{id} → "var.{id}"
124124
const varMatch = /^\/variables\/(.+)$/.exec(path);

0 commit comments

Comments
 (0)