You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Pull Request
## 📖 Description
Removes `ElementStyles.withBehaviors()` and the remaining stylesheet
behavior-composition path from `@microsoft/fast-element`.
This change also:
- removes CSS bindings in `css`
- removes stylesheet-attached behavior composition from `css` and `css.partial()`
- keeps `CSSDirective` as a static CSS extension point via `createCSS(): ComposableStyles`
- keeps runtime stylesheet toggling on `ElementController.addStyles()` / `removeStyles()`
This also updates the related Playwright coverage, migration guidance,
package docs, and regenerated 3.x API and export-size documentation.
### 🎫 Issues
- Closes#7244
## 📑 Test Plan
- `npm run build`
- `npm run prebuild -w sites/website`
- `npm run biome:check`
- `npm run checkchange`
- `npm run test`
- `npm run test:playwright -w @microsoft/fast-element -- -x --reporter=line`
## ✅ Checklist
### General
- [x] I have included a change request file using `$ npm run change`
- [x] I have added tests for my changes.
- [x] I have tested my changes.
- [x] I have updated the project documentation to reflect my changes.
- [x] I have read the [CONTRIBUTING](https://github.com/microsoft/fast/blob/main/CONTRIBUTING.md) documentation and followed the [standards](https://github.com/microsoft/fast/blob/main/CODE_OF_CONDUCT.md#our-standards) for this project.
The `css` tag (analogous to `html`) builds `ElementStyles` objects. During `ElementController.connect()`, styles are applied to the element's shadow root either via `adoptedStylesheets` (preferred) or an appended `<style>` node, depending on platform support. Styles can also contain dynamic `CSSDirective`s (e.g., CSS custom property bindings) that register as `HostBehavior`s and connect/disconnect alongside the element.
279
+
The `css` tag (analogous to `html`) builds `ElementStyles` objects. During `ElementController.connect()`, styles are applied to the element's shadow root either via `adoptedStylesheets` (preferred) or an appended `<style>` node, depending on platform support. `CSSDirective`s can contribute additional static CSS during template composition, but runtime CSS bindings and style-attached `HostBehavior`s are not supported. Arbitrary runtime style toggling is handled through `ElementController.addStyles()` / `removeStyles()`; `ElementStyles` itself is a static container.
|`ElementStyles.withBehaviors()`| Move the runtime condition into the element and call `this.$fastController.addStyles()` / `this.$fastController.removeStyles()` directly. |
189
+
|`ElementStyles.behaviors`| Move any runtime behavior out of the stylesheet and into the element or controller lifecycle. |
190
+
| CSS bindings in `css` (for example ``css`color: ${x => x.color}```) | Move the dynamic value into the element and update classes, attributes, or inline styles from element code. |
191
+
|`CSSDirective.createCSS(add)`| Update directives to implement `createCSS()` and return only static CSS content. |
192
+
193
+
### Changed behavior
194
+
195
+
-`css` and `css.partial()` no longer compose `HostBehavior`s.
196
+
-`css` no longer accepts function or `Binding` interpolations.
197
+
-`ElementStyles` is now a fully static style container.
198
+
199
+
### Migration steps
200
+
201
+
1. Keep the conditional `ElementStyles` in a separate `css` value.
202
+
2. Move the external listener or condition (for example `matchMedia()` or an app event subscription) into the element lifecycle.
203
+
3. Call `this.$fastController.addStyles(styles)` when the condition is active and `this.$fastController.removeStyles(styles)` when it is inactive or during cleanup.
204
+
4. If you previously interpolated bindings or behavior-producing directives into `css`, replace them with element state and standard DOM or controller updates.
Bundle sizes for each tree-shakeable export are tracked in [`SIZES.md`](./SIZES.md) and regenerated on every build. See the [Export Sizes](https://www.fast.design/docs/3.x/resources/export-sizes/) documentation page for the latest numbers.
67
67
68
+
## Dynamic Style Application
69
+
70
+
When runtime state or external signals need to add or remove styles, create the
71
+
`ElementStyles` with `css` and toggle it through
72
+
`this.$fastController.addStyles()` / `this.$fastController.removeStyles()` from
73
+
the element lifecycle or change handlers.
74
+
75
+
`css` templates remain static style definitions. Runtime CSS bindings and
76
+
behavior-producing CSS directives are no longer supported; keep the condition on
77
+
the element and toggle a separate `ElementStyles` instance through the
78
+
controller when styles need to change.
79
+
68
80
## Prerendered Content Optimization
69
81
70
82
When a FAST element connects and already has an existing shadow root (from server-side rendering or declarative shadow DOM), `ElementController` automatically detects this. The `isPrerendered` property on the controller is a `Promise<boolean>` that resolves to `true` after prerendered content has been hydrated, or `false` when the component is client-side rendered. This enables several optimizations:
// dist/dts/components/fast-element.d.ts:60:5 - (ae-forgotten-export) The symbol "define" needs to be exported by the entry point index.d.ts
1115
1089
// dist/dts/components/fast-element.d.ts:61:5 - (ae-forgotten-export) The symbol "compose" needs to be exported by the entry point index.d.ts
1116
1090
// dist/dts/components/fast-element.d.ts:62:5 - (ae-forgotten-export) The symbol "from" needs to be exported by the entry point index.d.ts
1117
-
// dist/dts/styles/css-binding-directive.d.ts:35:9 - (ae-forgotten-export) The symbol "CSSBindingEntry" needs to be exported by the entry point index.d.ts
1118
1091
1119
1092
// (No @packageDocumentation comment for this package)
0 commit comments