@microsoft/fast-element 3.0.0-rc.1 → 3.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/README.md +50 -14
  3. package/dist/context/context.api.json +13 -13
  4. package/dist/declarative/declarative.api.json +654 -15
  5. package/dist/di/di.api.json +15 -15
  6. package/dist/dts/__test__/helpers.d.ts +6 -0
  7. package/dist/dts/__test__/setup-node.d.ts +0 -0
  8. package/dist/dts/binding/binding.d.ts +15 -5
  9. package/dist/dts/binding/one-time.d.ts +1 -1
  10. package/dist/dts/binding/one-way.d.ts +1 -1
  11. package/dist/dts/binding/signal.d.ts +1 -1
  12. package/dist/dts/binding/two-way.d.ts +1 -1
  13. package/dist/dts/components/attributes.d.ts +1 -1
  14. package/dist/dts/components/enable-hydration.d.ts +22 -2
  15. package/dist/dts/components/fast-definitions.d.ts +7 -4
  16. package/dist/dts/components/fast-element.d.ts +42 -12
  17. package/dist/dts/components/hydration-tracker.d.ts +47 -4
  18. package/dist/dts/components/hydration.d.ts +5 -0
  19. package/dist/dts/context.d.ts +7 -7
  20. package/dist/dts/declarative/debug.d.ts +2 -3
  21. package/dist/dts/declarative/index.d.ts +3 -2
  22. package/dist/dts/declarative/interfaces.d.ts +1 -2
  23. package/dist/dts/declarative/template.d.ts +2 -1
  24. package/dist/dts/declarative/utilities.d.ts +50 -4
  25. package/dist/dts/di/di.d.ts +6 -6
  26. package/dist/dts/dom-policy.d.ts +22 -4
  27. package/dist/dts/dom.d.ts +4 -16
  28. package/dist/dts/hydration/diagnostics.d.ts +93 -0
  29. package/dist/dts/hydration/hydration-debugger.d.ts +35 -0
  30. package/dist/dts/hydration/messages.d.ts +62 -0
  31. package/dist/dts/hydration/target-builder.d.ts +26 -1
  32. package/dist/dts/hydration.d.ts +7 -3
  33. package/dist/dts/index.d.ts +7 -3
  34. package/dist/dts/interfaces.d.ts +1 -0
  35. package/dist/dts/observation/observable.d.ts +3 -3
  36. package/dist/dts/platform.d.ts +20 -4
  37. package/dist/dts/registry.d.ts +1 -0
  38. package/dist/dts/templating/children.d.ts +1 -1
  39. package/dist/dts/templating/compiler.d.ts +1 -1
  40. package/dist/dts/templating/html-binding-directive.d.ts +6 -2
  41. package/dist/dts/templating/html-directive.d.ts +2 -1
  42. package/dist/dts/templating/hydration-view.d.ts +24 -3
  43. package/dist/dts/templating/ref.d.ts +1 -1
  44. package/dist/dts/templating/render.d.ts +2 -2
  45. package/dist/dts/templating/repeat.d.ts +1 -1
  46. package/dist/dts/templating/slotted.d.ts +1 -1
  47. package/dist/dts/templating/template.d.ts +5 -5
  48. package/dist/dts/templating/when.d.ts +1 -1
  49. package/dist/dts/testing/fakes.d.ts +4 -4
  50. package/dist/esm/__test__/helpers.js +22 -0
  51. package/dist/esm/__test__/setup-node.js +18 -0
  52. package/dist/esm/binding/two-way.js +1 -2
  53. package/dist/esm/components/attributes.js +12 -8
  54. package/dist/esm/components/element-controller.js +11 -6
  55. package/dist/esm/components/enable-hydration.js +27 -3
  56. package/dist/esm/components/fast-definitions.js +19 -18
  57. package/dist/esm/components/hydration-tracker.js +34 -5
  58. package/dist/esm/components/hydration.js +85 -6
  59. package/dist/esm/debug.js +1 -0
  60. package/dist/esm/declarative/attribute-map.js +2 -1
  61. package/dist/esm/declarative/debug.js +0 -1
  62. package/dist/esm/declarative/index.js +1 -0
  63. package/dist/esm/declarative/interfaces.js +0 -1
  64. package/dist/esm/declarative/observer-map-utilities.js +58 -55
  65. package/dist/esm/declarative/template-bridge.js +4 -14
  66. package/dist/esm/declarative/template.js +4 -3
  67. package/dist/esm/declarative/utilities.js +236 -1
  68. package/dist/esm/di/di.js +2 -1
  69. package/dist/esm/dom-policy.js +33 -4
  70. package/dist/esm/hydration/diagnostics.js +50 -0
  71. package/dist/esm/hydration/hydration-debugger.js +112 -0
  72. package/dist/esm/hydration/messages.js +84 -0
  73. package/dist/esm/hydration/target-builder.js +65 -19
  74. package/dist/esm/hydration.js +3 -1
  75. package/dist/esm/index.js +6 -2
  76. package/dist/esm/interfaces.js +1 -0
  77. package/dist/esm/metadata.js +2 -8
  78. package/dist/esm/observation/notifier.js +2 -4
  79. package/dist/esm/registry.js +1 -0
  80. package/dist/esm/templating/html-binding-directive.js +1 -1
  81. package/dist/esm/templating/hydration-view.js +20 -27
  82. package/dist/esm/templating/render.js +39 -18
  83. package/dist/esm/templating/repeat.js +51 -17
  84. package/dist/esm/templating/view.js +1 -1
  85. package/dist/esm/testing/fixture.js +2 -2
  86. package/dist/esm/testing/timeout.js +2 -2
  87. package/dist/fast-element.api.json +1329 -99
  88. package/dist/fast-element.d.ts +147 -66
  89. package/dist/fast-element.debug.js +392 -99
  90. package/dist/fast-element.debug.min.js +2 -2
  91. package/dist/fast-element.js +392 -99
  92. package/dist/fast-element.min.js +2 -2
  93. package/dist/fast-element.untrimmed.d.ts +133 -70
  94. package/dist/hydration/hydration.api.json +1280 -57
  95. package/dist/styles/styles.api.json +1 -1
  96. package/package.json +21 -9
  97. package/ARCHITECTURE_FASTELEMENT.md +0 -63
  98. package/ARCHITECTURE_HTML_TAGGED_TEMPLATE_LITERAL.md +0 -36
  99. package/ARCHITECTURE_INTRO.md +0 -10
  100. package/ARCHITECTURE_OVERVIEW.md +0 -52
  101. package/ARCHITECTURE_UPDATES.md +0 -11
  102. package/CHANGELOG.json +0 -2275
  103. package/DECLARATIVE_DESIGN.md +0 -806
  104. package/DECLARATIVE_HTML.md +0 -470
  105. package/DECLARATIVE_MIGRATION.md +0 -215
  106. package/DECLARATIVE_RENDERING.md +0 -530
  107. package/DECLARATIVE_RENDERING_LIFECYCLE.md +0 -288
  108. package/DECLARATIVE_SCHEMA_OBSERVER_MAP.md +0 -489
  109. package/DESIGN.md +0 -615
  110. package/MIGRATION.md +0 -387
  111. package/SIZES.md +0 -25
  112. package/api-extractor.arrays.json +0 -15
  113. package/api-extractor.context.json +0 -15
  114. package/api-extractor.declarative.json +0 -15
  115. package/api-extractor.di.json +0 -15
  116. package/api-extractor.hydration.json +0 -15
  117. package/api-extractor.styles.json +0 -15
  118. package/biome.json +0 -4
  119. package/docs/ACKNOWLEDGEMENTS.md +0 -12
  120. package/docs/api-report.api.md +0 -1299
  121. package/docs/arrays/api-report.api.md +0 -114
  122. package/docs/context/api-report.api.md +0 -69
  123. package/docs/declarative/api-report.api.md +0 -397
  124. package/docs/di/api-report.api.md +0 -315
  125. package/docs/fast-element-2-changes.md +0 -15
  126. package/docs/hydration/api-report.api.md +0 -285
  127. package/docs/styles/api-report.api.md +0 -135
  128. package/playwright.config.ts +0 -26
  129. package/playwright.declarative.config.ts +0 -26
  130. package/playwright.declarative.webui.config.ts +0 -20
  131. package/scripts/declarative/build-fixtures-with-webui.js +0 -135
  132. package/scripts/declarative/build-fixtures.js +0 -49
  133. package/scripts/declarative/build-fixtures.utilities.js +0 -101
  134. package/scripts/measure-sizes.js +0 -219
  135. package/scripts/run-api-extractor.js +0 -70
  136. package/test/declarative/fixtures/README.md +0 -72
  137. package/test/declarative/fixtures/WRITING_FIXTURES.md +0 -330
  138. package/test/declarative/fixtures/bindings/README.md +0 -12
  139. package/test/declarative/fixtures/bindings/attribute/entry.html +0 -13
  140. package/test/declarative/fixtures/bindings/attribute/fast-build.config.json +0 -6
  141. package/test/declarative/fixtures/bindings/attribute/index.html +0 -25
  142. package/test/declarative/fixtures/bindings/attribute/main.ts +0 -41
  143. package/test/declarative/fixtures/bindings/attribute/state.json +0 -8
  144. package/test/declarative/fixtures/bindings/attribute/templates.html +0 -11
  145. package/test/declarative/fixtures/bindings/content/entry.html +0 -12
  146. package/test/declarative/fixtures/bindings/content/fast-build.config.json +0 -6
  147. package/test/declarative/fixtures/bindings/content/index.html +0 -19
  148. package/test/declarative/fixtures/bindings/content/main.ts +0 -27
  149. package/test/declarative/fixtures/bindings/content/state.json +0 -4
  150. package/test/declarative/fixtures/bindings/content/templates.html +0 -6
  151. package/test/declarative/fixtures/bindings/dot-syntax/entry.html +0 -11
  152. package/test/declarative/fixtures/bindings/dot-syntax/fast-build.config.json +0 -6
  153. package/test/declarative/fixtures/bindings/dot-syntax/index.html +0 -47
  154. package/test/declarative/fixtures/bindings/dot-syntax/main.ts +0 -59
  155. package/test/declarative/fixtures/bindings/dot-syntax/state.json +0 -16
  156. package/test/declarative/fixtures/bindings/dot-syntax/templates.html +0 -17
  157. package/test/declarative/fixtures/bindings/event/entry.html +0 -11
  158. package/test/declarative/fixtures/bindings/event/fast-build.config.json +0 -6
  159. package/test/declarative/fixtures/bindings/event/index.html +0 -43
  160. package/test/declarative/fixtures/bindings/event/main.ts +0 -43
  161. package/test/declarative/fixtures/bindings/event/state.json +0 -3
  162. package/test/declarative/fixtures/bindings/event/templates.html +0 -18
  163. package/test/declarative/fixtures/bindings/host/entry.html +0 -40
  164. package/test/declarative/fixtures/bindings/host/fast-build.config.json +0 -6
  165. package/test/declarative/fixtures/bindings/host/index.html +0 -96
  166. package/test/declarative/fixtures/bindings/host/main.ts +0 -222
  167. package/test/declarative/fixtures/bindings/host/state.json +0 -9
  168. package/test/declarative/fixtures/bindings/host/templates.html +0 -55
  169. package/test/declarative/fixtures/directives/README.md +0 -12
  170. package/test/declarative/fixtures/directives/children/entry.html +0 -11
  171. package/test/declarative/fixtures/directives/children/fast-build.config.json +0 -6
  172. package/test/declarative/fixtures/directives/children/index.html +0 -15
  173. package/test/declarative/fixtures/directives/children/main.ts +0 -22
  174. package/test/declarative/fixtures/directives/children/state.json +0 -3
  175. package/test/declarative/fixtures/directives/children/templates.html +0 -3
  176. package/test/declarative/fixtures/directives/ref/entry.html +0 -11
  177. package/test/declarative/fixtures/directives/ref/fast-build.config.json +0 -6
  178. package/test/declarative/fixtures/directives/ref/index.html +0 -15
  179. package/test/declarative/fixtures/directives/ref/main.ts +0 -17
  180. package/test/declarative/fixtures/directives/ref/state.json +0 -1
  181. package/test/declarative/fixtures/directives/ref/templates.html +0 -3
  182. package/test/declarative/fixtures/directives/repeat/entry.html +0 -21
  183. package/test/declarative/fixtures/directives/repeat/fast-build.config.json +0 -6
  184. package/test/declarative/fixtures/directives/repeat/index.html +0 -133
  185. package/test/declarative/fixtures/directives/repeat/main.ts +0 -110
  186. package/test/declarative/fixtures/directives/repeat/sprites.svg +0 -8
  187. package/test/declarative/fixtures/directives/repeat/state.json +0 -10
  188. package/test/declarative/fixtures/directives/repeat/templates.html +0 -75
  189. package/test/declarative/fixtures/directives/slotted/entry.html +0 -17
  190. package/test/declarative/fixtures/directives/slotted/fast-build.config.json +0 -6
  191. package/test/declarative/fixtures/directives/slotted/index.html +0 -27
  192. package/test/declarative/fixtures/directives/slotted/main.ts +0 -29
  193. package/test/declarative/fixtures/directives/slotted/state.json +0 -1
  194. package/test/declarative/fixtures/directives/slotted/templates.html +0 -7
  195. package/test/declarative/fixtures/directives/when/entry.html +0 -51
  196. package/test/declarative/fixtures/directives/when/fast-build.config.json +0 -6
  197. package/test/declarative/fixtures/directives/when/index.html +0 -136
  198. package/test/declarative/fixtures/directives/when/main.ts +0 -172
  199. package/test/declarative/fixtures/directives/when/state.json +0 -12
  200. package/test/declarative/fixtures/directives/when/templates.html +0 -75
  201. package/test/declarative/fixtures/ecosystem/README.md +0 -11
  202. package/test/declarative/fixtures/ecosystem/declarative-no-hydration/entry.html +0 -12
  203. package/test/declarative/fixtures/ecosystem/declarative-no-hydration/fast-build.config.json +0 -6
  204. package/test/declarative/fixtures/ecosystem/declarative-no-hydration/index.html +0 -20
  205. package/test/declarative/fixtures/ecosystem/declarative-no-hydration/main.ts +0 -68
  206. package/test/declarative/fixtures/ecosystem/declarative-no-hydration/state.json +0 -4
  207. package/test/declarative/fixtures/ecosystem/declarative-no-hydration/templates.html +0 -7
  208. package/test/declarative/fixtures/ecosystem/errors/entry.html +0 -12
  209. package/test/declarative/fixtures/ecosystem/errors/fast-build.config.json +0 -6
  210. package/test/declarative/fixtures/ecosystem/errors/index.html +0 -20
  211. package/test/declarative/fixtures/ecosystem/errors/main.ts +0 -17
  212. package/test/declarative/fixtures/ecosystem/errors/state.json +0 -1
  213. package/test/declarative/fixtures/ecosystem/errors/templates.html +0 -7
  214. package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/entry.html +0 -17
  215. package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/fast-build.config.json +0 -6
  216. package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/index.html +0 -56
  217. package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/main.ts +0 -134
  218. package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/state.json +0 -12
  219. package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/templates.html +0 -34
  220. package/test/declarative/fixtures/ecosystem/performance-metrics/entry.html +0 -25
  221. package/test/declarative/fixtures/ecosystem/performance-metrics/fast-build.config.json +0 -6
  222. package/test/declarative/fixtures/ecosystem/performance-metrics/fast-card.css +0 -10
  223. package/test/declarative/fixtures/ecosystem/performance-metrics/index.html +0 -181
  224. package/test/declarative/fixtures/ecosystem/performance-metrics/main.ts +0 -58
  225. package/test/declarative/fixtures/ecosystem/performance-metrics/state.json +0 -6
  226. package/test/declarative/fixtures/ecosystem/performance-metrics/templates.html +0 -15
  227. package/test/declarative/fixtures/extensions/README.md +0 -15
  228. package/test/declarative/fixtures/extensions/attribute-map/entry.html +0 -14
  229. package/test/declarative/fixtures/extensions/attribute-map/fast-build.config.json +0 -6
  230. package/test/declarative/fixtures/extensions/attribute-map/index.html +0 -31
  231. package/test/declarative/fixtures/extensions/attribute-map/main.ts +0 -40
  232. package/test/declarative/fixtures/extensions/attribute-map/state.json +0 -4
  233. package/test/declarative/fixtures/extensions/attribute-map/templates.html +0 -14
  234. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/entry.html +0 -12
  235. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/fast-build.config.json +0 -7
  236. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/index.html +0 -25
  237. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/main.ts +0 -31
  238. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/state.json +0 -5
  239. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/templates.html +0 -11
  240. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/entry.html +0 -13
  241. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/fast-build.config.json +0 -7
  242. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/index.html +0 -23
  243. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/main.ts +0 -37
  244. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/state.json +0 -1
  245. package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/templates.html +0 -9
  246. package/test/declarative/fixtures/extensions/observer-map/entry.html +0 -15
  247. package/test/declarative/fixtures/extensions/observer-map/fast-build.config.json +0 -6
  248. package/test/declarative/fixtures/extensions/observer-map/index.html +0 -442
  249. package/test/declarative/fixtures/extensions/observer-map/main.ts +0 -482
  250. package/test/declarative/fixtures/extensions/observer-map/state.json +0 -158
  251. package/test/declarative/fixtures/extensions/observer-map/templates.html +0 -172
  252. package/test/declarative/fixtures/extensions/observer-map-config-object/entry.html +0 -16
  253. package/test/declarative/fixtures/extensions/observer-map-config-object/fast-build.config.json +0 -6
  254. package/test/declarative/fixtures/extensions/observer-map-config-object/index.html +0 -27
  255. package/test/declarative/fixtures/extensions/observer-map-config-object/main.ts +0 -53
  256. package/test/declarative/fixtures/extensions/observer-map-config-object/state.json +0 -9
  257. package/test/declarative/fixtures/extensions/observer-map-config-object/templates.html +0 -12
  258. package/test/declarative/fixtures/extensions/observer-map-deep-merge/README.md +0 -98
  259. package/test/declarative/fixtures/extensions/observer-map-deep-merge/entry.html +0 -156
  260. package/test/declarative/fixtures/extensions/observer-map-deep-merge/fast-build.config.json +0 -6
  261. package/test/declarative/fixtures/extensions/observer-map-deep-merge/index.html +0 -376
  262. package/test/declarative/fixtures/extensions/observer-map-deep-merge/main.ts +0 -366
  263. package/test/declarative/fixtures/extensions/observer-map-deep-merge/state.json +0 -69
  264. package/test/declarative/fixtures/extensions/observer-map-deep-merge/templates.html +0 -91
  265. package/test/declarative/fixtures/extensions/observer-map-properties/entry.html +0 -14
  266. package/test/declarative/fixtures/extensions/observer-map-properties/fast-build.config.json +0 -6
  267. package/test/declarative/fixtures/extensions/observer-map-properties/index.html +0 -110
  268. package/test/declarative/fixtures/extensions/observer-map-properties/main.ts +0 -175
  269. package/test/declarative/fixtures/extensions/observer-map-properties/state.json +0 -29
  270. package/test/declarative/fixtures/extensions/observer-map-properties/templates.html +0 -55
  271. package/test/declarative/fixtures/scenarios/README.md +0 -7
  272. package/test/declarative/fixtures/scenarios/nested-elements/entry.html +0 -16
  273. package/test/declarative/fixtures/scenarios/nested-elements/fast-build.config.json +0 -6
  274. package/test/declarative/fixtures/scenarios/nested-elements/index.html +0 -126
  275. package/test/declarative/fixtures/scenarios/nested-elements/main.ts +0 -214
  276. package/test/declarative/fixtures/scenarios/nested-elements/state.json +0 -10
  277. package/test/declarative/fixtures/scenarios/nested-elements/templates.html +0 -54
  278. package/test/declarative/index.html +0 -12
  279. package/test/declarative/vite.config.ts +0 -55
  280. package/test/declarative-main.ts +0 -6
  281. package/test/extension-subpaths-main.ts +0 -9
  282. package/test/index.html +0 -11
  283. package/test/main.ts +0 -109
  284. package/test/pure-declarative-main.ts +0 -1
  285. package/test/vite.config.ts +0 -19
  286. package/tsconfig.api-extractor.json +0 -6
