Skip to content

fix: handle leading comments in component templates - #445

Merged
Mohamed Mansour (mohamedmansour) merged 2 commits into
microsoft:mainfrom
mohamedmansour:mohamedmansour-fix-leading-comments
Aug 14, 2026
Merged

fix: handle leading comments in component templates#445
Mohamed Mansour (mohamedmansour) merged 2 commits into
microsoft:mainfrom
mohamedmansour:mohamedmansour-fix-leading-comments

Conversation

@mohamedmansour

Copy link
Copy Markdown
Contributor

Component templates with copyright or license comments before their first authored node were misclassified, causing an existing <template> wrapper to be wrapped again and preventing root metadata from being detected.

This change adds a shared zero-copy scan that skips leading whitespace and HTML comments before root classification. Template construction, component render policy parsing, runtime attribute detection, and root event extraction now use the same semantics. Regression coverage includes a leading comment followed by an authored template, an element, or text, plus root policy and event metadata cases.

The docs synchronization guidance now avoids user-facing documentation churn for internal fixes that only restore already-documented behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes component-template root classification when the authored content begins with leading HTML comments (e.g., license headers), which previously caused double-wrapping of an existing <template> and missed root metadata detection. The change introduces a shared, zero-copy “leading content” scan so multiple subsystems agree on what constitutes the first meaningful node.

Changes:

  • Added leading_content() scanner to skip leading whitespace and well-formed HTML comments and report the byte offset of the first non-comment content.
  • Updated root template classification call sites (template construction, component render policy parsing, runtime attribute detection, root event extraction) to use the shared scan.
  • Added regression tests covering leading-comment scenarios for root detection and root policy parsing; updated docs-sync guidance to avoid docs churn for internal fixes restoring documented behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/webui-parser/src/html_parser.rs Adds leading_content() utility to consistently skip leading whitespace/comments with an offset.
crates/webui-parser/src/lib.rs Uses leading_content() for root template detection and runtime-attr detection; adds regression tests.
crates/webui-parser/src/component_policy.rs Uses leading_content() so root render/hydration policy is detected after leading comments; adds a test.
crates/webui-parser/src/plugin/webui.rs Uses leading_content() so root event extraction works when a leading comment precedes <template>.
.github/skills/docs-sync/SKILL.md Clarifies docs-update guidance to avoid user-facing doc churn for internal regressions/refactors.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@mohamedmansour
Mohamed Mansour (mohamedmansour) merged commit 92a25ab into microsoft:main Aug 14, 2026
10 checks passed
@mohamedmansour
Mohamed Mansour (mohamedmansour) deleted the mohamedmansour-fix-leading-comments branch August 14, 2026 21:52
Mohamed Mansour (mohamedmansour) added a commit that referenced this pull request Aug 15, 2026
## Release

Bumps WebUI to `0.0.25`.

Previous release tag: `v0.0.24`

## Changes since `v0.0.24`

Fixes:

- TypeScript consumers can import the framework and router together
without conflicting `Window.__webui` declarations (fix: make WebUI
global declarations compatible #444).
- Component templates correctly classify authored roots and root
metadata when leading copyright or license comments are present (fix:
handle leading comments in component templates #445).
- Router navigation distinguishes same-component route declarations by
path, preserving declaration-specific pending, error, cache, and
keep-alive behavior (fix: distinguish route declarations by path #446).

## Validation

- `cargo xtask check`

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

3 participants