Fix streaming HTML parser to handle nested div tags correctly #154
+73
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
findBalancedDivEnd()tracks open/close div tag depth to find actual element boundariesextractCompleteElements()only yields complete balanced elements, keeping partial content in buffer for next chunkBefore/After
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
/cardversions of those pages the images all appear as expected.