-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conflict between Next.js router and Office.js #2327
Comments
This sounds like a compatibility issue with the next.js framework. @preethikakiru - any idea if we support the next.js framework for Office Add-ins? |
Hello @lkedmi, |
@preethikakiru this doesn't look like a DevX tooling problem. It looks like an office.js compatibility problem and should go to the office.js engineers. |
I will say that I moved on to a more "classic" solution but it'll be nice if we could use modern meta frameworks to build office add-ins. |
@lkedmi Could you please re-name this issue's title to not specify Next.js? Perhaps something like "Office.js should not null out history APIs" I've had this problem with various React routers, and am currently having this issue with SvelteKit. This is entirely a problem inside Office.js, which nulls out office-js/dist/office.debug.js Lines 1960 to 1964 in 64d4977
The OfficeJS documents mention that IE11 is still used in the field, but it does not have first-class support, as referenced here: https://docs.microsoft.com/en-us/office/dev/add-ins/concepts/browsers-used-by-office-web-add-ins and https://docs.microsoft.com/en-us/office/dev/add-ins/develop/support-ie-11
Common workarounds:Some people use NPM libraries which add history polyfills or support. With some routers, you can use HashRouter support (if they have it). I use variations of this silly workaround: https://stackoverflow.com/a/53662709/992509 <script type="text/javascript">
window._historyCache = {
replaceState: window.history.replaceState,
pushState: window.history.pushState
};
</script>
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<script type="text/javascript">
window.history.replaceState = window._historyCache.replaceState;
window.history.pushState = window._historyCache.pushState;
</script> The Request:Could someone please remove those 5 lines of code and let modern browsers/routing be the norm, and let the rare failures on unsupported browsers be handled on a case-by-case basis. IE11 is now retired and no longer supported by Microsoft. AppSource doesn't mandate IE11 support. Most Office variants (other than unsupported operating systems, or non-subscription Office purchases before 2020) can use the HTML5 history API. Please delete those 5 lines, and add documentation surrounding the error that would appear if you use IE11 and try to use those APIs. References:This problem has come up a few times, with many workarounds. Here's a non-exhaustive list of the resources I've needed to look at while solving this issue in the past. The first issue is over 3 years old.
|
@AbidRahman-MSFT @preethikakiru Does anybody know who is the contactor of office.js? |
Any update? |
We're also using NextJS, and are using the "silly workaround" mentioned by @sureshjoshi above. Any updates here? Are there any other known NextJS incompatibilities? |
@aorsten I am also facing the same problem with nextjs. The workaround seems to not work anymore following the most recent outlook update. |
According to this, the problem is supposed to be fixed: #1344 (comment) Can anyone confirm? |
I can't verify if this issue has been fixed or not but I am experimenting with placing the whole app behind an |
Not fixed yet, I have tested with a Nextjs app, so it would not work with any modern web app that use modern routing |
I'm not sure it really work using I'm curious to see how you are doing so? |
@RK1PF (I had to put that project on hold for the time being but) the strategy I was using is as follows:
So essentially, the top most window is the one who is responsible to interact with Office.js, not the iframe. This strategy seemed to be successful on my local machine but I haven't reached to a point where I'm publishing it to the Microsoft Office Add-ins Store. |
Provide required information needed to triage your issue
I'm using Next.js as the framework for a Word plugin, trying to at least. Next.js has their own router implementation which gets overridden by Office.js.
It's caused by this piece of code:
office-js/dist/office.debug.js
Line 1963 in 64d4977
In my case, this piece of code nullify both functions.
Your Environment
Expected behavior
Not override and nullify
window.history.pushState
whenwindow.next
is set.Current behavior
The Next.js router breaks when loading Office.js
Steps to reproduce
Link to live example(s)
Provide additional details
Context
I was hoping to build a Word plugin and base it on Next.js, but due to this behaviour, it doesn't looks like it's possible, which is a shame.
Useful logs
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.
The text was updated successfully, but these errors were encountered: