Skip to content

ActionBar does not update position correctly when reordering items upward via setUi dispatch #955

Open
@FedericoBonel

Description

@FedericoBonel

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

  1. 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>
    );
  },
}}
  1. Drag and drop multiple components into the canvas
  2. Select the top component and press "Down"
  3. Select the bottom component and press "Up"

What happens

  • "Move down" (itemSelector.index + 1) works as expected:

    • reorder action correctly moves the item
    • setUi correctly updates the ActionBar position
  • "Move up" (itemSelector.index - 1) fails:

    • reorder action correctly moves the item
    • setUi 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions