scttcper / ngx-color

🎨 Color Pickers from Sketch, Photoshop, Chrome, Github, Twitter & more
https://ngx-color.vercel.app
MIT License
436 stars 55 forks source link

Issue with onDestroy directive when component was invisible #372

Closed glani closed 2 years ago

glani commented 2 years ago
ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'unsubscribe')
TypeError: Cannot read properties of undefined (reading 'unsubscribe')
    at CoordinatesDirective.ngOnDestroy (ngx-color.mjs:117:18)

Problem happens in this part:

    ngOnInit() {
        this.sub = this.mousechange
            .pipe(
        // limit times it is updated for the same area
        distinctUntilChanged((p, q) => p.x === q.x && p.y === q.y))
            .subscribe(n => this.handleChange(n.x, n.y, n.$event, n.isTouch));
    }
    ngOnDestroy() {
        this.sub.unsubscribe();
    }

However color component sits under display: none Issue vanished when show all color components.

Stacktrace comes from this piece of code, view tries to destroy all:

 ngOnDestroy() {
        this._stateChanges.complete();
        this._contentViewRef.destroy();
        if (this._headerViewRef) {
            this._headerViewRef.destroy();
        }
    }

Browser debugger shows that ngOnInit was not called.

Proposal is to put destroy under if condition

scttcper commented 2 years ago

:tada: This issue has been resolved in version 8.0.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: