Skip to content

SD-2974 - Bug: image resizing in suggesting mode duplicates the image#3238

Merged
harbournick merged 4 commits into
mainfrom
gabriel/sd-2974-bug-image-resizing-in-suggesting-mode-duplicates-the-image
Jun 3, 2026
Merged

SD-2974 - Bug: image resizing in suggesting mode duplicates the image#3238
harbournick merged 4 commits into
mainfrom
gabriel/sd-2974-bug-image-resizing-in-suggesting-mode-duplicates-the-image

Conversation

@chittolinag

@chittolinag chittolinag commented May 11, 2026

Copy link
Copy Markdown
Contributor

Issue

Images resized in suggesting mode creates a duplicate.

Proposed solution

Since MS Word does not track changes when the image is resized, the simplest way to fix the issue is by simply ignoring track changes on the event of an image resize.

Just for future reference, the original issue happens around here.

This replaceRange call adds the new (resized) image but keeps the old one. If we ever want to show the old and new image (and show the tracked change for resized) images, we might have to fix this.

Created a behavior test that ensures this doesn't happen in the future (tested both before & after the fix).

@chittolinag
chittolinag requested a review from a team as a code owner May 11, 2026 19:47
@linear

linear Bot commented May 11, 2026

Copy link
Copy Markdown

SD-2974

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@andrii-harbour andrii-harbour left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! Here are a few notes:

  1. Rebase needed: the branch is ~1,100 commits behind main, and main's ImageResizeOverlay.test.js:17 mocks tr as { setNodeMarkup } only — no setMeta — so this PR as-is throws tr.setMeta is not a function in main's unit tests. (Good news: verified the bug still reproduces on current main, so the fix is still needed.)
  2. Simpler mechanism worth considering: tr.setNodeAttribute(imagePos, 'size', …) instead of setNodeMarkup + skipTrackChanges — it also fixes an edge case the current approach misses (details inline).
  3. Test hardening: the behavior test can false-pass if the drag no-ops, and two of the ticket's acceptance criteria aren't covered yet (details inline).

Comment thread packages/super-editor/src/editors/v1/components/ImageResizeOverlay.vue Outdated
Comment thread tests/behavior/tests/images/image-resize-in-suggesting-mode.spec.ts
Comment thread tests/behavior/tests/images/image-resize-in-suggesting-mode.spec.ts
chittolina and others added 2 commits June 3, 2026 11:51
…-2974)

Address review feedback:

- Replace setNodeMarkup + skipTrackChanges with tr.setNodeAttribute, which
  emits an AttrStep. AttrSteps pass through the track-changes machinery
  untracked and never trip the protect-tracked-review-state guard, so the
  resize applies in place even when the image is itself a pending tracked
  insertion.
- Bump the containing blocks' sdBlockRev in the same transaction: AttrSteps
  have no changed range, so blockNodePlugin never increments the rev and the
  layout engine would reuse the cached FlowBlock, leaving the paint stale
  (same pattern as numberingPlugin's bumpBlockRev).
- Harden the behavior test against false-greens by asserting the image's
  size attrs actually changed after the drag.
- Add coverage for repeated resizes (AC #3) and for resizing an image that
  is itself a pending tracked insertion.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chittolinag

chittolinag commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@andrii-harbour Thanks for the review! All addressed, including the rebase.

1. Mechanism - switched to setNodeAttribute, plus one fix it needed: AttrSteps have no changed range, so blockNodePlugin never bumps sdBlockRev and the layout engine reuses the cached FlowBlock - PM state updated but the paint stayed stale. The resize now bumps the containing blocks' sdBlockRev in the same transaction (same pattern as numberingPlugin).

2. Tests - all three added: before/after size assertions, repeated resizes, pending-insertion resize.

Two findings from the pending-insertion test:

  1. It also passes under the old skipTrackChanges approach: on current main the protect guard sets protectTrackedReviewState, which compiles the replace with preserveExistingReviewState: true - in-place, no duplicate. So it's regression coverage, not a mechanism pin. AttrStep is still the better choice.
  2. Separate latent bug: setImage in suggesting mode duplicates at insert time - imageRegistrationPlugin rewrites unregistered images via untracked setNodeMarkup. The test sidesteps it (pre-registered image with rId + trackInsert mark constructed directly); I'm creating a new ticket for that now.

@harbournick harbournick left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@harbournick
harbournick merged commit 946e821 into main Jun 3, 2026
69 checks passed
@harbournick
harbournick deleted the gabriel/sd-2974-bug-image-resizing-in-suggesting-mode-duplicates-the-image branch June 3, 2026 15:55
@superdoc-bot

superdoc-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc-cli v0.16.0

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc-sdk v1.15.0

@superdoc-bot

superdoc-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in @superdoc-dev/mcp v0.11.0

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc v1.39.0

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in @superdoc-dev/react v1.10.0

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in vscode-ext v2.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants