Shaddix / dnd-kit-sortable-tree

Tree component for React with ability to drag-and-drop items throughout the tree. Based on an example from dnd-kit (https://github.com/clauderic/dnd-kit).
MIT License
81 stars 22 forks source link

Does not work with SSR #10

Open benjick opened 1 year ago

benjick commented 1 year ago

Hey! Great library, thanks for making this!

I'm using it with NextJS but it does not support SSR. I made this change locally: https://github.com/Shaddix/dnd-kit-sortable-tree/pull/9 and then it works if I wrap it with dynamic:

const SortableTreeClient: any = dynamic(() => Promise.resolve(SortableTree), {
  ssr: false,
});

But it still gives me some issues with document if I don't wrap it in dynamic. I think it's related to this line: https://github.com/Shaddix/dnd-kit-sortable-tree/blob/0ee9535b547ad79e8b218b93366a03498691cfc5/src/SortableTree.tsx#L257 but I haven't used portals before so I'm not sure how to solve it.

Cheers

Shaddix commented 1 year ago

Thanks for the PR! I merged it and pushed a version to npm. Personally I haven't used it with SSR, so can't advice much. If something could be changed in a library to make it easier, PRs are more than welcome!

benjick commented 1 year ago

Thanks @Shaddix!