Commit b78786a
authored
feat: modularize FASTElement with opt-in hydration and subpath exports (#7497)
# Pull Request
## 📖 Description
Modularizes `@microsoft/fast-element` to reduce core bundle size and make hydration, styles, and array observation opt-in through subpath exports.
**Hydration is now opt-in** — `enableHydration()` from `@microsoft/fast-element/hydration.js` activates hydration via a pluggable hook. Without it, `ElementController` has zero hydration imports or logic.
**New subpath exports** split heavy features out of the main barrel:
- `./styles.js` — `css`, `ElementStyles`, `CSSDirective`, style strategies
- `./arrays.js` — `ArrayObserver`, `Splice`, `SpliceStrategy`, array utilities
- `./hydration.js` — `enableHydration`, `deferHydrationAttribute`
**`globalThis.FAST` removed** — `FAST` is now a module-scoped export with no side-effecting global mutation. `FAST.getById()`, `FASTGlobal`, `KernelServiceId`, and the `requestIdleCallback` polyfill are all removed.
**Per-element lifecycle callbacks** are passed directly to `declarativeTemplate()`, and `isPrerendered` / `isHydrated` are now separate promises with clear semantics.
## 👩💻 Reviewer Notes
- `TemplateElement.config()` is preserved as a deprecated shim for backward compatibility.
- `ElementController` now uses composition for `PropertyChangeNotifier` instead of inheritance.
- The hydration rendering path (`renderPrerendered`) moved entirely into `enable-hydration.ts` via `ElementController.installHydrationHook()`.
- `isPrerendered` resolves `true` when a DSD shadow root existed (independent of hydration). `isHydrated` resolves `true` only when hydration actually ran.
- Declarative template `{{ }}` bindings with spaces inside braces do not work — the templates.html files must use `{{binding}}` without spaces.
## 📑 Test Plan
- 1396 Playwright tests pass (chromium)
- 176 declarative fixture tests pass (chromium)
- New `declarative-no-hydration` fixture (5 tests) verifies client-side rendering, lifecycle callbacks without hydration, and `isPrerendered`/`isHydrated` semantics
- Updated `platform.pw.spec.ts` and `debug.pw.spec.ts` for module-scoped FAST
- Updated `lifecycle-callbacks` and `performance-metrics` fixtures for new API
## ✅ 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.
## ⏭ Next Steps
- Run full CI across all browsers (Firefox, WebKit)
- Remove `TemplateElement.config()` deprecated shim in a future release
- Consider lazy-loading the `Compiler` on first render for further size reduction1 parent 803c757 commit b78786a
197 files changed
Lines changed: 3827 additions & 4866 deletions
File tree
- change
- examples/todo-app/src
- packages
- fast-element
- docs
- arrays
- declarative
- hydration
- styles
- scripts
- src
- binding
- components
- declarative
- di
- hydration
- observation
- state
- styles
- templating
- testing
- test
- declarative
- fixtures/ecosystem
- declarative-no-hydration
- lifecycle-callbacks
- performance-metrics
- fast-router
- docs
- src
- sites/website/src/docs/3.x
- advanced
- api
- fast-element/declarative
- declarative-templates
- getting-started
- resources
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
Lines changed: 74 additions & 49 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
101 | 102 | | |
102 | | - | |
| 103 | + | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| |||
154 | 155 | | |
155 | 156 | | |
156 | 157 | | |
157 | | - | |
| 158 | + | |
158 | 159 | | |
159 | | - | |
| 160 | + | |
160 | 161 | | |
161 | 162 | | |
162 | | - | |
163 | | - | |
164 | 163 | | |
165 | 164 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | 165 | | |
170 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
171 | 170 | | |
172 | 171 | | |
173 | | - | |
| 172 | + | |
174 | 173 | | |
175 | 174 | | |
176 | 175 | | |
| |||
186 | 185 | | |
187 | 186 | | |
188 | 187 | | |
189 | | - | |
| 188 | + | |
190 | 189 | | |
191 | 190 | | |
192 | 191 | | |
| |||
200 | 199 | | |
201 | 200 | | |
202 | 201 | | |
203 | | - | |
| 202 | + | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
| 207 | + | |
207 | 208 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
226 | 213 | | |
227 | 214 | | |
228 | | - | |
229 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
230 | 242 | | |
231 | 243 | | |
232 | 244 | | |
233 | 245 | | |
234 | 246 | | |
235 | 247 | | |
236 | 248 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
245 | 253 | | |
246 | | - | |
| 254 | + | |
247 | 255 | | |
248 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
249 | 274 | | |
250 | 275 | | |
251 | 276 | | |
252 | 277 | | |
253 | 278 | | |
254 | | - | |
| 279 | + | |
255 | 280 | | |
256 | | - | |
| 281 | + | |
257 | 282 | | |
258 | 283 | | |
259 | | - | |
260 | | - | |
261 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
262 | 287 | | |
263 | 288 | | |
0 commit comments