Skip to content

fix: preserve text content with bindings after void elements#243

Merged
janechu merged 1 commit intomainfrom
fix/parser-text-after-void-element
Apr 16, 2026
Merged

fix: preserve text content with bindings after void elements#243
janechu merged 1 commit intomainfrom
fix/parser-text-after-void-element

Conversation

@janechu
Copy link
Copy Markdown
Contributor

@janechu janechu commented Apr 15, 2026

Description

Fix text nodes and {{bindings}} being silently dropped when they follow HTML void elements like <br>, <hr>, <img>, etc.

Tree-sitter HTML parses void elements with following text as children of the void element node. For example, <br>Part B: {{value2}} is parsed as a single element node where Part B: {{value2}} is a text child of <br>. The parser previously skipped content processing for void elements (since they have no end tag), which caused any text nodes and bindings that tree-sitter attached as children to be silently dropped.

The fix adds process_content_children() for void elements, matching the behavior already used for elements with end tags.

Before:

Input:    Part A: {{value1}}<br>Part B: {{value2}}
Fragments: [raw("Part A: "), signal("value1"), raw("<br>")]
           ❌ "Part B: " and {{value2}} are lost

After:

Input:    Part A: {{value1}}<br>Part B: {{value2}}
Fragments: [raw("Part A: "), signal("value1"), raw("<br>Part B: "), signal("value2")]
           ✅ All content preserved

Test Plan

  • Added regression test test_text_with_binding_after_void_element
  • All 286 existing parser tests continue to pass
  • cargo xtask check passes (license-headers, fmt, clippy, test)

Checklist

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I understand and have considered the performance impact of my changes.

@janechu janechu marked this pull request as ready for review April 16, 2026 03:19
@janechu janechu force-pushed the fix/parser-text-after-void-element branch from e175859 to 0d8cc20 Compare April 16, 2026 03:19
Tree-sitter HTML parses void elements like `<br>` with following text
as children of the void element node (e.g., `<br>Part B: {{value2}}`
becomes one element node spanning both the tag and the text). The parser
skipped content processing for void elements since they have no end tag,
which silently dropped any text nodes and bindings that tree-sitter
attached as children.

Process content children for void elements so that text and bindings
following `<br>`, `<hr>`, `<img>`, etc. are correctly emitted as
fragments.

Co-authored-by: Copilot <[email protected]>
@janechu janechu force-pushed the fix/parser-text-after-void-element branch from 0d8cc20 to ccf3685 Compare April 16, 2026 04:15
@janechu janechu merged commit 57a0198 into main Apr 16, 2026
21 checks passed
@janechu janechu deleted the fix/parser-text-after-void-element branch April 16, 2026 04:21
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