Skip to content

fix(muya): keep the image resize bar from crashing after its image is removed (#5216) - #5288

Merged
Jocs merged 4 commits into
developfrom
fix/5216-image-resize-bar-race
Sep 10, 2026
Merged

Jocs merged 4 commits into
developfrom
fix/5216-image-resize-bar-race

Conversation

@Jocs

@Jocs Jocs commented Sep 10, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #5216
Fixes #4976
Fixes #4995
Fixes #5057

The image resize bar (ImageResizeBar) crashed when its image went away before it finished working with it. There were two separate races:

1. Deferred render after the image is deleted (#5216, v0.20.0-rc.1)

  • Clicking an image emits muya-transformer with the image container and schedules _render() with setTimeout.
  • Deleting the selected image right away (Delete, Backspace or Enter) emits { reference: null } before the timer fires.
  • The render then ran against a null reference: TypeError: Cannot read properties of null (reading 'getBoundingClientRect') in ImageResizeBar._update.
  • Fix: the timer only renders if the reference is still the one that scheduled it.

2. Mouse move after the bar hides mid-drag (#4976, #4995, #5057)

  • Those three reports come from the legacy image transformer in v0.19.x (HTMLBodyElement.mouseMove, null getBoundingClientRect/querySelector). @muyajs/core has the same bug.
  • hide() removed the handles but left the drag's mousemove/mouseup listeners attached.
  • Deleting the image while holding a handle clears the reference, so the next mouse move threw Cannot read properties of null (reading 'querySelector').
  • Fix: hide() detaches the drag listeners and resets the drag state (anchor, width, resizing flag), so a stale width also cannot leak into a later resize.

Test plan

  • e2e, Chromium (e2e/tests/drag/image-resize-bar-detached-5216.spec.ts):
    • Clicking an image and deleting it in the same task: no pageerror, no handles left. Before: the getBoundingClientRect TypeError.
    • Pressing Delete while dragging a handle, then moving the mouse: no pageerror. Before: the querySelector TypeError, four times.
  • Existing e2e/tests/drag/image-resize.spec.ts and image-resize-bar-reflow-2939.spec.ts still pass.
  • Unit (src/ui/imageResizeBar/__tests__/imageResizeBar.spec.ts): both races, red before the fix.
  • pnpm -C packages/muya test, pnpm -C packages/muya lint:types, eslint on the changed files

🤖 Generated with Claude Code

https://claude.ai/code/session_015EPgRzXj7DDhJToWxHtkkR

Jocs and others added 4 commits September 10, 2026 20:24
…#5216)

Clicking an image emits `muya-transformer` with the image container and
defers `_render()` to a timer. Deleting the selected image right away
(Delete, Backspace or Enter) emits `{ reference: null }` before that
timer runs, so the render ran against a null reference and `_update`
threw "Cannot read properties of null (reading 'getBoundingClientRect')".

Only render when the reference is still the one that scheduled it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015EPgRzXj7DDhJToWxHtkkR
Hiding the resize bar removed its handles but left the drag's mousemove
and mouseup listeners attached. Deleting the image while holding a handle
clears the reference, so the next mousemove threw "Cannot read properties
of null (reading 'querySelector')" — the crash reported against the
legacy image transformer in #4976, #4995 and #5057.

Detach the drag listeners and reset the drag state whenever the bar hides,
so a stale width cannot leak into a later resize either.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015EPgRzXj7DDhJToWxHtkkR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant