fix(board): restore layouts after column changes (#6979)

* fix: preserve geometry across layout resizing

* style: format layout migration snapshots
This commit is contained in:
Thomas authored and GitHub committed 2026-10-03 22:32:49 +02:00
1 parent eec910aabb
commit e048ae9cd7
14 files changed
+5567 -10

No files matched your search

+12 -5
View File
@@ -1,4 +1,4 @@
import { generateResponsiveGridFor } from "@homarr/common";
import { generateResponsiveGridFor, getLayoutResizeSource } from "@homarr/common";
import type { GridAlgorithmItem } from "@homarr/common";
import type { BoardLane, LayoutRole, WidgetKind } from "@homarr/definitions";
import { boardLanes, getBoardLaneColumnCount, getRootSectionLane } from "@homarr/definitions";
@@ -10,6 +10,7 @@ export interface BoardPreviewLayout {
rightGutterColumnCount: number;
breakpoint: number;
role: LayoutRole;
resizeSource?: string | null;
}
interface BoardPreviewItemLayout {
@@ -77,7 +78,13 @@ export const projectBoardLayout = (
sourceLayout: LayoutGeometry,
targetLayout: LayoutGeometry,
) => {
const elements = getElementsForLayout(board, sourceLayout.id);
const currentElements = getElementsForLayout(board, sourceLayout.id);
let serializedSource: string | null | undefined;
if (sourceLayout.id === targetLayout.id) {
serializedSource = board.layouts.find((layout) => layout.id === sourceLayout.id)?.resizeSource;
}
const source = getLayoutResizeSource(sourceLayout, currentElements, serializedSource);
const elements = source.elements;
if (
sourceLayout.id === targetLayout.id &&
@@ -85,7 +92,7 @@ export const projectBoardLayout = (
sourceLayout.leftGutterColumnCount === targetLayout.leftGutterColumnCount &&
sourceLayout.rightGutterColumnCount === targetLayout.rightGutterColumnCount
) {
return elements;
return currentElements;
}
const emptyRoots = board.sections
@@ -124,12 +131,12 @@ export const projectBoardLayout = (
const sourceLanes = boardLanes.filter(
(sourceLane) =>
rootByLane.has(sourceLane) &&
getBoardLaneColumnCount(sourceLayout, sourceLane) > 0 &&
getBoardLaneColumnCount(source.geometry, sourceLane) > 0 &&
targetLaneBySourceLane.get(sourceLane) === lane,
);
const previousWidth =
sourceLanes.length === 1
? getBoardLaneColumnCount(sourceLayout, sourceLanes[0] ?? "main")
? getBoardLaneColumnCount(source.geometry, sourceLanes[0] ?? "main")
: Number.MAX_SAFE_INTEGER;
return generateResponsiveGridFor({