Skip to content

Commit

Permalink
fix: 🐛 updating src doesn't clear previously loaded states
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalz committed Sep 6, 2023
1 parent 022a1f0 commit 5acb38c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/common/src/dotlottie-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class DotLottieLoader {
}

public async loadFromUrl(url: string): Promise<void> {
this.clearCache();
const response = await fetch(url, {
method: 'GET',
mode: 'cors',
Expand Down Expand Up @@ -93,6 +94,7 @@ export class DotLottieLoader {
}

public loadFromLottieJSON(json: Record<string, unknown>): void {
this.clearCache();
if (!isValidLottieJSON(json)) {
throw new Error('Invalid lottie JSON');
}
Expand All @@ -114,6 +116,7 @@ export class DotLottieLoader {
}

public async loadFromArrayBuffer(arrayBuffer: ArrayBuffer): Promise<void> {
this.clearCache();
this._dotLottie = await loadFromArrayBufferUtil(arrayBuffer);

const manifest = await getManifestUtil(this._dotLottie);
Expand Down Expand Up @@ -204,4 +207,10 @@ export class DotLottieLoader {

return stateMachine;
}

public clearCache(): void {
this._stateMachinesMap.clear();
this._themeMap.clear();
this._animationsMap.clear();
}
}
3 changes: 2 additions & 1 deletion packages/common/src/dotlottie-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class DotLottiePlayer {

private _visibilityPercentage: number = 0;

protected _stateMachineManager?: DotLottieStateMachineManager;
protected _stateMachineManager: DotLottieStateMachineManager | undefined;

public constructor(
src: string | Record<string, unknown>,
Expand Down Expand Up @@ -443,6 +443,7 @@ export class DotLottiePlayer {
this._src = src;
this._activeAnimationId = undefined;
this._currentAnimationId = undefined;
this._stateMachineManager = undefined;
this.load();
}

Expand Down

0 comments on commit 5acb38c

Please sign in to comment.