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

[Bug] New Context API does not work with ReactDOM.unstable_renderSubtreeIntoContainer #12493

Closed
pmunin opened this issue Mar 30, 2018 · 4 comments

Comments

@pmunin
Copy link

pmunin commented Mar 30, 2018

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

What is the current behavior?
Consumer rendered by invokes ReactDOM.unstable_renderSubtreeIntoContainer, invokes render function with DEFAULT context value ignoring value of Provider

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
Open example on Codesandbox.io

  1. Click "Increment state.contextValue"
    =>State should change to 1, and ChildComponent rendered directly will show it
  2. Click "Render into placeholder"
    => ChildComponent rendered through unstable_renderSubtreeIntoContainer should show 1

Actual result: ChildComponent rendered through unstable_renderSubtreeIntoContainer should show 111 (which is default value specified in createContext)

What is the expected behavior?
unstable_renderSubtreeIntoContainer should pass context through to consumer

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React: 16.3.0
Chrome: 65 x64
Windows: 10 x64

@gaearon
Copy link
Collaborator

gaearon commented Mar 30, 2018

I don’t think we’ll implement new context API support for unstable_renderSubtreeIntoContainer. Effectively unstable_renderSubtreeIntoContainer has been superseded by Portals in React 16, and I encourage you to migrate to using a portal (which will propagate both new and legacy context correctly). We will deprecate unstable_renderSubtreeIntoContainer in a future minor release.

@pmunin
Copy link
Author

pmunin commented Mar 30, 2018

I see. Unfortunately there are some cool 3rd party components that still use it, like golden-layout. It's javascript (not React) component, but they have integration with react, which triggers each docking panel to rendering through react the following way:

class ReactComponentHandler extends GoldenLayout["__lm"].utils.ReactComponentHandler
{
    _render() {
        var reactContainer = this._container.layoutManager.reactContainer;
        this._reactComponent =  reactContainer 
        ? ReactDOM.unstable_renderSubtreeIntoContainer(
            reactContainer,
            this._getReactComponent(),
            this._container.getElement()[ 0 ])
        : ReactDOM.render( this._getReactComponent(), this._container.getElement()[ 0 ]);
		
        this._originalComponentWillUpdate = this._reactComponent.componentWillUpdate || function() {};
	this._reactComponent.componentWillUpdate = this._onUpdate.bind( this );
    }
}

Not sure how to migrate it to createPortal approach, since it's the javascript component who triggers the rendering of each docking react panel, not the parent react component.

@urrri
Copy link

urrri commented Aug 15, 2018

ag-grid-react has the same behavior and the same problem for cells

@gaearon
Copy link
Collaborator

gaearon commented Aug 15, 2018

Sorry. unstable_renderSubtreeIntoContainer has never been an officially supported API. There's a reason it starts with unstable_.

@facebook facebook locked as resolved and limited conversation to collaborators Aug 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants