OfficeDev/office-js

When replying or forwarding an email, calling body.setAsync resets the email body twice

Closed this issue · 11 comments

Provide required information needed to triage your issue

Likely related #4392

Calling body.setAsync on a reply/forward email will cause the email body to reset, interfering with entering text.

Your Environment

  • Platform [PC desktop, Mac, iOS, Office on the web]: PC desktop
  • Host [Excel, Word, PowerPoint, etc.]: Outlook
  • Office version number: 2402 (Build 17328.20282 Click-to-run)
  • Operating System: Windows 11
  • Browser (if using Office on the web): ______

Expected behavior

body.setAsync sets the email body without extra side effects

Current behavior

body.setAsync sets the email body and the email body resets twice. If the user is actively typing into the email body, the contents can be cleared/reset

Steps to reproduce

  • Open a received email and press the reply button. We see this issue on the Microsoft Viva emails.
  • Execute item.body.getAsync, and sets the same content back with item.body.setAsync

Link to live example(s)

Javascript

$("#run").on("click", run);

const timeout = 1000;

function run() {
  // Gets current email body
  Office.context.mailbox.item.body.getAsync(Office.CoercionType.Html, (result) => {
    document.getElementById("firstBody").innerHTML = escapeHtml(result.value);

    setTimeout(() => {
      // Sets the same email body
      Office.context.mailbox.item.body.setAsync(result.value, { coercionType: Office.CoercionType.Html }, (result) => {
        Office.context.mailbox.item.body.getAsync(Office.CoercionType.Html, (result) => {
          // Gets email body again after setAsync
          document.getElementById("secondBody").innerHTML = escapeHtml(result.value);
        });
      });
    }, timeout);
  });
}

function escapeHtml(html) {
  return html
    .replace(/&/g, "&")
    .replace(/</g, "&lt;")
    .replace(/>/g, "&gt;")
    .replace(/"/g, "&quot;")
    .replace(/'/g, "&#039;");
}

HTML

<div>
	<button id="run" class="ms-Button">
    <span class="ms-Button-label">Run</span>
</button>

	<p>--FIRST--</p>
	<p id="firstBody"></p>
	<br><br>
	<p>--SECOND--</p>
	<p id="secondBody"></p>
</div>

Context

  • The flicker severely interfere with a user trying to type into the reply/forward email body.

Hi @exextoc, this is actively affecting our customers using Outlook for Windows, and they're reporting disruption to their workflows. Please let us know if the team is able to revert this change to mitigate user pain. Thank you

@Oleg-O Is this something your team can help with?

@hsptkt @akshayta23 I cannot repro the issue. Do you repro it only when call body.setAsync after the body.getAsync? Can you repro with directly calling body.setAsync?

@zhngx1 We can repro this using Script Lab, and the javascript/html pair in the issue description consistently. It calls body.setAsync after the body.getAsync, which emulates our real production add-in's usages.

@zhngx1 Any updates on this issue? Here is a recording demonstrating this issue through the provided script lab snippets:

getsetbody_flicker.mov

@zhngx1 Could we please get an update on this issue?

@hsptkt , @bchen-hs-eng sorry for the delayed response. I tried it on build 17328. I can see the flickering but it does not set the body twice. Just want to confirm, is the issue about flickering or setting the body twice?

@zhngx1 The issue here is about how the flickering is causing a frustrating user experience (interfering with the customer's ability to start typing). It seems like a side effect of the body setting as @bchen-hs-eng highlighted in the example Script Lab, but we are specifically wanting to have the flickering fixed

@hsptkt May I ask why do you need to get the entire body and set it back? We are trying to see if we can provide any work around or better approach for your scenario while we investigating the issue.

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!

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