Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only delete page content if the number of connections is zero #4285

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
define async delete function more locally
  • Loading branch information
falkoschindler committed Jan 29, 2025
commit 3cff4670e1fb960671815317ea561c0a7919f521
8 changes: 4 additions & 4 deletions nicegui/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,16 @@ def handle_handshake(self, next_message_id: Optional[int]) -> None:

def handle_disconnect(self) -> None:
"""Wait for the browser to reconnect; invoke disconnect handlers if it doesn't."""
async def delete_content() -> None:
await asyncio.sleep(self.page.resolve_reconnect_timeout())
if self._num_connections == 0:
self.delete()
self._num_connections -= 1
for t in self.disconnect_handlers:
self.safe_invoke(t)
for t in core.app._disconnect_handlers: # pylint: disable=protected-access
self.safe_invoke(t)
if not self.shared:
async def delete_content() -> None:
await asyncio.sleep(self.page.resolve_reconnect_timeout())
if self._num_connections == 0:
self.delete()
self._delete_task = background_tasks.create(delete_content())

def handle_event(self, msg: Dict) -> None:
Expand Down