Skip to content

fix(core): splitElementInHtml data-end + text-content inner wrapper#1273

Closed
vanceingalls wants to merge 3 commits into
mainfrom
06-07-fix_core_splitelementinhtml_data-end_text-content_inner_wrapper
Closed

fix(core): splitElementInHtml data-end + text-content inner wrapper#1273
vanceingalls wants to merge 3 commits into
mainfrom
06-07-fix_core_splitelementinhtml_data-end_text-content_inner_wrapper

Conversation

@vanceingalls

@vanceingalls vanceingalls commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

What

Three independent correctness fixes in packages/core/src/studio-api/helpers/sourceMutation.ts, extracted as a standalone PR so they can merge without waiting for the R1 stack.

1. setElementDuration — stale sibling attribute

When writing data-end, the old code left data-duration untouched (and vice versa). An element that previously used data-duration and got split would have both attributes after the split, with the runtime reading whichever it found first.

// now removes the other attr in each branch:
if (usesDataEnd) {
  el.setAttribute("data-end", endTime);
  el.removeAttribute("data-duration");  // ← added
} else {
  el.setAttribute("data-duration", duration);
  el.removeAttribute("data-end");       // ← added
}

2. text-content op — inner wrapper breadth

The text-content patch targets firstElementChild to avoid clobbering outer element structure. The old check required tagName === "div"; the generator can wrap text in any single-child element (<p>, <span>, etc.).

// before: only unwrapped div wrappers
// after: unwraps any single-child element
const inner = htmlEl.children.length === 1 ? htmlEl.firstElementChild : null;

3. data-playback-rate — NaN default

parseFloat on a missing attribute returns NaN. The trim offset calculation would produce NaN media start times for any element without an explicit data-playback-rate.

const rateRaw = parseFloat(el.getAttribute("data-playback-rate") ?? "");
const rate = Number.isFinite(rateRaw) ? rateRaw : 1;  // default 1× when absent/malformed

Why

All three are correctness bugs found during code review of the R1 stack. They exist independently of R1 and are safe to merge at any time.

Test plan

  • Existing sourceMutation.test.ts split tests cover setElementDuration behavior
  • Full test suite passes (380 tests, 0 fail)

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

vanceingalls added a commit that referenced this pull request Jun 8, 2026
…1273)

Covers the three bugs fixed in the parent commit:
- setElementDuration sibling cleanup (data-end removes data-duration, vice versa)
- text-content op with non-div inner wrappers (p, span)
- data-playback-rate absent → trim offset must not be NaN

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
vanceingalls and others added 3 commits June 8, 2026 14:51
…ack-rate

- setElementDuration: remove stale sibling timing attr on write
- text-content: target single element child regardless of tag name
- data-playback-rate: Number.isFinite guard replaces || 1
- rename `rounded` to `endTime` (it was an end-time, not a duration)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…1273)

Covers the three bugs fixed in the parent commit:
- setElementDuration sibling cleanup (data-end removes data-duration, vice versa)
- text-content op with non-div inner wrappers (p, span)
- data-playback-rate absent → trim offset must not be NaN

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vanceingalls vanceingalls force-pushed the 06-07-fix_core_splitelementinhtml_data-end_text-content_inner_wrapper branch from d8b13e9 to b72dc5a Compare June 8, 2026 21:51
@miguel-heygen

Copy link
Copy Markdown
Collaborator

Closing — all three fixes (setElementDuration stale sibling, text-content inner wrapper, data-playback-rate NaN guard) have been folded into the gesture-to-keyframes branch (PR #1256). They'll land with that stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants