OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
670 stars 96 forks source link

setSelectedDataAsync() sets selection to empty if replacing an `<img>` within a `<p>` tag #4785

Closed chambomango closed 3 weeks ago

chambomango commented 1 month ago

Your Environment

Expected behavior

The <img> should get replaced with the data we send to setSelectedDataAsync(). In our case we tried setting the selected data to another <img> tag

Current behavior

The <img> tag within the <p> tag gets replaced with an empty string, and the p tag converts to a <div>

Steps to reproduce

  1. Create an outlook 365 addin
  2. Open 365 outlook online and set the body to <p class="pTagWrapper" style="margin:0"> <img src="https://picsum.photos/200/300" style="display:block" > </p> using setBody() or some equivalent
  3. Click on the image
  4. Call setSelectedDataAsync() via the addin and try setting to a different image, (or try to insert anything). Any image will cause the issue but I tested with <img src="https://picsum.photos/id/237/200/300" alt="dog" width="500" height="600">. For the setSelectedDataAsync options I used { coercionType: Office.CoercionType.Html }
  5. Notice the selected image disappears without being replaced and notice the p tag was replaced with an empty div. An addRange() warning appears in the console

Context

We need this in order to set images inside p tags

Screenshots

Before: image

After: image

Useful logs

image

sivachandran-msft commented 1 month ago

Hi @chambomango , thanks for sharing the observations. We will investigate and get back on this.

anjalitp commented 1 month ago

We are not able to repro the issue. Could you please share a repro video? We would like to understand how the API is getting called after selecting the image.

microsoft-github-policy-service[bot] commented 4 weeks ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

microsoft-github-policy-service[bot] commented 3 weeks ago

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.