Skip to content

React 16 - unstable_renderSubtreeIntoContainer does not always return an instance #10310

@jlongster

Description

@jlongster

Do you want to request a feature or report a bug?

A bug

What is the current behavior?

I am using the react-modal library and tested it under React 16 beta. It throws an error when I try to close the modal.

The reason is it calls renderSubtreeIntoContainer here and expects an instance back. But sometimes it's null, so when it's closing and it's trying to read it's state here you get a null reference error.

If you use the API like <Modal isOpen={this.state.open} /> is works, but only because the component never tries to read from this.portal. If you use it like this.state.open && <Modal /> you get the error, because it tries to read it in componentWillUnmount: https://github.com/reactjs/react-modal/blob/master/src/components/Modal.js#L132

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/84v837e9/).

https://github.com/jlongster/fiber-modal-error

What is the expected behavior?

renderSubtreeIntoContainer should always return an instance so this modal librarly works (it will close).

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

React 16 beta. It works in all previous versions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions