Skip to content

fix(flow): keep the canvas viewport usable when coordinates go non-finite - #1098

Open
zheng1114567 wants to merge 1 commit into
Tencent:mainfrom
zheng1114567:fix/flow-canvas-viewport-recovery
Open

zheng1114567 wants to merge 1 commit into
Tencent:mainfrom
zheng1114567:fix/flow-canvas-viewport-recovery

Conversation

@zheng1114567

Copy link
Copy Markdown

What happens

On the SOP canvas, panning and zooming can stop moving the nodes while the zoom label keeps changing. Clicking "fit" doesn't recover it either. After that, adding a node from the palette puts it at left: NaNpx.

Why

The stage transform became translate(NaNpx, ...). Browsers drop an invalid transform, so #canvasStage stays frozen at the last valid value. The viewport state itself is NaN, and fit() keeps it that way because bounds() doesn't filter nodes with unusable coordinates. freeSpot() reads the same state, so the next node gets NaN coordinates too.

Fix

  • flowViewport: repair non-finite x/y/zoom before writing the transform, and skip nodes without finite coordinates in bounds(). zoomAt/centerOn/reveal ignore non-finite inputs.
  • renderCanvas(): a node with a broken position is placed on a grid slot instead of rendering left: NaNpx, so the repaired position is what gets saved.
  • mergeAIEdit / aiPlaceNode: check both x and y when deciding whether a draft position is usable. The edit path only checked x, so a draft that had x but no y could drop the position.

How I checked

  • Reproduced on a self-hosted 0.4.0 instance: the stage stayed at scale(0.55) while the label showed 60%, and fit() produced scale(NaN).
  • Added webtest/tests/flow-viewport-recovery.test.mjs: poisoned viewport heals on zoom, freeSpot stays finite, broken node positions are repaired before fit, and an x-only AI draft keeps the old position.
  • node --test tests/*.test.mjs in webtest: 217 passed.
  • Web line coverage was 87.65% when I ran the c8 gate locally (threshold 85%).

A non-finite node position or viewport x/y/zoom poisons every transform
and fit computed from the canvas. Browsers drop the invalid transform, so
panning and zooming freeze while the zoom label keeps changing.

Repair non-finite viewport state before it is written, skip nodes without
usable coordinates when fitting the view, park broken nodes on a grid slot
at render time, and keep the previous position when an AI edit draft omits
one coordinate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant