Skip to content

Commit 4656c46

Browse files
authored
chore: remove hydratable view and unused code (#7489)
# Pull Request ## 📖 Description This change removes the hydratable views side effects exports, incorporates them into the declarative templating and removes some unused code. ## ✅ Checklist ### General - [x] I have included a change request file using `$ npm run change` - [ ] 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.
1 parent f01136d commit 4656c46

28 files changed

Lines changed: 105 additions & 170 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Remove hydration view template side effect and unused export paths",
4+
"packageName": "@microsoft/fast-element",
5+
"email": "7559015+janechu@users.noreply.github.com",
6+
"dependentChangeType": "none"
7+
}

change/@microsoft-fast-element-1776500147.json renamed to change/@microsoft-fast-element-61e3e3bd-e227-4449-9ff6-8edc104819d8.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"type": "major",
33
"comment": "Replace HydratableElementController with automatic prerendered content optimization. When a component connects with an existing shadow root, bindings skip attribute/booleanAttribute DOM updates during initial render while still setting up event listeners, observers, and dependency tracking. Added isPrerendered flag to ElementController and ViewController. Added template-pending guard for defineAsync flow.",
44
"packageName": "@microsoft/fast-element",
5-
"email": "janechu@microsoft.com",
5+
"email": "7559015+janechu@users.noreply.github.com",
66
"dependentChangeType": "patch"
77
}

change/@microsoft-fast-element-move-declarative-html.json renamed to change/@microsoft-fast-element-61e3e3bd-e227-4449-9ff6-8edc104819d9.json

File renamed without changes.

packages/fast-element/SIZES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Bundle sizes for `@microsoft/fast-element` exports.
44

55
| Export | Minified | Gzip | Brotli |
66
|--------|----------|------|--------|
7-
| CDN Rollup Bundle | 62.60 KB | 18.64 KB | 16.77 KB |
7+
| CDN Rollup Bundle | 62.60 KB | 18.64 KB | 16.75 KB |
88
| FASTElement | 22.88 KB | 7.14 KB | 6.46 KB |
99
| Updates | 3.03 KB | 1.25 KB | 1.06 KB |
1010
| Observable | 7.55 KB | 2.76 KB | 2.48 KB |

packages/fast-element/docs/api-report.api.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ export type Callable = typeof Function.prototype.call | {
109109
};
110110

