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 colors: TrackColor[] = ['blue', 'green', 'purple', 'orange', 'pink', 'indigo', 'yellow', 'red'];
|
||||||
const randomColor = colors[Math.floor(Math.random() * colors.length)];
|
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 {
|
return {
|
||||||
id: generateTrackId(),
|
id: generateTrackId(),
|
||||||
name: name || 'New Track',
|
name: trackName,
|
||||||
color: TRACK_COLORS[color || randomColor],
|
color: TRACK_COLORS[color || randomColor],
|
||||||
height: DEFAULT_TRACK_HEIGHT,
|
height: DEFAULT_TRACK_HEIGHT,
|
||||||
audioBuffer: null,
|
audioBuffer: null,
|
||||||
@@ -43,7 +46,9 @@ export function createTrackFromBuffer(
|
|||||||
name?: string,
|
name?: string,
|
||||||
color?: TrackColor
|
color?: TrackColor
|
||||||
): Track {
|
): 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;
|
track.audioBuffer = buffer;
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user