Skip to content

[BUG] State corruption and export failure due to premature state update in 'TrimControl' #954

@Sandeep6135

Description

@Sandeep6135

Description

In TrimControl.tsx, the handleEnd function dispatches a state update to the global recipe object before validating the user's input. If a user enters an invalid value (resulting in NaN) or a value that is out of bounds, the application's state is corrupted with NaN for trimEnd. Because NaN > duration evaluates to false, this bypasses the pre-export validation in useVideoEditor.ts, passing the invalid state directly to FFmpeg which causes the export to fail or crash.

To Reproduce
Steps to reproduce the behavior:

  1. Upload a valid video file.
  2. In the "Trim" section, type an invalid character or partially clear the "End (sec)" input field (so that parseFloat results in NaN).
  3. Note that the UI correctly displays an inline error message ("Enter a valid number.").
  4. Click the "Export" button.
  5. The export will attempt to run (bypassing validation) and subsequently crash/fail because the underlying recipe.trimEnd state is corrupted.

Expected behavior
The recipe state should only be updated after the input has been fully validated (similar to how handleStart currently operates). If the input is invalid, the state should remain unchanged, and the export validation should correctly block the export.

Code Snippet

// src/components/TrimControl.tsx
const handleEnd = (val: string) => {
  // ...
  const n = parseFloat(val);
  
  // 🐛 BUG: State is updated before validation
  onChange({ trimEnd: n }); 

  if (isNaN(n)) {
    setEnd(true);
    setEndErrorMsg("Enter a valid number.");
    return;
  }
  // ...
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working correctlytype:bugBug fixtype:designUI/UX design

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions