Skip to content

fix: the rectangle label listens to the canvas once for all its labels - #207

Merged
tbolis merged 1 commit into
release/1.1.0from
fix/rectangle-label-listeners
Nov 2, 2026
Merged

tbolis merged 1 commit into
release/1.1.0from
fix/rectangle-label-listeners

Conversation

@tbolis

@tbolis tbolis commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Summary

Each rectangle label subscribed to object:scaling and object:moving on the canvas when it was drawn (RectangleLabelObject), and nothing unsubscribed. The two listeners stayed after the label was deleted or the canvas was cleared, so a canvas which is drawn on for long kept more of them, and each moved or scaled object ran all of them.

  • The canvas has the two listeners once. They look the label up by the target of the event, in a WeakMap keyed by the rectangle, so a label is not kept alive by them. A WeakSet of canvases tells which ones already have the listeners.
  • The listeners are not removed with a label: undo and redo take its rectangle off the canvas and put it back, and the label has to follow it again.
  • RectangleLabelObject.update is a method without the event argument, as the target check moved to the lookup.
  • CHANGELOG: an entry under Fixed in 1.1.0.

Checks

yarn format:check, yarn lint, yarn typecheck and yarn test pass (450 passing and 1 todo). The 4 new tests are in tools.spec.ts:

  • the canvas gets one object:moving and one object:scaling registration for three labels (it failed before the change, with three of each);
  • each label follows only its own rectangle;
  • the label of a second canvas follows its rectangle (it fails if the "already listening" flag is global, which I checked);
  • the label follows after its rectangle is removed and added back.

Not checked: a real mouse drag in the showcase. The tests use a real fabric canvas and fire its events.

Notes for review

  • RectangleLabelObject.setText has no callers. It is not touched here.

Each label subscribed to object:scaling and object:moving on the canvas
when it was drawn, and nothing unsubscribed. The listeners stayed after a
label was deleted or the canvas was cleared, so a canvas drawn on for long
kept more and more of them.

The canvas has the two listeners once, and they look the label up by the
target of the event. They are not removed with a label, as undo and redo
take its rectangle off the canvas and put it back, and it follows again.
@tbolis
tbolis merged commit 3742980 into release/1.1.0 Nov 2, 2026
3 checks passed
@tbolis
tbolis deleted the fix/rectangle-label-listeners branch November 2, 2026 11:01
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