Skip to content

Commit

Permalink
prevent two deletions because of two subsequent disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Jan 29, 2025
1 parent 3cff467 commit 5ae38b3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions nicegui/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ def on_disconnect(self, handler: Union[Callable[..., Any], Awaitable]) -> None:

def handle_handshake(self, next_message_id: Optional[int]) -> None:
"""Cancel pending disconnect task and invoke connect handlers."""
if self._delete_task:
self._delete_task.cancel()
self._delete_task = None
self._cancel_delete_task()
self._num_connections += 1
if next_message_id is not None:
self.outbox.try_rewind(next_message_id)
Expand All @@ -251,6 +249,7 @@ 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."""
self._cancel_delete_task()
self._num_connections -= 1
for t in self.disconnect_handlers:
self.safe_invoke(t)
Expand All @@ -263,6 +262,11 @@ async def delete_content() -> None:
self.delete()
self._delete_task = background_tasks.create(delete_content())

def _cancel_delete_task(self) -> None:
if self._delete_task:
self._delete_task.cancel()
self._delete_task = None

def handle_event(self, msg: Dict) -> None:
"""Forward an event to the corresponding element."""
with self:
Expand Down

0 comments on commit 5ae38b3

Please sign in to comment.