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

`Initialize` and `onReady` are not being called on initial document load #3922

Open hdwatts opened 11 months ago

hdwatts commented 11 months ago

Provide required information needed to triage your issue

We have an Office.onReady function that enables/disables "Login" and "Logout" buttons in the ribbon to match the user's logged in state.

When a user opens a new document, the onReady function does not get called until either a custom function is ran or the taskpane is open.

Is there an initialization function we can call when the custom functions are registered? According to the runtime logs, they get registered every time a document is opened which is when we would ideally be calling this.

See below video, which was taken with a fresh workbook and showcases that both Office.initialize and Office.onReady aren't called until a function is ran - and then my ribbon updates to the intended state.

https://github.com/OfficeDev/office-js/assets/16158417/33070de4-cc3a-444d-a0c6-b2c1cff3016e

Your Environment

Expected behavior

I expect onReady to be called when a document is open and the ribbon is visible.

Current behavior

onReady is not called until an action is taken by the user to run a command from our Add-in.

Steps to reproduce

  1. Create an add in with a ribbon with the shared runtime
  2. Add an onReady function that enables or disables a control on the ribbon
  3. Load a fresh document, the function does not get ran

Link to live example(s)

See video.

Provide additional details

N/A

Context

We would like to show the user's login state, and also disable/enable buttons based on who is logged in. Users will be confused if they are presented with disabled buttons that should be enabled, or with a login button when they have already logged in.

Useful logs

See video above

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.

dingjin-ms commented 11 months ago

Hi @hdwatts , thank you for raising the problem!

'OnReady' is designed to be called until user takes action in an add-in. Could you please try 'Automatically open a taskpane with a document' to see if it fits your scenario?

We apologize for the inconvenience, but we do not support the scenario you mentioned at the moment. If you would like to request this feature, please post it on our developer forum, where our product managers will regularly review and prioritize the suggestions.

hdwatts commented 11 months ago

@dingjin-ms Thanks, I have made a post there. I looked through that documentation already and unfortunately it doesn't solve the use case. Ideally, we would be able to ensure that the ribbon is accurate no matter what document is open, not just ones that we have tagged as such.

As it stands, this is going to lead to a lot of confusion for our users and it is disappointing that this isn't possible.

Does the Microsoft team have any guidance on recommended practices for handling access with ribbon controls?