Hi there,
It looks like we are encountering a bug in Forge related to the “Allow Access” screen. When a user wants to use your forge app for the first time and your app sends a request, a “Allow Access” button is displayed. The request of your app is stalled until the user gives the required permissions to your app.
That works pretty fine, but only if there’s one single “stalled request”. If there are multiple “stalled requests”, only the first one is actually finished, after the button is pressed. Here’s a demo of what that looks like (notice how “B” never finishes loading, because the graphql request isn’t resent):
The code needed to reproduce this is quite simple. First, you need a forge function that calls an endpoint which requires a scope:
import Resolver from '@forge/resolver';
const resolver = new Resolver();
// Make some request to trigger the "Allow Access" prompt
resolver.define('SOMETHING', async({context}) => {
const spaceKey = context.extension.space.key;
await api.asUser().requestConfluence('/wiki/rest/api/space/' + spaceKey);
return 'DONE';
});
export const handler = resolver.getDefinitions();
For the frontend, I’m using Custom UI:
import React from 'react';
import ReactDOM from 'react-dom';
import '@atlaskit/css-reset';
import {invoke} from '@forge/bridge';
const fetchSomething = async(setValue) => {
const value = await invoke('SOMETHING');
setValue(value);
};
function BugDemo() {
const [a, setA] = React.useState('Loading...');
const [b, setB] = React.useState('Loading...');
React.useEffect(() => {
// Sending two requests at once, only first one will finish after "Allow Access"
fetchSomething(setA);
fetchSomething(setB);
}, []);
return (
<ul>
<li>A: {a}</li>
<li>B: {b}</li>
</ul>
);
}
ReactDOM.render(
<BugDemo/>,
document.getElementById('root')
);
In this example, we could of course very easily fix this by await
ing each fetchSomething
call. But in our actual app we are sending several independent requests at once which we really cannot make wait for each other as that would massively slow down the loading time / performance of our app.
So my question is: Is there an easy way to prevent this from happening? Is there a way for us to send multiple requests at once without out the “Allow Access” process breaking our app?
Cheers,
Sven