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

Excel event binding issue when using shared runtime and custom functions #4679

Open demyte opened 4 months ago

demyte commented 4 months ago

We are having an event binding issue within our Excel Addin which uses customfunctions and the shared runtime.

If a subsequent workbook is opened that has the custom functions on it, if we try to unbind our events, it fails with an error.

If the subsequent workbook opened is a blank workbook or doesn't have custom functions in it, it all works fine.

A github repo, instructions to replicate and a video are available below.

Your Environment

Expected behavior

When <event>.remove() is called within its context, as per the code below, it should always unbind.

await Excel.run(event.context, async (context) => {
  try {
    console.log(`[EXCEL EVENTS] > UNBINDING EVENT FROM CONTEXT > ${eventName}`, event, context);

    event.remove();
    await context.sync();

    console.log(`[EXCEL EVENTS] > UNBINDING SUCCESSFUL > ${eventName}`);
  } catch (e) {
    console.error(`[EXCEL EVENTS] > UNBINDING FAILED > BYPASS > ${eventName}`, e);
  }
});

Current behavior

When opening a 2nd workbook in excel that has customfunctions on it with a sharedruntime, event binding loses the context so unbinding events fail and re-binding events can cause multiple events to be bound.

So in the code above in Expected Behaviour, the event never unbinds and duplicate events can be bound

Steps to reproduce

  1. Using this repo: https://github.com/demyte/officejs-failing-fn-sharedruntime
  2. build:dev
  3. start:desktop
  4. keep new workbook open
  5. Open \docs\singlefunction.xlsx
  6. Open taskpane
  7. Show devtools
  8. Click on some cells to see the event log out
  9. Click on Unbind button in the task pane
  10. See errors shown image
  11. Now click on cells to show events... event is still bound as shown in the console: image
  12. Now click Rebind and click on cells and now 4 events are bound as shown in the console: image

Context

Useful logs

Video:

https://github.com/user-attachments/assets/1e55b158-23cc-4b77-8eb5-46cc2c81fcda

Thank you for taking the time to report an issue. Our triage team will respond to you in less than 72 hours. Normally, response time is <10 hours Monday through Friday. We do not triage on weekends.

shanshanzheng-dev commented 3 months ago

Hi @demyte Thanks for reporting this issue. I can repro this issue and we'll be looking into this and report back if we have a suggestion for you. Thanks.

demyte commented 1 month ago

Hi @shanshanzheng-dev

I am really looking to get a resolution to this issue as our app relies heavily on these events, especially onSelectionChanged and onFormulaChanged.

This issue is bleeding out into an really painful issue where these events just stop firing on subsequent workbook loads and users have to use the inbuilt taskpane menu to reload the addin to get them working again.

This is such a bad experience for our users and really undermines their confidence in our product and even though its an issue with Excel/OfficeJS, they do not see it that way.

Can you please let me know what we can do to expidite a resolution for this?

shanshanzheng-dev commented 1 month ago

Hi @demyte sorry for convenience. We're actively investigating these two issues. We'll update once we have a solution. Thanks for your patience.