Skip to content

fix: rewrite aem.page/aem.live image srcs in editor to prevent 401 errors #930

Open
andreituicu wants to merge 10 commits into
mainfrom
fximg
Open

fix: rewrite aem.page/aem.live image srcs in editor to prevent 401 errors #930
andreituicu wants to merge 10 commits into
mainfrom
fximg

Conversation

@andreituicu
Copy link
Copy Markdown
Contributor

@andreituicu andreituicu commented May 13, 2026

Description

Images stored with *.aem.page or *.aem.live URLs now display correctly in the editor without triggering 401 errors.

When DA documents contain images served from AEM preview/publish hosts, the editor lacks the auth those hosts require. This PR rewrites those image URLs to their *.preview.da.live equivalent at render time via ProseMirror nodeViews — display-only, never written back to the document or synced via collab.

How Has This Been Tested?

Manually with: https://fximg--da-live--adobe.aem.live/edit#/andreituicu/da-test/mediabus

Screenshots (if appropriate):

The image with the cat is behind helix auth: https://main--da-test--andreituicu.aem.page/media_1222da127066e69ab4693b1aa98ad4cd6fdfe1fe4.jpg?width=2000&format=webply&optimize=medium

mediabus-images

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@aem-code-sync
Copy link
Copy Markdown

aem-code-sync Bot commented May 13, 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

@andreituicu andreituicu changed the title Fximg fix: rewrite aem.page/aem.live image srcs in editor to prevent 401 errors May 13, 2026
Copy link
Copy Markdown
Contributor

@kptdobe kptdobe left a comment

Choose a reason for hiding this comment

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

Missing tests...

Also, .preview.da.live maps to da-ue worker. I do not see the relationship here. It feels like this worker is a place for a lot of things. If we want .preview to become a central place for our editor, I think we should make a clean worker that includes only what's needed.

* @param {string} src - The original image src URL.
* @returns {string} The rewritten src, or the original if no rewrite was needed.
*/
export function rewriteImageSrcForEditor(src) {
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.

No tests created for this function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed in dfe691e

Comment on lines +156 to +161
return {
dom: img,
update(updated) {
if (updated.type.name !== 'image') return false;
updateImageAttributes(img, updated.attrs);
return true;
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.

No tests for this code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed in dfe691e, but as mentioned on the Slack thread, I'm not familiar with this particular feature.

Would be grateful for a second pair of eyes from @chrischrischris

Comment on lines +473 to +486
image(node) {
const img = document.createElement('img');
img.src = rewriteImageSrcForEditor(node.attrs.src);
if (node.attrs.alt) img.alt = node.attrs.alt;
return {
dom: img,
update(updated) {
if (updated.type.name !== 'image') return false;
img.src = rewriteImageSrcForEditor(updated.attrs.src);
if (updated.attrs.alt) img.alt = updated.attrs.alt;
return true;
},
};
},
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.

No tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed in 91afe27

@andreituicu
Copy link
Copy Markdown
Contributor Author

Thank you for the review!

Also, .preview.da.live maps to da-ue worker. I do not see the relationship here. It feels like this worker is a place for a lot of things. If we want .preview to become a central place for our editor, I think we should make a clean worker that includes only what's needed.

This was a decision in the last Helix hackathon to have the preview proxy and the UE proxy in the same worker, because they have a lot in common. They actually have more in common the differences.

As with everything it is in a bit of transition phase, but essentially they both:

  1. Provide access to content behind auth (both IMS and Helix), in the context of editors (DA and UE)
  2. They both proxy context and merge DA with Helix
  3. They can both be used for injecting later scripts for live preview, quick edit, UE instrumentation, on top of the content served.

Probably the only essential difference in the long-run is that the UE side of that worker, injects instrumentation for the HTML that is required for the UE editor.

The tests are a fair point, will add them.

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