Indeed something like a collapsible menu may call the backend to ask to open/close the menu.
But some frameworks may open the prefilled menu when you click it, and sync the state to the backend, instead of waiting for the backend to “approve” the request to open the menu.
Hypothetical example:
m = menu(1, 2, 3)
if m.opened:
print(“It was opened.”)
Here there may not be any UI latency when opening the menu. The menu opens when you click it, and the state is synced to the backend. However,
m = menu(1, 2, 3)
b = button(“open the menu”)
if b.clicked:
m.opened = True
In this program, there will be a round trip to the backend when you click the button to indirectly open the menu.
Overall, it depends on how you design the framework and how you divide interaction control between backend and frontend. Controlling every little interaction thru the backend is probably not a good idea, and you should bake some frontend interactions into the UI components.