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

data-reactroot="" lost in server render if element inside <Context.Provider> #15012

Closed
overlookmotel opened this issue Mar 4, 2019 · 6 comments

Comments

@overlookmotel
Copy link
Contributor

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

Bug.

What is the current behavior?

Calling .renderToString() on <React.Fragment><div>Hello!</div></React.Fragment> produces <div data-reactroot="">Hello!</div>.

However, many other combinations of DOM root element within "invisible" React elements are rendered without data-reactroot="".

e.g. all of the following produce <div>Hello!</div> (without data-reactroot=""):

<React.Fragment><React.Fragment><div>Hello!</div></React.Fragment></React.Fragment>

<Context.Provider><div>Hello!</div></Context.Provider>

<Context.Consumer>{() => <div>Hello!</div>}</Context.Consumer>

<React.StrictMode><div>Hello!</div></React.StrictMode>

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:

See above.

What is the expected behavior?

I assume that any of the above examples should produce markup including data-reactroot="" on the div element.

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

Issue present in all versions >= 16.7.0, possibly earlier versions too.

This is a minor issue - I guess would only affect where the markup is rehydrated on client side using .render() rather than .hydrate() - usage which is discouraged. However, using .render() to rehydrate is still officially supported.

I can implement a fix and make a PR. But can anyone confirm that the expected behavior is what I think it is, and that this is indeed a bug?

@gaearon
Copy link
Collaborator

gaearon commented Mar 5, 2019

This does sound like a bug. A fix would be welcome.

@overlookmotel
Copy link
Contributor Author

OK great. Thanks for swift response. I'll submit a PR soon as I can - should be in next couple of weeks.

@overlookmotel
Copy link
Contributor Author

I've submitted a PR #15023.

@overlookmotel
Copy link
Contributor Author

@gaearon Anyone had a chance to look at my fix for this in PR #15023?

@ianks
Copy link

ianks commented Mar 25, 2019

Now that react-apollo is using the Context API, our builds are broken because of this.

@gaearon
Copy link
Collaborator

gaearon commented Mar 24, 2021

We're planning to remove this attribute altogether. It only exists for hydration via ReactDOM.render to work. But that already warns that you should be using ReactDOM.hydrate instead. So I don't think we'll fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants