Parcourir la source

handle timeout errors for infinite scroll example (fixes #2966)

Falko Schindler il y a 1 an
Parent
commit
35b23ae6c3
1 fichiers modifiés avec 5 ajouts et 2 suppressions
  1. 5 2
      examples/infinite_scroll/main.py

+ 5 - 2
examples/infinite_scroll/main.py

@@ -7,8 +7,11 @@ from nicegui import ui
 @ui.page('/')
 async def page():
     async def check():
-        if await ui.run_javascript('window.pageYOffset >= document.body.offsetHeight - 2 * window.innerHeight'):
-            ui.image(f'https://picsum.photos/640/360?{time.time()}')
+        try:
+            if await ui.run_javascript('window.pageYOffset >= document.body.offsetHeight - 2 * window.innerHeight'):
+                ui.image(f'https://picsum.photos/640/360?{time.time()}')
+        except TimeoutError:
+            pass  # the client might have disconnected
     await ui.context.client.connected()
     ui.timer(0.1, check)