fix: preserve plugin template root attributes#359
Merged
Conversation
Preserve authored root <template> attributes for plugin/client component templates while keeping SSR output clean. Append CSS module adopted stylesheet attributes centrally when missing and add todo-fast E2E coverage for delegated root events. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a parser/plugin contract issue where user-authored root <template> attributes (notably FAST root delegated @event handlers) were being stripped before parser plugins could see them, breaking delegated root event wiring in examples/app/todo-fast. It does so by building two explicit component-template views: an SSR/internal parse view (cleaned) and a plugin/client artifact view (preserving authored root <template> attributes), while also centralizing CSS module adopted-stylesheet attribute insertion.
Changes:
- Build dual component template views in
HtmlParser(ssrvs plugin-facingartifact) and pass the plugin-facing view toParserPlugin::register_component_template. - Append
shadowrootadoptedstylesheets="<component-name>"for--css modulewhen a component has CSS and the authored wrapper is missing the attribute; remove the obsoleteParserError::MissingAdoptedStylesheetscontract. - Add Playwright E2E coverage for
examples/app/todo-fastand wire it intocargo xtask e2e; updateDESIGN.mdand docs to reflect the new contract.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
xtask/src/e2e.rs |
Adds todo-fast to the xtask-managed Playwright E2E suite list. |
pnpm-lock.yaml |
Records @playwright/test for the todo-fast example workspace importer. |
examples/app/todo-fast/tests/todo-fast.spec.ts |
Adds SSR + interactivity Playwright coverage, including assertions for preserved root runtime attrs in FAST templates. |
examples/app/todo-fast/playwright.config.ts |
Introduces Playwright config for the todo-fast example (baseURL/timeout/projects). |
examples/app/todo-fast/package.json |
Adds Playwright test scripts and the @playwright/test dev dependency. |
docs/guide/concepts/plugins/index.md |
Documents that plugin-facing component templates preserve authored root <template> attributes. |
docs/guide/cli/index.md |
Updates --css module behavior to reflect automatic shadowrootadoptedstylesheets appending + wrapper attr preservation. |
docs/ai.md |
Updates AI reference to note wrapper attribute preservation and automatic adopted-stylesheets insertion in module CSS mode. |
DESIGN.md |
Updates the spec: removes the “MissingAdoptedStylesheets” error contract and documents the new append-if-missing behavior + plugin template surface. |
crates/webui-parser/src/plugin/webui.rs |
Adjusts internal docs/comments to reflect “plugin-facing” template capture semantics. |
crates/webui-parser/src/plugin/mod.rs |
Updates plugin trait docs to specify plugin-facing template semantics and root attribute preservation. |
crates/webui-parser/src/lib.rs |
Implements dual template views (BuiltComponentTemplate), passes artifact view to plugins, appends adopted-stylesheets attr when missing, and updates/extends tests accordingly. |
crates/webui-parser/src/error.rs |
Removes ParserError::MissingAdoptedStylesheets variant and its error message contract. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
akroshg
approved these changes
Jun 19, 2026
janechu
reviewed
Jun 19, 2026
janechu
approved these changes
Jun 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
<template>attributes for parser plugin/client component templates while continuing to strip runtime-only attributes from the SSR/internal parse view.ParserPlugin::register_component_template.shadowrootadoptedstylesheets="<component-name>"centrally for CSS module strategy when a component has CSS and the authored wrapper is missing the attribute.ParserError::MissingAdoptedStylesheetscontract and updateDESIGN.md, CLI docs, plugin docs, and the AI reference.todo-fastPlaywright coverage and wire it intocargo xtask e2eso FAST delegated root events are covered without requiring CSS module mode.Why
FAST component templates were receiving the SSR-cleaned component template string. That string had root runtime attributes such as
@toggle-item,@delete-item, and@clickstripped from user-authored<template>wrappers before FAST generated<f-template>artifacts. As a result,examples/app/todo-fastrendered and could handle local child events, but delegated root events from child components did not wire up, so toggling and deleting existing todos failed.The correct contract is that authored root
<template>attributes belong to the plugin/client template surface. SSR can still use a clean view that removes runtime-only syntax, but plugins should not have to reconstruct or special-case raw component source.Design
This change centralizes the behavior in
HtmlParserrather than adding a FAST-specific workaround:BuiltComponentTemplate::ssris used for internal fragment parsing and SSR output.BuiltComponentTemplate::artifact()is passed to parser plugins.<template>attributes.@,:,?) so rendered HTML remains clean.This keeps WebUI and FAST on the same parser/plugin contract. WebUI’s existing raw-source root-event path remains compatible, but plugin correctness no longer depends on duplicating that pattern in FAST.
Performance notes
Validation
cargo test -p microsoft-webui-parser --libcargo test -p microsoft-webui-parserpnpm --dir examples/app/todo-fast run buildpnpm --dir examples/app/todo-fast testpnpm --dir examples/app/todo-webui testpnpm --dir docs buildcargo xtask check