[BUG] Sidebar - componentWillUnmount - v1.5.2

UI Components for React
Post Reply
rvw
Posts: 12
Joined: 01 Jun 2018, 10:48

01 Jun 2018, 11:00

Hi there,

I stumbled upon a bug after putting in navigation (router) inside a sidebar.
Uncaught TypeError: Cannot read property 'removeEventListener' of null
at Sidebar.unbindMaskClickListener (Sidebar.js:130)
at Sidebar.componentWillUnmount (Sidebar.js:58)
...
Problem + fix:

Code: Select all

key: 'componentWillUnmount',
        value: function componentWillUnmount() {
            this.disableModality();
            this.unbindMaskClickListener();
        }

Code: Select all

key: 'disableModality',
        value: function disableModality() {
            if (this.mask) {
                document.body.removeChild(this.mask);
                if (this.props.blockScroll) {
                    _DomHandler2.default.removeClass(document.body, 'ui-overflow-hidden');
                }
                this.mask = null;
            }
        }

Code: Select all

key: 'unbindMaskClickListener',
        value: function unbindMaskClickListener() {
            if (this.maskClickListener) {
                this.mask.removeEventListener('click', this.maskClickListener);
                this.maskClickListener = null;
            }
        }
In disableModality:

Code: Select all

this.mask = null
In unbindMaskClickListener:

Code: Select all

 this.mask.removeEventListener('click', this.maskClickListener);
Last line gives the error, because this.mas = null

fix: switch the function calls around like so:

Code: Select all

key: 'componentWillUnmount',
        value: function componentWillUnmount() {
            this.unbindMaskClickListener();
            this.disableModality();
        }

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

04 Jun 2018, 07:24

Good catch! +1

Thanks a lot, fixed now!

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 15 guests