Skip to content

Commit

Permalink
Update due to merge conflicts, test memory leak issue
Browse files Browse the repository at this point in the history
  • Loading branch information
janechu committed Sep 24, 2024
1 parent 913c27e commit 03e6e39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix memory leak due to binding observers",
"packageName": "@microsoft/fast-foundation",
"email": "7282195+m-akinc@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export interface CSSDesignToken<
| ({
createCSS?(): string;
} & Record<PropertyKey, any>)
> extends DesignToken<T>, CSSDirective {
> extends DesignToken<T>,
CSSDirective {
/**
* The {@link (DesignToken:interface)} formatted as a CSS custom property if the token is
* configured to write a CSS custom property.
Expand Down Expand Up @@ -128,8 +129,10 @@ export interface DesignTokenSubscriber<T extends DesignToken<any>> {
/**
* Implementation of {@link (DesignToken:interface)}
*/
class DesignTokenImpl<T extends { createCSS?(): string }> extends CSSDirective
implements DesignToken<T> {
class DesignTokenImpl<T extends { createCSS?(): string }>
extends CSSDirective
implements DesignToken<T>
{
public readonly name: string;
public readonly cssCustomProperty: string | undefined;
public readonly id: string;
Expand Down Expand Up @@ -314,8 +317,8 @@ class DesignTokenImpl<T extends { createCSS?(): string }> extends CSSDirective
* @param token - the token to alias to
*/
private alias(token: DesignToken<T>): DerivedDesignTokenValue<T> {
return (((target: HTMLElement) =>
token.getValueFor(target)) as unknown) as DerivedDesignTokenValue<T>;
return ((target: HTMLElement) =>
token.getValueFor(target)) as unknown as DerivedDesignTokenValue<T>;
}
}

Expand Down Expand Up @@ -390,10 +393,10 @@ class DesignTokenBindingObserver<T extends { createCSS?(): string }> {
this.node.store.set(
this.token,

(this.observer.observe(
this.observer.observe(
this.node.target,
defaultExecutionContext
) as unknown) as StaticDesignTokenValue<T>
) as unknown as StaticDesignTokenValue<T>
);
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -704,6 +707,9 @@ class DesignTokenNode implements Behavior, Subscriber {
const parent = childToParent.get(this)!;
parent.removeChild(this);
}
for (const token of this.bindingObservers.keys()) {
this.tearDownBindingObserver(token);
}
}

/**
Expand Down

0 comments on commit 03e6e39

Please sign in to comment.