Skip to content

fix: preserve explicit html and head tags when JSX comment follows DOCTYPE#1134

Merged
Princesseuh merged 2 commits intowithastro:mainfrom
tgfjt:fix/issue-1124-jsx-comment-before-html
Feb 17, 2026
Merged

fix: preserve explicit html and head tags when JSX comment follows DOCTYPE#1134
Princesseuh merged 2 commits intowithastro:mainfrom
tgfjt:fix/issue-1124-jsx-comment-before-html

Conversation

@tgfjt
Copy link
Copy Markdown
Contributor

@tgfjt tgfjt commented Feb 2, 2026

Changes

  • Fixed an issue where explicit <html> and <head> tags were removed from output when a JSX comment appeared between DOCTYPE and the <html> tag
  • Added removeImplicitMarker helper function to remove ImplicitNodeMarker attribute from nodes
  • Modified inBodyIM to handle <html> tag before the originalIM check, preventing implicit <head> from being converted to <body>
  • Modified inHeadIM to copy attributes and remove ImplicitNodeMarker when explicit <head> tag is encountered

Closes #1124

Testing

  • Added test cases for TestPrinter and TestPrintToJSON
  • All existing tests pass: go test ./internal/...

Docs

Bug fix only - no documentation changes needed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 2, 2026

🦋 Changeset detected

Latest commit: 2b1dc8c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/compiler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tgfjt tgfjt force-pushed the fix/issue-1124-jsx-comment-before-html branch from d967dd6 to b7487e9 Compare February 2, 2026 12:12
…CTYPE (withastro#1124)

When a JSX comment like `{/* Comment */}` appeared between DOCTYPE and the
`<html>` tag, the explicit `<html>` and `<head>` tags were removed from output.

Root cause:
- The expression triggered implicit `<html>` and `<head>` insertion with
`ImplicitNodeMarker` attribute
- When explicit tags came later, the marker wasn't removed
- Printer skips outputting tags with `ImplicitNodeMarker`

Changes:
- Add `removeImplicitMarker` helper function
- Handle `<html>` tag before `originalIM` check in `inBodyIM` to prevent
implicit `<head>` from being converted to `<body>`
- Remove `ImplicitNodeMarker` when explicit `<html>` or `<head>` is encountered
@tgfjt tgfjt force-pushed the fix/issue-1124-jsx-comment-before-html branch from b7487e9 to 8a75ecc Compare February 2, 2026 12:14
Copy link
Copy Markdown
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@Princesseuh Princesseuh merged commit f89451a into withastro:main Feb 17, 2026
5 checks passed
@tgfjt tgfjt deleted the fix/issue-1124-jsx-comment-before-html branch February 18, 2026 03:37
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.

JSX Comment between DOCTYPE and <html> tag removes <html> and <head> in output

2 participants