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
Dragging not working using SSR after refresh #1854
Comments
I'm facing this exact issue. I'm also using nextjs and SSR
|
also using nextJS facing this. but I did not use SSR Can be easily reproduce with any sample codes. Apparently linked to this #1883 . It can be used after npm run build but not when in hot reload environment |
Guys, try to make this in
|
This worked for me |
Sorry, my mistake. It works !!! I was using Draggable in wrong way... Gracias compadre! (as we say in my country) |
Another solution was to use the react-no-ssr library. Just wrap the whole DND component with <NoSSR>
... // react-beautiful-dnd code inside
</NoSSR> |
This worked! Thanks |
Here is how to do it with Typescript: import { GetServerSideProps } from "next";
import { resetServerContext } from "react-beautiful-dnd";
export const getServerSideProps: GetServerSideProps = async (context) => {
resetServerContext();
return { props: {} };
}; |
Another solution: const [isBrowser, setIsBrowser] = useState(false);
useEffect(() => {
setCanRender(process.browser);
}, [])
function Home() {
return(
<>
{isBrowser ? <DragDropContext> { /* all rbd code */ } </DragDropContext> : null}
</>
)
} |
@IKrehan solution is not really correct as |
After some investigation and looking at the code it seems the root of the problem is more the client-side than the server-side. A possible workaround (just tested quickly) is to directly call |
The |
If you guys want to use react-beautiful-dnd with Next.js, this is my solution, i just make a component contain dnd not work with SSR of Next and it's work for me.
I done my dnd followed by this tutorial: https://www.freecodecamp.org/news/how-to-add-drag-and-drop-in-react-with-react-beautiful-dnd/ |
Also if you don't need HTML5 DND support then dnd-kit is a very good other solution with Next.js support I am quite happy with (very actively developed). |
This works perfectly, thanks for the solution. |
If anyone still looking for SSR NextJS solution, following way of importing worked
|
Thanks so much, this worked for me instantly :) |
so do I create _document.js and then copy this code or what? |
getInitialProps is obsolete and should not be used, use getServerSideProps instead. resetServerContext() does not work in many cases. Would be great to have the SSR logic inside DragDropContext. |
Any update on this ???? |
This worked well for me! |
Thank you so much. |
If anyone, like me, is using Typescript and getting errors with the above try this: import dynamic from 'next/dynamic';
const DragDropContext = dynamic(
async () => {
const mod = await import('react-beautiful-dnd');
return mod.DragDropContext;
},
{ ssr: false },
);
const Droppable = dynamic(
async () => {
const mod = await import('react-beautiful-dnd');
return mod.Droppable;
},
{ ssr: false },
);
const Draggable = dynamic(
async () => {
const mod = await import('react-beautiful-dnd');
return mod.Draggable;
},
{ ssr: false },
); |
somebody made it work with next13 + app directory? mixed server and client components with |
What about Nextjs 13.4.4 + App Directory . Im having this Issue . please help |
thx! |
I'm experiencing the issues mentioned in this issue. For some reason, it was closed, even though the issue isn't resolved. However, unlike the reporter in this issue, I am using the suggested
_document.js
API.#1775 (comment)
Expected behavior
react-beautiful-dnd should run without warnings and errors when using SSR with next.js production AND dev. I should be able to always pick up draggable items.
Actual behavior
Receiving the following errors when trying to run react-beautiful-dnd with next.js:
Which according to other issues should resolve the problem with the client, server id mismatches when using SSR.
But it's not resolved for me sadly.
The issue appears to be most reproduceable, by refreshing the page after initial load in development mode.
Steps to reproduce
Install the next.js, react-beautiful-react-dnd
Follow this tutorial: https://egghead.io/courses/beautiful-and-accessible-drag-and-drop-with-react-beautiful-dnd
In this tutorial the attribute innerRef is being used. Don't use it. Instead use the ref attribute!
What version of
react-beautiful-dnd
andreact
are you running?I'm using the following dependencies (listed in my package.json file):
What browser are you using?
Chrome Version 83.0.4103.61 (Official Build) (64-bit)
Firefox 76.0.1 (64-bit)
The text was updated successfully, but these errors were encountered: