Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

fix: use set:html to prevent HTML entity escaping issues in JSX - #153

Merged
jp-knj merged 3 commits into
mainfrom
fix/html-entity-escaping-jsx
Jan 25, 2026
Merged

jp-knj merged 3 commits into
mainfrom
fix/html-entity-escaping-jsx

Conversation

@jp-knj

@jp-knj jp-knj commented Jan 25, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixes esbuild errors Expected "{" but found "&" when processing MDX files with URLs containing query parameters (e.g., ?a=1&b=2)
  • Uses Astro's set:html directive to pass HTML content as a JSON-serialized string that gets parsed at runtime instead of compile time
  • Removes the now-unused sanitizeHtmlForJsx() function

Root Cause

The issue occurred because HTML containing & entities (from URLs with query parameters) was embedded directly as JSX children. When esbuild parsed this JSX, it encountered & in an unexpected context and failed.

Before:

<>{html content with &amp;}</>

After:

<Fragment set:html={"html content with &amp;"} />

Test plan

  • All Rust tests pass (cargo test --workspace)
  • All N-API tests pass (pnpm --dir crates/napi test)
  • All astro-markflow tests pass (pnpm --dir packages/astro-markflow test)
  • withastro-docs build completes without Expected "{" but found "&" errors

🤖 Generated with Claude Code

jp-knj and others added 2 commits January 25, 2026 17:35
Fixes esbuild errors "Expected '{' but found '&'" when processing MDX
files with URLs containing query parameters (e.g., ?a=1&b=2).

The issue occurred because HTML containing &amp; entities was embedded
directly as JSX children. When esbuild parsed this JSX, it encountered
&amp; in an unexpected context and failed.

Changes:
- Update generate_astro_module() in Rust to use set:html for HTML content
- Update blocksToJsx() to use set:html for HTML blocks and component slots
- Remove unused sanitizeHtmlForJsx() function
- Update tests to reflect new output format

The fix uses Astro's set:html directive to pass HTML as a JSON-serialized
string that gets parsed at runtime instead of compile time.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update tests that check for HTML content inside set:html to use
escaped quotes since HTML is now serialized as a JSON string.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@claude

claude Bot commented Jan 25, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

…_module

The previous approach wrapped the entire module output in set:html which
broke component rendering (components became plain HTML text).

This fix:
- Use set:html for HTML blocks (Fragment set:html={...})
- Use set:html for component slot content
- Keep components as JSX so they render as actual components
- Remove unused sanitize_html_block_for_jsx function
- Update tests to reflect new output format with JSON-escaped quotes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jp-knj
jp-knj merged commit a8b91ab into main Jan 25, 2026
17 of 18 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant