Breaks Server-Side Rendering
See original GitHub issueSeems to affect both versions 5.x and 6.x. I have a decorator like this:
import { DragDropContext, DragLayer, DropTarget } from 'react-dnd'
export function DragAndDrop() {
const context = DragDropContext(HTML5Backend)
const layer = DragLayer((monitor) =>({ isDragging : monitor.isDragging() }))
return component => context(layer(component))
}
The I decorate my app’s main component with @DragAndDrop()
.
This results in the .render()
method returning null
on server-side, and so server-side rendering returns emptyness.
When I remove the @DragAndDrop()
decorator everything renders as expected on server-side.
As a workaround, until the bug is fixed in this library, I modified my code this way:
import { DragDropContext, DragLayer, DropTarget } from 'react-dnd'
export function DragAndDrop() {
if (typeof window === 'undefined') {
return component => component
}
const context = DragDropContext(HTML5Backend)
const layer = DragLayer((monitor) =>({ isDragging : monitor.isDragging() }))
return component => context(layer(component))
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
[2.0.0] Server-side rendering breaks · Issue #1890 - GitHub
Description Reanimated v2 stable breaks server side rendering, because it uses window.performance in the constructor of JSReanimated.
Read more >Stop Client Side and Server Side Rendering. Do This Instead.
Server -side rendering involves two renders. First, the server executes the data fetches and creates a fully rendered HTML page to send to...
Read more >React Server Side Rendering Errors
Hi,. I am using MDB React Pro v4.8.7. My team uses SSR for all of our websites but I have been getting errors...
Read more >Server Rendering with React and React Router - ui.dev
In this comprehensive, up-to-date guide, you'll learn how, why, and when to add server rendering to a React and React Router application.
Read more >Server rendering - Material UI - MUI
The most common use case for server-side rendering is to handle the initial render when a user (or search engine crawler) first requests...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Why is there no “Reopen” button? This is not fixed.
@dkarbayev Actually, my workaround doesn’t work (I guess yours too). It still renders but then throws a warning in
React.hydrate()
: “Did not expect server HTML to contain …”. (doesn’t seem to throw the warning when usingreact-dnd@5
so I’m staying at version5
until it’s fixed, if it ever gets fixed) It’s weird though because the server and client markups are identical. Maybe a React bug even.@darthtrevino Here is a sample repo illustrating the bug. https://github.com/catamphetamine/react-dnd-bug-showcase
npm install && npm start
http://localhost:3000 Disable JavaScript in DevTools and see “Text” on the page. Then go tosrc/pages/DragAndDrop.js
and comment the lines:Ctrl + C and
npm start
. See that nothing renders. The workaround is still not the solution because it breaksReact.hydrate()
.