Skip to content

Commit d469023

Browse files
authored
Merge pull request #170 from arturovt/fix/169
fix: do not update `isVisible` signal when view is destroyed
2 parents d2bd038 + 7c43af9 commit d469023

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

projects/ngneat/helipopper/src/lib/tippy.directive.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export class TippyDirective implements OnChanges, AfterViewInit, OnInit {
226226
private destroyRef = inject(DestroyRef);
227227
private isServer = isPlatformServer(inject(PLATFORM_ID));
228228
private tippyFactory = inject(TippyFactory);
229+
private destroyed = false;
229230

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

242243
this.destroyRef.onDestroy(() => {
244+
this.destroyed = true;
243245
this.instance?.destroy();
244246
this.destroyView();
245247
this.visibilityObserverCleanup?.();
@@ -569,7 +571,12 @@ export class TippyDirective implements OnChanges, AfterViewInit, OnInit {
569571
private onHidden(instance: TippyInstance = this.instance) {
570572
this.destroyView();
571573
const isVisible = false;
572-
this.isVisible.set(isVisible);
574+
// `model()` uses `OutputEmitterRef` internally to emit events when the
575+
// signal changes. If the directive is destroyed, it will throw an error:
576+
// "Unexpected emit for destroyed `OutputRef`".
577+
if (!this.destroyed) {
578+
this.isVisible.set(isVisible);
579+
}
573580
this.visibleInternal.next(isVisible);
574581
if (this.visible.observed) {
575582
this.ngZone.run(() => this.visible.next(isVisible));

0 commit comments

Comments
 (0)