-
Notifications
You must be signed in to change notification settings - Fork 57
Description
UPDATE 3
Unfortunately, I was unable to find the root cause. If you see an issue with my code, please let me know. I will try to find the time to make a minimal, reproducible example. The fact that draggedStyle is set correctly every second mouse event leads me to believe that this is a bug in react-reorder. The only workaround I found involved forking react-reorder, I opted to use react-dnd instead, which is a lot more complicated, but it works.
UPDATE 2
I couldn't tell you the root problem. I'm also having a different issue causing me to be unable to debug the application (connection refused), so I'm relying on console.log. Logging every time draggedStyle is written to with something vs. null, I would not expect it to be null when this error occurs, but it is. Every second time. However, this seems to fix the issue:
if (this.state.draggedStyle === null) {
console.log("Skipping because draggedStyle is null.");
return;
}
this.state.draggedStyle.transform = createOffsetStyles(event, this.props);
store.setDraggedStyle(this.props.reorderId, this.props.reorderGroup, this.state.draggedStyle);
This seems to have no side-effects, and reordering, drag and drop are perfectly smooth.
My only issue now is one that I also had before this: If I drag an item from "left-side" to "right-side" or vice versa, the component disappears from the source list and its "ghost" (my translucent clone placeholder) appears in the destination list (as expected) while still dragging. When I release it, it goes back to its source list, in the same position. Note that both lists have the same components.
UPDATE 1
Second time writing this update for some reason. Props are set correctly, and the stylesheet is also loaded. The names match up, and the bug has nothing to do with draggedClassName. I noticed something weird when inspecting state where the error occurs: It's only sometimes undefined. I narrowed it down to not being set on children in render:
// index.js
var isDragged = this.isDragging() && this.isDraggingFrom() && index === this.state.draggedIndex;
var draggedStyle = isDragged ? assign({}, child.props.style, this.state.draggedStyle) : child.props.style;
In the above code, draggedStyle will be undefined if child.props.style is undefined and isDragged is false. The child would be my WidgetWrapper, which in the default state has no style. I thought the fix would be:
var childStyle = child.props.style ?? {}; // <-- here
var draggedStyle = isDragged ? assign({}, childStyle, this.state.draggedStyle) : childStyle;
But this still isn't working. The expectation that style.transform is defined also needs to be dealt with. Still investigating.
ORIGINAL BODY
Edit: Irrelevant info removed
I'm using react-reorder with Typescript and self-declared types (please add types!). Before migrating to Typescript, it was working fine. Now, when I drag a component, I get this output in the console:
Uncaught TypeError: this.state.draggedStyle is null
onWindowMove index.js:647
componentDidMount index.js:688
chainedFunction factory.js:741
React 6
unstable_runWithPriority scheduler.development.js:468
React 9
tsx index.tsx:7
tsx main.chunk.js:2609
Webpack 7
__webpack_require__
fn
1
__webpack_require__
checkDeferredModules
webpackJsonpCallback
<anonymous>
I'm using a Reorder component with draggedClassName={widgetStyles.Dragged}, where widgetStyles is a sass stylesheet imported as widgetStyles. widgetStyles.Dragged resolves to something like WidgetWrapper_Dragged__3VyWh, but even using a regular css stylesheet with just .dragged { styles go here } and using "dragged" as draggedClassName results in the same error.
The console prints the error on every mouse event (edit: turns out to be every second mouse event) and it's very laggy. Traceback excerpt:
644 |
645 | }
646 |
> 647 | this.state.draggedStyle.transform = createOffsetStyles(event, this.props);
| ^ 648 | store.setDraggedStyle(this.props.reorderId, this.props.reorderGroup, this.state.draggedStyle);
649 |
650 | mouseOffset = {