Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 30, 2025

Streaming lookup results occasionally rendered incomplete cards (missing artwork, provider links) because the parser used lastIndexOf('</div>') to detect complete HTML—incorrectly treating inner closing tags as element boundaries in nested structures.

Changes

  • Balanced tag detection: New findBalancedDivEnd() tracks open/close div tag depth to find actual element boundaries
  • Proper extraction: extractCompleteElements() only yields complete balanced elements, keeping partial content in buffer for next chunk

Before/After

// Before: breaks on first </div> found
let lastClosingDiv = buffer.lastIndexOf('</div>');
const completeHTML = buffer.substring(0, lastClosingDiv + 6);

// After: counts balanced tags
const { completeHtml, remaining } = extractCompleteElements(buffer);
// Only processes when div depth returns to 0

Truncated card like <div class="col"><div class="card"><div class="title">X</div> now correctly stays buffered until the outer divs close.

Original prompt

This section details on the original issue you should resolve

<issue_title>Results cards occasionally dropping links</issue_title>
<issue_description>Occasionally, on the lookup results pages, the application is dropping the result images and music service links and icons.

Here is an example where one card has the correct links and images and the following one does not. If you actually go to the /card versions of those pages the images all appear as expected.

<div class="col">
    <div class="embed-card h-100 provider-applemusic" data-rkey="track:CH3131340083">
        <div class="embed-header-top">
            <div class="embed-title-row">
                    <a href="https://dev.tunebridge.media/card/rfi2z4jmtt7emfznukoc4gmhdguaqmuk" target="_blank" rel="noopener noreferrer" class="embed-title">
                        You Make Me
                    </a>
                    <div class="share-dropdown">
                        <button class="share-button" type="button" aria-expanded="false" aria-haspopup="true" title="Share">
                            <img src="/public/Share_arrow.png" alt="Share" class="share-arrow-icon">
                        </button>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li>
                                <button class="dropdown-item copy-link-btn" type="button" data-url="https://dev.tunebridge.media/card/rfi2z4jmtt7emfznukoc4gmhdguaqmuk">
                                    <span class="dropdown-icon">📋</span> Copy Link
                                </button>
                            </li>
                            <li>
                                <button class="dropdown-item copy-embed-btn" type="button" data-url="https://dev.tunebridge.media/card/rfi2z4jmtt7emfznukoc4gmhdguaqmuk" data-title="" you="" make="" me""="">
                                    <span class="dropdown-icon">🖼️</span> Copy Embed
                                </button>
                            </li>
                                <li>
                                    <button class="dropdown-item copy-atproto-btn" type="button" data-uri="at://did:plc:7y2pqy7ogqqjmqe4ubl6fafv/media.tunebridge.dev.lookup/track:CH3131340083">
                                        <span class="dropdown-icon">🔗</span> Copy ATProto URI
                                    </button>
                                </li>
                        </ul>
                    </div>
            </div>
        </div>
        <div class="embed-header">
                    <a href="https://dev.tunebridge.media/card/rfi2z4jmtt7emfznukoc4gmhdguaqmuk" target="_blank" rel="noopener noreferrer">
                        <img src="https://is1-ssl.mzstatic.com/image/thumb/Music211/v4/18/5b/1e/185b1ef5-5d97-19d8-aebf-8e29e41874ef/13UAAIM59255.rgb.jpg/1500x1500bb.jpg" alt="You Make Me artwork" class="embed-image">
                    </a>
            <div class="embed-content">
                <div class="embed-info">
                    Artist: Avicii
<br>ISRC: CH3131340083                </div>
            </div>
        </div>
        <div class="embed-providers">
                <a href="https://music.apple.com/us/album/you-make-me/1440872730?i=1440872944" target="_blank" rel="noopener noreferrer" class="provider-button">
                    <span class="provider-icon provider-icon-applemusic">
                        <img src="/public/providerIcons/US-UK_Apple_Music_Listen_on_Lockup_RGB_blk_072720.svg" alt="Apple Music logo" class="provider-logo provider-logo-light"><img src="/public/providerIcons/US-UK_Apple_Music_Listen_on_Lockup_RGB_wht_072720.svg" alt="Apple Music logo" class="provider-logo provider-logo-dark">
                    </span>
                    <span class="visually-hidden">Apple Music</span>
                </a>
                <a href="https://open.spotify.com/track/63bwUT2JAPomuoIITQ2Iiy" target="_blank" rel="noopener noreferrer" class="provider-button">
                    <span class="provider-icon provider-icon-spotify">
                        <img src="/public/providerIcons/Spotify_Full_Logo_Green_CMYK.svg" alt="Spotify logo" class="provider-logo provider-logo-light"><img src="/public/providerIcons/Spotify_Full_Logo_Green_RGB.svg" alt="Spotify logo" class="provider-logo provider-logo-dark">
                    </span>
                    <span class="visually-hidden">Spotify</span>
                </a>
                <a href="https://tidal.com/browse/track/22120603" target="_blank" rel="noopener noreferrer" class="provider-button">
                    <span class="provider-icon provider-icon-tidal">
                        <img src="/public/providerIcons/tidal-horizontal-black-cmyk.png" alt="Tidal logo" class="provider-logo provider-logo-light"><img src="/public/providerIcons/tidal-horizontal-white-cmyk.png" alt="Tidal logo" class="provider-logo provider-logo-dark">
                    </span>
                    <...

</details>

- Fixes tsmarvin/BridgeBeats#153

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI changed the title [WIP] Fix results cards occasionally dropping links Fix streaming HTML parser to handle nested div tags correctly Nov 30, 2025
Copilot AI requested a review from tsmarvin November 30, 2025 18:34
Copilot finished work on behalf of tsmarvin November 30, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants