refactor(canvas): drop a dead custom_colors.height write on zone growth

Growing a zone during a subnet import wrote the new height twice: to
`node.height`, the live field, and to `data.custom_colors.height`, which
nothing reads. The blob copy is produced by the serializer at save time
(rebuilt from `node.height`, so the value written here was overwritten
before it reached the API) and consumed at load time off the API payload.
Writing it from the store was invisible, and misleading in a blob that
otherwise holds colours and style.

The test asserting the dead field is replaced by a save/load round-trip
through the real serializer, which is what actually protects the height.

ha-relevant: yes
This commit is contained in:
Pouzor
2026-08-27 01:45:23 +02:00
committed by Pouzor - Rémy Jardient
parent 2bf9f1bca8
commit f9f88c8fb0
2 changed files with 13 additions and 12 deletions
@@ -1,6 +1,7 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { useCanvasStore } from '@/stores/canvasStore'
import { makeNode } from '@/test/factories'
import { serializeNode, deserializeApiNode, type ApiNode } from '@/utils/canvasSerializer'
function resetStore() {
useCanvasStore.setState({
@@ -238,8 +239,14 @@ describe('canvasStore — importZoneSubnet', () => {
const z = useCanvasStore.getState().nodes.find((n) => n.id === 'z1')!
expect(z.height!).toBeGreaterThan(300)
// The renderer reads the persisted size back out of custom_colors.
expect(z.data.custom_colors?.height).toBe(z.height)
// The grown height has to survive a save/load round-trip. A zone has no
// height column, so the serializer stashes it in the custom_colors blob
// on the way out and hoists it back on the way in.
const wire = serializeNode(z) as { custom_colors: { height: number } }
expect(wire.custom_colors.height).toBe(z.height)
const reloaded = deserializeApiNode(wire as unknown as ApiNode, new Map())
expect(reloaded.height).toBe(z.height)
})
it('keeps the parent ahead of its new children, as React Flow requires', () => {
+4 -10
View File
@@ -1072,17 +1072,11 @@ export const useCanvasStore = create<CanvasState>((rawSet, get) => {
set((s) => {
const updated = s.nodes.map((n) => {
// `height` is the only live field: the serializer stashes it into the
// custom_colors blob on save, since the nodes table has no height
// column for a zone, and hoists it back out on load.
if (n.id === zoneId) {
return grownHeight === zoneHeight
? n
: {
...n,
height: grownHeight,
data: {
...n.data,
custom_colors: { ...(n.data.custom_colors ?? {}), height: grownHeight },
},
}
return grownHeight === zoneHeight ? n : { ...n, height: grownHeight }
}
const at = placements.get(n.id)
if (!at) return n