Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grandchild component with ref throwing error when conditionally rendered. #145

Closed
ethib137 opened this issue Aug 3, 2016 · 2 comments
Closed
Assignees
Labels

Comments

@ethib137
Copy link

ethib137 commented Aug 3, 2016

import Component, {Config} from 'metal-jsx';

class Child extends Component {
    render() {
        return <div>{this.props.children}</div>;
    }
}

class GrandChild extends Component {
    render() {
        return <div>{this.props.children}</div>;
    }
}

class TestKit extends Component {
    created() {
        this.handleClick_ = this.handleClick_.bind(this);
    }

    handleClick_() {
        this.state.visible_ = !this.state.visible_;
    }

    render() {
        return (
            <div>
                <a href="javascript:;" onClick={this.handleClick_}>{'Toggle'}</a>

                {this.state.visible_ &&
                    <Child>
                        <GrandChild ref="grandChild">
                            {'Child Component'}
                        </GrandChild>
                    </Child>
                }
            </div>
        );
    }
}

TestKit.STATE = {
    visible_: Config.value(true)
};

export default TestKit;

Steps to Reproduce:

  1. Toggle to hide.
  2. Toggle to show.

Result: Error Thrown.

Uncaught TypeError: Cannot read property 'startSkipUpdates' of null

I noticed that IncrementalDomRender is trying to call getRenderer() on a component that has already been disposed. Since disposing a component sets renderer_ to null, this throws an error.

Let me know if you have any questions.

Thanks.

@mairatma
Copy link
Contributor

mairatma commented Aug 4, 2016

Thanks! I know now what is causing this, and will publish a fix soon.

@mairatma mairatma self-assigned this Aug 4, 2016
@mairatma mairatma added the bug label Aug 4, 2016
@mairatma
Copy link
Contributor

mairatma commented Aug 4, 2016

The fix for this is now available at version 2.2.2.

@mairatma mairatma closed this as completed Aug 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants