Skip to content

Commit d4aa5f9

Browse files
fix(studio): guard against null tag in timeline track style (#1679)
getTrackStyle() can receive a falsy tag at runtime (e.g. empty string from timeline element defaults), causing toLowerCase() and startsWith() to throw. Default to "div" when tag is falsy.
1 parent 344618e commit d4aa5f9

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

packages/studio/src/player/components/timelineIcons.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ const ICONS: Record<string, ReactNode> = {
3939
};
4040

4141
export function getTrackStyle(tag: string): TrackVisualStyle {
42-
const trackStyle = getTimelineTrackStyle(tag);
43-
const normalized = tag.toLowerCase();
42+
if (!tag) console.warn("[Timeline] getTrackStyle received empty tag, defaulting to div");
43+
const safeTag = tag || "div";
44+
const trackStyle = getTimelineTrackStyle(safeTag);
45+
const normalized = safeTag.toLowerCase();
4446
const icon =
4547
normalized.startsWith("h") && normalized.length === 2 && "123456".includes(normalized[1] ?? "")
4648
? ICONS.h1

packages/studio/src/player/lib/timelineDOM.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export {
6161
// TimelineElement factories
6262
// ---------------------------------------------------------------------------
6363

64+
function resolveClipTag(clip: ClipManifestClip): string {
65+
return clip.tagName || clip.kind || "div";
66+
}
67+
6468
export function createTimelineElementFromManifestClip(params: {
6569
clip: ClipManifestClip;
6670
fallbackIndex: number;
@@ -72,7 +76,7 @@ export function createTimelineElementFromManifestClip(params: {
7276
const label = getTimelineElementDisplayLabel({
7377
id: clip.id,
7478
label: clip.label,
75-
tag: clip.tagName || clip.kind,
79+
tag: resolveClipTag(clip),
7680
});
7781

7882
let domId: string | undefined;
@@ -103,7 +107,7 @@ export function createTimelineElementFromManifestClip(params: {
103107
id: identity.id,
104108
label,
105109
key: identity.key,
106-
tag: clip.tagName || clip.kind,
110+
tag: resolveClipTag(clip),
107111
start: clip.start,
108112
duration: clip.duration,
109113
track: clip.track,

0 commit comments

Comments
 (0)