I couldn't make a reproduction because it requires a testing framework to click the button very quickly.
my expectation is that if the page is being rendered, the middleware should already be finished by then. Is it more likely the problem is on the framework side or my incorrect usage of the middleware?
otherwise is there a designed way of handle this situation?