Skip to content

fix: prevent FPO placeholder from reappearing after image upload#918

Merged
chrischrischris merged 1 commit intomainfrom
imagefix
May 4, 2026
Merged

fix: prevent FPO placeholder from reappearing after image upload#918
chrischrischris merged 1 commit intomainfrom
imagefix

Conversation

@kptdobe
Copy link
Copy Markdown
Contributor

@kptdobe kptdobe commented May 4, 2026

User scenario

A user uploads several images one after another in the DA editor. After the upload the real image briefly appears then reverts to the FPO/upload-icon placeholder (/blocks/edit/img/fpo.svg).

The same regression was reported by a second user after uploading a single image.

Root cause (two independent bugs)

1. FPO replaced by stale cursor position (imageDrop.js)

The original code stored $from.pos at the moment of upload, then used that position to replace the FPO after the upload response arrived. With multiple concurrent uploads, or with collaborative edits arriving in the meantime, the stored position no longer pointed at the right node. The replacement targeted the wrong image, leaving the old FPO in place.

2. Redundant wsProvider.connect() on every focus (prose/index.js)

Every window focus event called wsProvider.connect() unconditionally, even when the WebSocket was already open. Each spurious connect triggered a fresh Y.js session on the collab Durable Object, which can discard in-flight document state (see companion PR in da-collab).

Fix

imageDrop.js — Each upload now embeds the unique upload URL as a hash fragment in the FPO src attribute (fpo.svg#<uploadUrl>). The replacement handler searches the document for the node whose src matches that unique value rather than relying on a stale position. Concurrent uploads each get a distinct FPO identifier and are replaced independently.

prose/index.js — The focus handler now guards the call with !wsProvider.wsconnected, so reconnection only happens when the WebSocket is actually closed.

Related PRs

Tests

  • uploadImageFile gives FPO a unique src containing the upload URL
  • concurrent uploads use distinct FPO srcs so they can be replaced independently
  • uploadImageFile replaces FPO with the real image URL after upload completes

Two bugs caused the upload icon to re-appear after a real image was shown:

1. imageDrop.js replaced the FPO node by stale cursor position.  With
   multiple concurrent uploads or collaborative edits in flight the wrong
   node could be targeted, leaving the real URL in place and putting the
   FPO back.  Fix: each upload now embeds the unique upload URL as a hash
   fragment in the FPO src (fpo.svg#<uploadUrl>) and the replacement
   handler finds the node by that content rather than position.

2. prose/index.js called wsProvider.connect() on every window focus event,
   even when the WebSocket was already open.  Each redundant connect()
   triggered a fresh Y.js session on the collab DO, which could discard
   in-flight document state.  Fix: guard the call with !wsProvider.wsconnected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aem-code-sync
Copy link
Copy Markdown

aem-code-sync Bot commented May 4, 2026

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

@chrischrischris chrischrischris merged commit 0e57c77 into main May 4, 2026
4 checks passed
@chrischrischris chrischrischris deleted the imagefix branch May 4, 2026 17:19
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.

2 participants