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

Deprecate return value of ReactDOM.render() #6397

Closed
jimfb opened this issue Apr 1, 2016 · 8 comments
Closed

Deprecate return value of ReactDOM.render() #6397

jimfb opened this issue Apr 1, 2016 · 8 comments
Labels
Component: DOM Resolution: Stale Automatically closed due to inactivity Type: Enhancement

Comments

@jimfb
Copy link
Contributor

jimfb commented Apr 1, 2016

This is a tracking issue, because we're not ready to deprecate the return value of ReactDOM.render() yet. This will likely be a longer-term objective (not immediate), but we should have an issue to reference as we start to get the ball rolling.

Reasoning: We are working towards a new incremental reconciler, which means that a render may not be complete prior to ReactDOM.render() returning. For anyone relying on the return value of ReactDOM.render(), there would be a race condition where the returned instance is potentially not fully mounted. Safe-looking code might work 99% of the time, but fail 1% of the time, at the sole discretion of the scheduler. To be clear: this is not an issue today, but will become an issue once we start utilizing an incremental renderer, iff people rely on the return value.

As we prepare for the new reconciliation algorithm, we should start encouraging people should start avoiding the return value of ReactDOM.render. People should, instead, attach a callback ref to their root component when rendering the component, thus allowing them to get a reference to the instance after mounting is complete.

First step in this process is to update the documentation to state that the return value of ReactDOM.render is legacy, and that people should attach a ref instead (similar to what we did for string refs).

@gaearon
Copy link
Collaborator

gaearon commented Apr 1, 2016

Related: #2642 (comment)

@sebmarkbage
Copy link
Collaborator

ReactTestUtils might be an exception as a convenience. Testing likely needs its own reconciler anyway.

@ibhub
Copy link

ibhub commented Apr 11, 2016

After update react and react-dom from 15.0.0-rc.2 to 15.0.0 ReactDOM does not contain method render. ReactDOM.render is deprecated?

import React from "react";
import ReactDOM from "react-dom";

...

ReactDOM.render((
    <Provider store={store}>
        <Router history={history} routes={appRoutes} />
    </Provider>
), document.getElementById(appConfig.rootElementId));

@jimfb
Copy link
Contributor Author

jimfb commented Apr 11, 2016

@ibhub I don't understand your question/comment. React v15.0.0 does contain a render function, and ReactDOM.render is not deprecated (only usage of the return value is discouraged, the behavior is unchanged).

@ibhub
Copy link

ibhub commented Apr 11, 2016

Ok, thanks. Perhaps bug in my code, but I don't understand why ReactDOM.render is undefined (only in 15.0.x version). if I find the reason I will comment.

Upd: I found problem. I had incorrect alias to react-dom in webpack config. Sorry.

@udalrich
Copy link

I am using a library which requires HTML and does not accept a react component. The documentation explicitly says to use the return value of ReactDom.render, in a way where a callback will not work. Is there a good way to handle this?

I suppose I could create a promise, return the future value of the promise and then add a callback and complete the promise in the callback. Would that work? Or would that just create the possibility of a deadlock?

@stale
Copy link

stale bot commented Jan 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@stale
Copy link

stale bot commented Jan 19, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@stale stale bot closed this as completed Jan 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: DOM Resolution: Stale Automatically closed due to inactivity Type: Enhancement
Projects
None yet
Development

No branches or pull requests

5 participants