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
686 stars 95 forks source link

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

Open bchen-hs-eng opened 6 months ago

bchen-hs-eng commented 6 months ago

Provide required information needed to triage your issue

Likely related https://github.com/OfficeDev/office-js/issues/4392

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

Your Environment

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

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

hsptkt commented 6 months ago

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

akshayta23 commented 6 months ago

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

zhngx1 commented 5 months ago

@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?

bchen-hs-eng commented 5 months ago

@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.

bchen-hs-eng commented 5 months ago

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

https://github.com/OfficeDev/office-js/assets/168113738/3b603cee-39ed-4867-b232-0122e0695dac

hsptkt commented 5 months ago

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

zhngx1 commented 5 months ago

@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?

hsptkt commented 5 months ago

@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

zhngx1 commented 4 months ago

@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.

hsptkt commented 3 months ago

Hi @zhngx1, this is still an issue for us. Our use case for get/setting the entire body is for grabbing & update link nodes in the body as the user is composing a message. Our expectation is one flicker instead of two flickers for the set.

zhngx1 commented 2 months ago

@hsptkt, I am reopening this issue. Do you only repro this issue for Microsoft Viva emails? Do you repro it on new compose?

hsptkt commented 2 months ago

@zhngx1 We can repro this on replies & forwards - I'm not able to reproduce this on new composes at the moment.

zhngx1 commented 2 months ago

@hsptkt Does it happen on all replies and forwards? Or only when replying or forwarding Microsoft Viva emails?

hsptkt commented 1 month ago

@zhngx1 It happens on all replies/forwards for me, and to be specific, the problem we're seeing is the flicker from the setAsync which we're noting as a regression

hsptkt commented 1 month ago

Re-opening this as it's still an issue for us.

zhngx1 commented 1 month ago

I will try to repro this. At the moment, I don't have a repro for 2 flickers. Have you tried latest build of Outlook?

zhngx1 commented 2 weeks ago

Is this still an issue? I can only see 1 flicker still, but that's expected due to the fact of setting the whole body. We do have concerns about the 2 flickers but we cannot repro yet. What is the number of customers impacted by this?