question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
overlookmotelcommented, Mar 5, 2019

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

1reaction
overlookmotelcommented, Mar 5, 2019

I’ve submitted a PR #15023.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Context undefined in Server Side Render - Stack Overflow
Show activity on this post. I am trying to pass in data during server side rendering for a simple app. and the data...
Read more >
React.Context. Context provides a way to pass data… - Medium
When React renders a component that subscribes to this Context object it will read the current context value from the closest matching Provider...
Read more >
Context - React
All consumers that are descendants of a Provider will re-render whenever the Provider's value prop changes. The propagation from Provider to its descendant ......
Read more >
How to Use React Context to Share Data between Components
There are different ways to share data between React components. The first one, which you may already know about if you are a...
Read more >
Using React Context for state management in Next.js - Netlify
Now, in every component and page in your application, if you'd like to access the values inside of that sharedState object, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found