We have recently developed and deployed our own Custom App for Freshdesk support_ticket, to help our customer support team in their daily operations.
The app basically connects to our backend systems via http-requests to present order data in a convenient way. Pretty standard stuff.
The first publish and subsequent versions have worked great without any issues. However, on Friday last week (October 11th) we published a new version that started behaving strangely. The sidebar widget does not load when you navigate from the “all tickets” list to a specific ticket and then open the widget in the sidebar. You have to do a hard reload of the ticket page for the widget to actually load. This makes this error particularly hard to debug since the development environment requires you to add “?dev=true” to the URL and do an actual page reload (hence, the app ALWAYS works in development mode AND test mode, but not in production). To maintain a stable version for our customer support team while still allowing us to “test” the custom app in a live environment, we have now published a second, experimental, copy of the app.
Currently there are two versions of the custom app published in our account: “Nestor” and “Nestor - Experimental”.
- Nestor is an older version of the custom app that still works.
- Nestor - Experimental is the newer version that has this strange behavior.
The custom app is built in React 18. I have been able to isolate the issue to the fact that when “app.initialized()” is called, in the version with the error, that call never resolves (or throws an error) when you navigate from the all tickets list to a ticket. It just remains idle indefinitely. And the strange thing about this is that we have not changed anything in regards to how we handle the initialization of the custom app between versions. The only thing that I can think of that would affect this is that the app itself has a larger footprint (some more components, added a request…) that might have some timing effects? Please note though that the extra requests and components added in the newer version, are never actually used when the error occurs, since the app never has a chance to load.
The following is the code used to initialize the app (of course just a snippet, client and setClient() are React state):
useLayoutEffect(() => {
const script = document.createElement('script');
script.src = '{{{appclient}}}';
script.addEventListener('load', () => {
app.initialized().then((returnedClient) => {
setClient(returnedClient);
})
});
script.defer = true;
document.head.appendChild(script);
}, []);
useLayoutEffect(() => {
if (!client) return;
client.events.on('app.activated', handleAppActivated);
client.events.on('app.deactivated', handleAppDeactivated);
return () => {
client.events.off('app.activated', handleAppActivated);
client.events.off('app.deactivated', handleAppDeactivated);
}
}, [client]);
As previously mentioned, both versions of the custom app use the exact same code to initialize the app, but for some reason in the newer version it doesn’t work when you don’t hard reload the ticket page.
I have looked through the community forums and found some similar issues, the most common solution being using “useLayoutEffect” instead of “useEffect” when injecting the script tag and running app.initialized(). That one we already did however, so that did not solve the issue. And in most other cases it seems to be that it doesn’t work at all, which isn’t the case here since it works on hard reload.
Would appreciate some help on this issue. Thank you in advance!