@@ -1,530 +0,0 @@
1
- # Non-browser HTML rendering
2
-
3
- 1. [Initial State](#initial-state)
4
- 2. [Hydrating Comments and Datasets](#hydration-comments-and-datasets)
5
-
6
- This document details information on rendering hydratable content and includes some pointers on how Dependency Injection can be used to create services that hydrate a custom elements state.
7
-
8
- ## Initial State
9
-
10
- To create initial state this should be added somewhere accessible by your service, in this example a `<script>` tag can be used to provide a global initial state.
11
-
12
- Example:
13
- ```html
14
- <script>
15
- window.__INITIAL_STATE__ = {
16
- text: "Hello world"
17
- }
18
- </script>
19
- ```
20
-
21
- Add a Dependency Injection service in your bundle to access properties in your state.
22
-
23
- Simple example (`initial-state.ts`):
24
- ```typescript
25
- import { DI } from "@microsoft/fast-element/di.js";
26
-
27
- interface InitialState {
28
- text: string;
29
- }
30
-
31
- export interface IInitialStateService {
32
- init(): InitialState;
33
- }
34
-
35
- export class InitialStateService implements IInitialStateService {
36
- private initialState: any;
37
-
38
- constructor() {
39
- this.initialState = window.__INITIAL_STATE__;
40
- }
41
-
42
- public init(...keys: Array<string>): InitialState {
43
- const config: any = {};
44
-
45
- for (let key of keys) {
46
- config[key] = this.initialState[key];
47
- }
48
-
49
- return config;
50
- }
51
- }
52
-
53
- export const initialStateFactory = DI.createContext<IInitialStateService>(
54
- 'i-initial-state-service',
55
- (x) => x.singleton(InitialStateService)
56
- );
57
- ```
58
-
59
- Include the DI service to your component.
60
-
61
- Example:
62
- ```typescript
63
- import { attr, FASTElement, Observable } from "@microsoft/fast-element";
64
- import {
65
- initialStateFactory,
66
- InitialStateService,
67
- type IInitialStateService,
68
- } from "./initial-state.js";
69
- import { inject } from "@microsoft/fast-element/di.js";
70
-
71
- export class MyComponent extends FASTElement {
72
- @inject(initialStateFactory) initialStateService!: InitialStateService;
73
-
74
- @attr
75
- text: string = "";
76
-
77
- service!: IInitialStateService;
78
-
79
- connectedCallback() {
80
- super.connectedCallback();
81
-
82
- this.loadItemFromInitialState();
83
- }
84
-
85
- loadItemFromInitialState(): void {
86
- const initialState = this.initialStateService.init(["text"]);
87
-
88
- this.text = initialState.text;
89
- }
90
- }
91
-
92
- MyComponent.define({
93
- name: "my-component",
94
- template: declarativeTemplate(),
95
- });
96
- ```
97
-
98
- When the element connects, `ElementController` automatically detects the
99
- existing shadow root from SSR and sets `isPrerendered = true`.
100
- `declarativeTemplate()` keeps the definition template concrete before
101
- registration completes, so the element can hydrate the prerendered shadow root
102
- immediately. The `defer-hydration` and `needs-hydration` attributes are no
103
- longer needed.
104
-
105
- ## Hydration Comments and Datasets
106
-
107
- When hydrating the HTML, FAST uses `ElementController` which detects an
108
- existing shadow root (from SSR or declarative shadow DOM) and sets
109
- `isPrerendered = true`. It then uses `template.hydrate()` to create a
110
- `HydrationView` that maps existing DOM nodes to binding targets using hydration
111
- "markers" such as comments and dataset attributes. By default the declarative
112
- runtime in `@microsoft/fast-element` assumes component hydration will occur, so
113
- rendering hydratable markup is required.
114
-
115
- ### Bindings
116
-
117
- #### Content Bindings
118
-
119
- Content binding markers are represented using HTML comments. These comments are used to indicate where dynamic content exists in the template. Markers carry no embedded data — they are fixed strings matched by string equality (not regex).
120
-
121
- * Start binding: `<!--fe:b-->`
122
- * End binding: `<!--fe:/b-->`
123
-
124
- Binding pairs are matched using balanced depth counting: each start marker increments a depth counter and each end marker decrements it. When the counter returns to zero the pair is complete.
125
-
126
- ##### Content Binding Marker Examples
127
-
128
- **Note**
129
- Examples shown below mostly skip the wrapping custom element and the internal template element with `shadowrootmode="open"`.
130
-
131
- Typically along with the content from the examples below, the rendering should include:
132
-
133
- ```html
134
- <my-component>
135
- <template shadowrootmode="open" shadowroot="open">
136
- <!-- hydratable content -->
137
- </template>
138
- </my-component>
139
- ```
140
-
141
- **Simple content example**
142
-
143
- Content bindings such as:
144
- ```html
145
- <h1>{{text}}</h1>
146
- ```
147
-
148
- When combined with state such as:
149
- ```json
150
- {
151
- "text": "Hello world"
152
- }
153
- ```
154
-
155
- Should result in:
156
- ```html
157
- <h1><!--fe:b-->Hello world<!--fe:/b--></h1>
158
- ```
159
-
160
- #### Attribute Bindings
161
-
162
- Attribute bindings are tracked using a single dataset attribute: `data-fe="N"` where `N` is the number of attribute bindings on the element.
163
-
164
- ##### Examples
165
-
166
- ###### Single attribute example
167
-
168
- Attribute binding such as:
169
- ```html
170
- <h1 greeting="{{greeting}}"></h1>
171
- ```
172
-
173
- When combined with state such as:
174
- ```json
175
- {
176
- "greeting": "Hello"
177
- }
178
- ```
179
-
180
- Should result in:
181
-
182
- ```html
183
- <h1 data-fe="1" greeting="Hello"></h1>
184
- ```
185
-
186
- ###### Multiple attribute bindings
187
-
188
- When multiple attribute bindings exist on the same element:
189
- ```html
190
- <h1 greeting="{{greeting}}" subtitle="{{subtitle}}" punctuation="{{punctuation}}"></h1>
191
- ```
192
-
193
- When combined with state such as:
194
- ```json
195
- {
196
- "greeting": "Hello",
197
- "subtitle": "world",
198
- "punctuation": "!"
199
- }
200
- ```
201
-
202
- Should result in:
203
-
204
- ```html
205
- <h1 data-fe="3" greeting="Hello" subtitle="world" punctuation="!"></h1>
206
- ```
207
-
208
- **Mixed attribute and content example**
209
-
210
- Multiple attributes and content bindings such as:
211
- ```html
212
- <div show="{{show}}" appearance="{{appearance}}" punctuation="{{punctuation}}">
213
- <h1>{{text}}</h1>
214
- <span>{{subtitle}}</span>
215
- <span>{{punctuation}}</span>
216
- </div>
217
- ```
218
-
219
- Should result in:
220
- ```html
221
- <div data-fe="3" show appearance="large" punctuation="!">
222
- <h1><!--fe:b-->Hello<!--fe:/b--></h1>
223
- <span><!--fe:b-->world<!--fe:/b--></span>
224
- <span><!--fe:b-->!<!--fe:/b--></span>
225
- </div>
226
- ```
227
-
228
- ### Directives
229
-
230
- Directives are treated differently from bindings as they include a template. This means that in addition to the binding used to determine the logic for the directive FAST also requires a separate marker for the directive itself to demarkate the beginning and end of the template.
231
-
232
- #### Repeat
233
-
234
- Example repeat binding:
235
- ```html
236
- <f-repeat value="{{item in list}}">
237
- <span>{{item}}</span>
238
- </f-repeat>
239
- ```
240
-
241
- Combined with state:
242
- ```json
243
- [
244
- "Bob",
245
- "Alice",
246
- "Sue"
247
- ]
248
- ```
249
-
250
- Should result in:
251
- ```html
252
- <!--fe:b-->
253
- <!--fe:r-->
254
- <span>
255
- <!--fe:b-->Bob<!--fe:/b-->
256
- </span>
257
- <!--fe:/r-->
258
- <!--fe:r-->
259
- <span>
260
- <!--fe:b-->Alice<!--fe:/b-->
261
- </span>
262
- <!--fe:/r-->
263
- <!--fe:r-->
264
- <span>
265
- <!--fe:b-->Sue<!--fe:/b-->
266
- </span>
267
- <!--fe:/r-->
268
- <!--fe:/b-->
269
- ```
270
-
271
- Note that the repeat markers are data-free — they carry no index or ID. Pairing uses balanced depth counting. Additionally, a binding wraps the repeat markers; even if the array is empty, this binding must be rendered.
272
-
273
- Example result of an empty array:
274
- ```html
275
- <!--fe:b-->
276
- <!--fe:/b-->
277
- ```
278
-
279
- #### When
280
-
281
- The when directive is either present in the DOM or not, and therefore does not need an extra marker for the template.
282
-
283
- Example when binding:
284
- ```html
285
- <f-when value="{{show}}">
286
- <span>{{text}}</span>
287
- </f-when>
288
- ```
289
-
290
- Combined with state:
291
- ```json
292
- {
293
- "show": true,
294
- "text": "Hello world"
295
- }
296
- ```
297
-
298
- Should result in:
299
- ```html
300
- <!--fe:b-->
301
- <span>
302
- <!--fe:b-->Hello world<!--fe:/b-->
303
- </span>
304
- <!--fe:/b-->
305
- ```
306
-
307
- If the when is evaluated to `falsy` then we can safely leave the binding markers only.
308
-
309
- Example state:
310
- ```json
311
- {
312
- "show": false,
313
- "text": "Hello world"
314
- }
315
- ```
316
-
317
- Should result in:
318
- ```html
319
- <!--fe:b-->
320
- <!--fe:/b-->
321
- ```
322
-
323
- ### Client Side Bindings
324
-
325
- Client side bindings are bindings which the client needs, but they are not necessary as part of an initial render. These must still be accounted for when creating hydration comments however, as the template needs to know which elements to attach these bindings to. There are two types of client side bindings, events and attribute directives. These do not require state as they are bound to class methods or properties.
326
-
327
- #### Event Bindings
328
-
329
- Event bindings such as `@keydown` and `@click` can be represented with hydration comments.
330
-
331
- Example event binding:
332
- ```html
333
- <button @click="{handleClick($e)}">Button</button>
334
- ```
335
-
336
- Should result in:
337
- ```html
338
- <button data-fe="1">Button</button>
339
- ```
340
-
341
- #### Attribute Directives
342
-
343
- Attribute directives such as `f-slotted` and `f-ref` can be represented with hydration comments.
344
-
345
- Example `f-ref` binding:
346
- ```html
347
- <button f-ref="{button}">Button</button>
348
- ```
349
-
350
- Should result in:
351
- ```html
352
- <button data-fe="1">Button</button>
353
- ```
354
-
355
- #### More Examples
356
-
357
- ##### Nested Whens
358
-
359
- Example when binding:
360
- ```html
361
- <f-when value="{{show}}">
362
- <span>{{text}}</span>
363
- <f-when value="{{showInternal}}">
364
- <span>{{internalText}}</span>
365
- </f-when>
366
- </f-when>
367
- ```
368
-
369
- Combined with state:
370
- ```json
371
- {
372
- "show": true,
373
- "text": "Hello world",
374
- "showInternal": true,
375
- "internalText": "Hello pluto"
376
- }
377
- ```
378
-
379
- Should result in:
380
- ```html
381
- <!--fe:b-->
382
- <span>
383
- <!--fe:b-->Hello world<!--fe:/b-->
384
- </span>
385
- <!--fe:b-->
386
- <span>
387
- <!--fe:b-->Hello pluto<!--fe:/b-->
388
- </span>
389
- <!--fe:/b-->
390
- <!--fe:/b-->
391
- ```
392
-
393
- ##### Nested Repeats
394
-
395
- Example when binding:
396
- ```html
397
- <f-repeat value="{{item in items}}">
398
- <div>
399
- <span>{{item.name}}</span>
400
- <f-when value="{{!!item.nested}}">
401
- <ul>
402
- <f-repeat value="{{person in item.nested}}">
403
- <li>{{person.name}}</li>
404
- </f-repeat>
405
- </ul>
406
- </f-when>
407
- </div>
408
- </f-repeat>
409
- ```
410
-
411
- Combined with state:
412
- ```json
413
- {
414
- "items": [
415
- {
416
- "name": "Bob"
417
- },
418
- {
419
- "name": "Alice"
420
- },
421
- {
422
- "name": "Sue",
423
- "nested": [
424
- {
425
- "name": "Amy"
426
- },
427
- {
428
- "name": "Clarice"
429
- },
430
- {
431
- "name": "Lawrence"
432
- }
433
- ]
434
- }
435
- ]
436
- }
437
- ```
438
-
439
- Should result in:
440
- ```html
441
- <!--fe:b-->
442
- <!--fe:r-->
443
- <div>
444
- <span><!--fe:b-->Bob<!--fe:/b--></span>
445
- <!--fe:b--><!--fe:/b-->
446
- </div>
447
- <!--fe:/r--><!--fe:r-->
448
- <div>
449
- <span><!--fe:b-->Alice<!--fe:/b--></span>
450
- <!--fe:b--><!--fe:/b-->
451
- </div>
452
- <!--fe:/r--><!--fe:r-->
453
- <div>
454
- <span><!--fe:b-->Sue<!--fe:/b--></span>
455
- <!--fe:b-->
456
- <ul>
457
- <!--fe:b-->
458
- <!--fe:r-->
459
- <li>
460
- <!--fe:b-->Amy<!--fe:/b-->
461
- </li>
462
- <!--fe:/r-->
463
- <!--fe:r-->
464
- <li>
465
- <!--fe:b-->Clarice<!--fe:/b-->
466
- </li>
467
- <!--fe:/r-->
468
- <!--fe:r-->
469
- <li>
470
- <!--fe:b-->Lawrence<!--fe:/b-->
471
- </li>
472
- <!--fe:/r-->
473
- <!--fe:/b-->
474
- </ul>
475
- <!--fe:/b-->
476
- </div>
477
- <!--fe:/r-->
478
- <!--fe:/b-->
479
- ```
480
-
481
- ##### Nested components with `<slot>`
482
-
483
- This example shows the wrapping custom element tag as well as the template component with `shadowrootmode="open"` for the sake of illustrating an example that would exist in the DOM.
484
-
485
- Example template of component "nested-component":
486
- ```html
487
- <f-when value="{{showButton}}">
488
- <my-button appearance="{{appearance}}">{{text}}</my-button>
489
- </f-when>
490
- ```
491
-
492
- Example template of component "my-button":
493
- ```html
494
- <button class="{{appearance}}">
495
- <slot></slot>
496
- </button>
497
- ```
498
-
499
- Combined with state:
500
- ```json
501
- {
502
- "showButton": true,
503
- "text": "Hello world",
504
- "appearance": "fancy"
505
- }
506
- ```
507
-
508
- Should result in:
509
- ```html
510
- <nested-components>
511
- <template shadowrootmode="open" shadowroot="open">
512
- <!--fe:b-->
513
- <my-button data-fe="1" appearance="fancy">
514
- <template shadowrootmode="open" shadowroot="open">
515
- <button class="default" data-fe="1">
516
- <slot></slot>
517
- </button>
518
- </template>
519
- <!--fe:b-->Hello world<!--fe:/b-->
520
- </my-button>
521
- <!--fe:/b-->
522
- </template>
523
- </nested-components>
524
- ```
525
-
526
- ## Rendering Lifecycle
527
-
528
- For information about the declarative rendering lifecycle inside
529
- `@microsoft/fast-element`, see
530
- [DECLARATIVE_RENDERING_LIFECYCLE.md](./DECLARATIVE_RENDERING_LIFECYCLE.md).