How to close the whole app when user closes FastListTemplate window?

My app uses a FastListTemplate with which the user operates. The program should be shut down when the user closes the browser window. How can I implement that? Is this a show() / serve() issue? I’m using show() because I had some problems with servable() in my development environment. I suppose that servable() and serve() combination is the preferred/correct way for the production version?

EDIT: it doesn’t seem to depend on show() / serve().

I managed to apply this method to my app: pn.state.on_session_destroyed() never called · Issue #3601 · holoviz/panel · GitHub
I agree that it is not very stylish solution. But it seems to be the only option for my case.