Skip to content

Commit

Permalink
Merge pull request #170 from arturovt/fix/169
Browse files Browse the repository at this point in the history
fix: do not update `isVisible` signal when view is destroyed
  • Loading branch information
NetanelBasal authored Dec 6, 2024
2 parents d2bd038 + 7c43af9 commit d469023
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion projects/ngneat/helipopper/src/lib/tippy.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export class TippyDirective implements OnChanges, AfterViewInit, OnInit {
private destroyRef = inject(DestroyRef);
private isServer = isPlatformServer(inject(PLATFORM_ID));
private tippyFactory = inject(TippyFactory);
private destroyed = false;

constructor(
@Inject(TIPPY_CONFIG) protected globalConfig: TippyConfig,
Expand All @@ -240,6 +241,7 @@ export class TippyDirective implements OnChanges, AfterViewInit, OnInit {
this.setupListeners();

this.destroyRef.onDestroy(() => {
this.destroyed = true;
this.instance?.destroy();
this.destroyView();
this.visibilityObserverCleanup?.();
Expand Down Expand Up @@ -569,7 +571,12 @@ export class TippyDirective implements OnChanges, AfterViewInit, OnInit {
private onHidden(instance: TippyInstance = this.instance) {
this.destroyView();
const isVisible = false;
this.isVisible.set(isVisible);
// `model()` uses `OutputEmitterRef` internally to emit events when the
// signal changes. If the directive is destroyed, it will throw an error:
// "Unexpected emit for destroyed `OutputRef`".
if (!this.destroyed) {
this.isVisible.set(isVisible);
}
this.visibleInternal.next(isVisible);
if (this.visible.observed) {
this.ngZone.run(() => this.visible.next(isVisible));
Expand Down

0 comments on commit d469023

Please sign in to comment.