111111
// @public
112-
export interface CaptureType<TSource, TParent> {
112+
export interface CaptureType {
113113
}
114114

115115
// @public
116116
export interface ChildListDirectiveOptions<T = any> extends NodeBehaviorOptions<T>, Omit<MutationObserverInit, "subtree" | "childList"> {
117117
}
118118

119119
// @public
120-
export function children<TSource = any, TParent = any>(propertyOrOptions: (keyof TSource & string) | ChildrenDirectiveOptions<keyof TSource & string>): CaptureType<TSource, TParent>;
120+
export function children<TSource = any>(propertyOrOptions: (keyof TSource & string) | ChildrenDirectiveOptions<keyof TSource & string>): CaptureType;
121121

122122
// @public
123123
export class ChildrenDirective extends NodeObservationDirective<ChildrenDirectiveOptions> {
@@ -753,7 +753,7 @@ export class PropertyChangeNotifier implements Notifier {
753753
}
754754

755755
// @public
756-
export const ref: <TSource = any, TParent = any>(propertyName: keyof TSource & string) => CaptureType<TSource, TParent>;
756+
export const ref: <TSource = any>(propertyName: keyof TSource & string) => CaptureType;
757757

758758
// @public
759759
export class RefDirective extends StatelessAttachedAttributeDirective<string> {
@@ -762,7 +762,7 @@ export class RefDirective extends StatelessAttachedAttributeDirective<string> {
762762
}
763763

764764
// @public
765-
export function render<TSource = any, TItem = any, TParent = any>(value?: Expression<TSource, TItem> | Binding<TSource, TItem> | {}, template?: ContentTemplate | string | Expression<TSource, ContentTemplate | string | Node, TParent> | Binding<TSource, ContentTemplate | string | Node, TParent>): CaptureType<TSource, TParent>;
765+
export function render<TSource = any, TItem = any, TParent = any>(value?: Expression<TSource, TItem> | Binding<TSource, TItem> | {}, template?: ContentTemplate | string | Expression<TSource, ContentTemplate | string | Node, TParent> | Binding<TSource, ContentTemplate | string | Node, TParent>): CaptureType;
766766

767767
// @public
768768
export class RenderBehavior<TSource = any> implements ViewBehavior, Subscriber {
@@ -788,7 +788,7 @@ export class RenderDirective<TSource = any> implements HTMLDirective, ViewBehavi
788788
}
789789

790790
// @public
791-
export function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any>, TParent = any>(items: Expression<TSource, TArray, TParent> | Binding<TSource, TArray, TParent> | ReadonlyArray<any>, template: Expression<TSource, ViewTemplate<any, TSource>> | Binding<TSource, ViewTemplate<any, TSource>> | ViewTemplate<any, TSource>, options?: RepeatOptions): CaptureType<TSource, TParent>;
791+
export function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any>, TParent = any>(items: Expression<TSource, TArray, TParent> | Binding<TSource, TArray, TParent> | ReadonlyArray<any>, template: Expression<TSource, ViewTemplate<any, TSource>> | Binding<TSource, ViewTemplate<any, TSource>> | ViewTemplate<any, TSource>, options?: RepeatOptions): CaptureType;
792792

793793
// @public
794794
export class RepeatBehavior<TSource = any> implements ViewBehavior, Subscriber {
@@ -827,7 +827,7 @@ export interface ShadowRootOptions extends ShadowRootInit {
827827
}
828828

829829
// @public
830-
export function slotted<TSource = any, TParent = any>(propertyOrOptions: (keyof TSource & string) | SlottedDirectiveOptions<keyof TSource & string>): CaptureType<TSource, TParent>;
830+
export function slotted<TSource = any>(propertyOrOptions: (keyof TSource & string) | SlottedDirectiveOptions<keyof TSource & string>): CaptureType;
831831

832832
// @public
833833
export class SlottedDirective extends NodeObservationDirective<SlottedDirectiveOptions> {
@@ -972,7 +972,7 @@ export interface SyntheticView<TSource = any, TParent = any> extends View<TSourc
972972
// @public
973973
export interface SyntheticViewTemplate<TSource = any, TParent = any> {
974974
create(): SyntheticView<TSource, TParent>;
975-
inline(): CaptureType<TSource, TParent>;
975+
inline(): CaptureType;
976976
}
977977

978978
// @public
@@ -990,7 +990,7 @@ export const TemplateOptions: {
990990
export type TemplateOptions = (typeof TemplateOptions)[keyof typeof TemplateOptions];
991991

992992
// @public
993-
export type TemplateValue<TSource, TParent = any> = Expression<TSource, any, TParent> | Binding<TSource, any, TParent> | HTMLDirective | CaptureType<TSource, TParent>;
993+
export type TemplateValue<TSource, TParent = any> = Expression<TSource, any, TParent> | Binding<TSource, any, TParent> | HTMLDirective | CaptureType;
994994

995995
// @public
996996
export type TrustedTypesPolicy = {
@@ -1072,7 +1072,7 @@ export class ViewTemplate<TSource = any, TParent = any> implements ElementViewTe
10721072
static create<TSource = any, TParent = any>(strings: string[], values: TemplateValue<TSource, TParent>[], policy?: DOMPolicy): ViewTemplate<TSource, TParent>;
10731073
readonly factories: Record<string, ViewBehaviorFactory>;
10741074
readonly html: string | HTMLTemplateElement;
1075-
inline(): CaptureType<TSource, TParent>;
1075+
inline(): CaptureType;
10761076
render(source: TSource, host: Node, hostBindingTarget?: Element): HTMLView<TSource, TParent>;
10771077
withPolicy(policy: DOMPolicy): this;
10781078
}
@@ -1081,7 +1081,7 @@ export class ViewTemplate<TSource = any, TParent = any> implements ElementViewTe
10811081
export function volatile(target: {}, name: string | Accessor, descriptor: PropertyDescriptor): PropertyDescriptor;
10821082

10831083
// @public
1084-
export function when<TSource = any, TReturn = any, TParent = any>(condition: Expression<TSource, TReturn, TParent> | boolean, templateOrTemplateBinding: SyntheticViewTemplate<TSource, TParent> | Expression<TSource, SyntheticViewTemplate<TSource, TParent>, TParent>, elseTemplateOrTemplateBinding?: SyntheticViewTemplate<TSource, TParent> | Expression<TSource, SyntheticViewTemplate<TSource, TParent>, TParent>): CaptureType<TSource, TParent>;
1084+
export function when<TSource = any, TReturn = any, TParent = any>(condition: Expression<TSource, TReturn, TParent> | boolean, templateOrTemplateBinding: SyntheticViewTemplate<TSource, TParent> | Expression<TSource, SyntheticViewTemplate<TSource, TParent>, TParent>, elseTemplateOrTemplateBinding?: SyntheticViewTemplate<TSource, TParent> | Expression<TSource, SyntheticViewTemplate<TSource, TParent>, TParent>): CaptureType;
10851085

10861086
// Warnings were encountered during analysis:
10871087
//

packages/fast-element/package.json

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,10 @@
6464
"types": "./dist/dts/context.d.ts",
6565
"default": "./dist/esm/context.js"
6666
},
67-
"./metadata.js": {
68-
"types": "./dist/dts/metadata.d.ts",
69-
"default": "./dist/esm/metadata.js"
70-
},
71-
"./testing.js": {
72-
"types": "./dist/dts/testing/exports.d.ts",
73-
"default": "./dist/esm/testing/exports.js"
74-
},
7567
"./di.js": {
7668
"types": "./dist/dts/di/di.d.ts",
7769
"default": "./dist/esm/di/di.js"
7870
},
79-
"./element-hydration.js": {
80-
"types": "./dist/dts/components/hydration.d.ts",
81-
"default": "./dist/esm/components/hydration.js"
82-
},
83-
"./install-element-hydration.js": {
84-
"types": "./dist/dts/components/install-hydration.d.ts",
85-
"default": "./dist/esm/components/install-hydration.js"
86-
},
87-
"./install-hydratable-view-templates.js": {
88-
"types": "./dist/dts/templating/install-hydratable-view-templates.d.ts",
89-
"default": "./dist/esm/templating/install-hydratable-view-templates.js"
90-
},
91-
"./pending-task.js": {
92-
"types": "./dist/dts/pending-task.d.ts",
93-
"default": "./dist/esm/pending-task.js"
94-
},
9571
"./dom-policy.js": {
9672
"types": "./dist/dts/dom-policy.d.ts",
9773
"default": "./dist/esm/dom-policy.js"
@@ -107,8 +83,6 @@
10783
"./dist/esm/debug.js",
10884
"./dist/esm/declarative.js",
10985
"./dist/esm/polyfills.js",
110-
"./dist/esm/components/install-hydration.js",
111-
"./dist/esm/templating/install-hydratable-view-templates.js",
11286
"./dist/esm/interfaces.js"
11387
],
11488
"scripts": {

packages/fast-element/src/components/install-hydration.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/fast-element/src/declarative.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1+
import { Hydratable } from "./components/hydration.js";
12
import { debugMessages } from "./declarative/debug.js";
23
import { FAST } from "./platform.js";
3-
import "./templating/install-hydratable-view-templates.js";
4+
import { ViewTemplate } from "./templating/template.js";
5+
import { HydrationView } from "./templating/view.js";
6+
7+
// Configure ViewTemplate to be hydratable by attaching a symbol identifier
8+
// and a hydrate method. Augmenting the hydration features is done by
9+
// property assignment instead of class extension to better allow the
10+
// hydration feature to be tree-shaken.
11+
//
12+
// When hydrate() is called, it creates a HydrationView that wraps the
13+
// pre-rendered DOM range (firstChild → lastChild) instead of cloning a
14+
// compiled DocumentFragment. The HydrationView will then use
15+
// buildViewBindingTargets() to scan for hydration markers and attach
16+
// reactive bindings to the existing DOM nodes.
17+
Object.defineProperties(ViewTemplate.prototype, {
18+
[Hydratable]: { value: Hydratable, enumerable: false, configurable: false },
19+
hydrate: {
20+
value: function (
21+
this: ViewTemplate,
22+
firstChild: Node,
23+
lastChild: Node,
24+
hostBindingTarget?: Element,
25+
): HydrationView {
26+
return new HydrationView(firstChild, lastChild, this, hostBindingTarget);
27+
},
28+
enumerable: true,
29+
configurable: false,
30+
},
31+
});
432

533
FAST.addMessages(debugMessages);
634

packages/fast-element/src/pending-task.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

packages/fast-element/src/templating/children.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ HTMLDirective.define(ChildrenDirective);
106106
* @param propertyOrOptions - The options used to configure child node observation.
107107
* @public
108108
*/
109-
export function children<TSource = any, TParent = any>(
109+
export function children<TSource = any>(
110110
propertyOrOptions:
111111
| (keyof TSource & string)
112-
| ChildrenDirectiveOptions<keyof TSource & string>
113-
): CaptureType<TSource, TParent> {
112+
| ChildrenDirectiveOptions<keyof TSource & string>,
113+
): CaptureType {
114114
if (isString(propertyOrOptions)) {
115115
propertyOrOptions = {
116116
property: propertyOrOptions,

0 commit comments

Comments
 (0)