From 4df618e418783b13365a27a4cbae8881d576c755 Mon Sep 17 00:00:00 2001 From: ajnart Date: Wed, 9 Sep 2026 11:59:10 +0200 Subject: [PATCH] fix(board): retain swap previews until layout commit renders --- apps/docs/docs/management/boards/index.mdx | 2 ++ .../src/components/board/sections/grid/grid-editor.tsx | 10 ++++++++-- .../board/sections/grid/use-grid-layout-actions.ts | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/docs/docs/management/boards/index.mdx b/apps/docs/docs/management/boards/index.mdx index 9c8df7efe..80a2f89b3 100644 --- a/apps/docs/docs/management/boards/index.mdx +++ b/apps/docs/docs/management/boards/index.mdx @@ -38,6 +38,8 @@ border color, and CSS classes. Items can occupy the outermost rows and columns of a Container. The drop preview shows the position where the item will remain when released. +Dragging an item onto another item of the same size swaps their positions; the displaced item stays at its previewed +position when you release the pointer. A **rail** reserves one to three columns at the left or right of a non-Mobile layout. Rails stay fixed while the page scrolls and store their contents separately for each layout. diff --git a/apps/nextjs/src/components/board/sections/grid/grid-editor.tsx b/apps/nextjs/src/components/board/sections/grid/grid-editor.tsx index 32245dfe6..a30b77449 100644 --- a/apps/nextjs/src/components/board/sections/grid/grid-editor.tsx +++ b/apps/nextjs/src/components/board/sections/grid/grid-editor.tsx @@ -415,7 +415,11 @@ export const BoardGridEditorProvider = ({ children }: PropsWithChildren) => { sectionId: grid.id, placements: grid.placements, })); - commitSectionGrids(snapshots); + const hasChanges = commitSectionGrids(snapshots); + if (!hasChanges) { + clearInteraction(); + return; + } const placement = state.grids .flatMap((grid) => grid.placements) @@ -429,7 +433,9 @@ export const BoardGridEditorProvider = ({ children }: PropsWithChildren) => { )} ${placement.h}`, ); } - clearInteraction(); + // Cache subscribers receive the committed board asynchronously. Keep the preview until + // the board-change layout effect clears it, so displaced items never flash at their old positions. + activeRef.current = null; }, [announce, clearInteraction, commitSectionGrids, currentLayoutId, t], ); diff --git a/apps/nextjs/src/components/board/sections/grid/use-grid-layout-actions.ts b/apps/nextjs/src/components/board/sections/grid/use-grid-layout-actions.ts index 2dd20fd71..59075087a 100644 --- a/apps/nextjs/src/components/board/sections/grid/use-grid-layout-actions.ts +++ b/apps/nextjs/src/components/board/sections/grid/use-grid-layout-actions.ts @@ -33,8 +33,8 @@ export const useGridLayoutActions = () => { placements.map((placement) => [`${layoutId}:${placement.id}`, { layoutId, sectionId, placement }] as const), ), ); + let hasChanges = false; updateBoard((previous) => { - let hasChanges = false; const items = previous.items.map((item) => { const layouts = item.layouts.map((layout) => { const resolved = byId.get(`${layout.layoutId}:${item.id}`); @@ -97,6 +97,7 @@ export const useGridLayoutActions = () => { return hasChanges ? { ...previous, items, sections } : previous; }); + return hasChanges; }, [updateBoard], );