fix: ensure track name is always a string in createTrack
Added type checking to prevent event objects from being used as track names. When onClick handlers pass events, we now explicitly check for string type. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -19,9 +19,12 @@ export function createTrack(name?: string, color?: TrackColor): Track {
|
||||
const colors: TrackColor[] = ['blue', 'green', 'purple', 'orange', 'pink', 'indigo', 'yellow', 'red'];
|
||||
const randomColor = colors[Math.floor(Math.random() * colors.length)];
|
||||
|
||||
// Ensure name is always a string, handle cases where event objects might be passed
|
||||
const trackName = typeof name === 'string' && name.trim() ? name.trim() : 'New Track';
|
||||
|
||||
return {
|
||||
id: generateTrackId(),
|
||||
name: name || 'New Track',
|
||||
name: trackName,
|
||||
color: TRACK_COLORS[color || randomColor],
|
||||
height: DEFAULT_TRACK_HEIGHT,
|
||||
audioBuffer: null,
|
||||
@@ -43,7 +46,9 @@ export function createTrackFromBuffer(
|
||||
name?: string,
|
||||
color?: TrackColor
|
||||
): Track {
|
||||
const track = createTrack(name, color);
|
||||
// Ensure name is a string before passing to createTrack
|
||||
const trackName = typeof name === 'string' && name.trim() ? name.trim() : undefined;
|
||||
const track = createTrack(trackName, color);
|
||||
track.audioBuffer = buffer;
|
||||
return track;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user