Skip to content

Overlapping subtitle cues: a long cue vanishes while a shorter, later-starting cue is active #181

Closed

Description

@Nawid3333

Severity: medium

Where: chrome/player/ui/subtitles/SubtitlesManager.mjs (renderSubtitles, the cue lookup after Utils.binarySearch)

What happens

if (cueIndex < -1) cueIndex = -cueIndex - 2;
while (cueIndex > 0 && cues[cueIndex - 1].endTime >= currentTime && cues[cueIndex - 1].startTime <= currentTime) cueIndex--;
while (cueIndex >= 0 && cueIndex < cues.length && cues[cueIndex].endTime >= currentTime && cues[cueIndex].startTime <= currentTime) { ... cueIndex++; }

The binary search lands on the last cue with startTime <= time; the backward walk stops at the first non-active neighbour, so an active cue further back (earlier start, longer duration) is never reached. Cues are sorted by start time only (SubtitleTrack.loadText's onflush), which is the normal shape of overlapping tracks.

Reproduced with the real Utils.binarySearch and cues [0-100 "SIGN"], [10-12 "l1"], [11-13 "l2"]:

time shown
5 SIGN
11.5 SIGN, l1, l2
12.5 l2 (SIGN missing)
20 nothing (SIGN missing)

Any SRT/VTT with a sign, song or narrator cue spanning dialogue (common in anime subtitles) flickers the long cue on and off as dialogue cues start and end. No test covers overlapping cues.

Also: WebUtils.replaceChildrenPerformant only appends new nodes, so a cue that became visible later is appended below one that started later, and after a backward seek into an overlap the lines swap positions until the first ends.

Suggested fix

Precompute maxEndSoFar[i] on flush/shift (cues sorted by start) so the back-walk can stop when maxEndSoFar[i-1] < currentTime and collect every cue in between with endTime >= currentTime; or simply scan back while startTime <= currentTime (tracks are small). Order the children by startTime after the diff in replaceChildrenPerformant (insertBefore when parent.children[i] !== child).

Confidence: high.


From a line-by-line code review of the tree at 41363fd (2026-10-02). Each claim above was checked against the source before filing; the reproduction steps and line references are as of that commit.


Generated by Claude Code

Activity

  1. added
    bugSomething isn't working
    code-reviewFound by the 2026-10-02 line-by-line review
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcode-reviewFound by the 2026-10-02 line-by-line review

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions