Open
Description
Dispatching a reorder
action followed by a setUi
action to reselect the reordered item doesn't work as expected when called inside an actionBar
override.
Reordering elements down (increasing their index by one in their dropzone) updates the UI correctly, moving the ActionBar to the new position.
However, reordering elements up (decreasing their index by one) moves the item but the ActionBar stays in the previous position until you hover over the item in the canvas.
- This bug happens in:
v0.19.0-canary.0a3e56e
- This bug doesn't happen in:
v0.18.2
Reproduction steps
- Render a minimal Puck editor with an
actionBar
override:
export const usePuckContext = createUsePuck();
overrides={{
actionBar: () => {
const dispatch = usePuckContext((state) => state.dispatch);
const itemSelector = usePuckContext(
(state) => state.appState.ui.itemSelector
);
const handleClickAngle = (type: "up" | "down") => () => {
const destination = type === "up"
? itemSelector?.index - 1
: itemSelector?.index + 1;
dispatch({
type: "reorder",
sourceIndex: itemSelector?.index,
destinationIndex: destination,
destinationZone: itemSelector?.zone,
});
dispatch({
type: "setUi",
ui: (ui) => ({
...ui,
itemSelector: { ...ui.itemSelector, index: destination },
}),
});
};
return (
<ActionBar>
<ActionBar.Action onClick={handleClickAngle("down")}>Down</ActionBar.Action>
<ActionBar.Action onClick={handleClickAngle("up")}>Up</ActionBar.Action>
</ActionBar>
);
},
}}
- Drag and drop multiple components into the canvas
- Select the top component and press "Down"
- Select the bottom component and press "Up"
What happens
-
"Move down" (
itemSelector.index + 1
) works as expected:reorder
action correctly moves the itemsetUi
correctly updates the ActionBar position
-
"Move up" (
itemSelector.index - 1
) fails:reorder
action correctly moves the itemsetUi
does not move the ActionBar. It remains visually in the old position until the reordered item is hovered
What I expect to happen
The ActionBar should consistently update its position after setUi
, regardless of direction.
Video
Puck_._.webm
Considerations
- This bug was initially reported in ActionBar not updating position after
setUi
#947, it was rewritten here for clarity - The original reporter @christian-tchaikovsky, mentioned that this seems to happen because the DraggableComponent element in the document doesn't update.