How to avoid page updates? #41
-
Do I understand correctly that any event handler (upload, click, timer, etc.) by default leads to full page update and the handler should return False to prevent that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Yes, that's a rather non-obvious "feature" NiceGUI adopts from JustPy: To avoid a complete page update after handling an event, the event handler should return Right now I can't find JustPy's documentation about that. But here is a corresponding comment in the source code: # If page is not to be updated, the event_function should return anything but None
if event_result is None:
if com_type == 0: # WebSockets communication
if LATENCY:
await asyncio.sleep(LATENCY / 1000)
await p.update()
elif com_type == 1: # Ajax communication
build_list = p.build_list() Usually the default behavior should be fine, but for frequent events (or timer callbacks) it's reasonable to return |
Beta Was this translation helpful? Give feedback.
-
Since NiceGUI 0.8.0 this is no longer the case. Event handlers don't automatically update the whole page. Only elements that are directly modified (e.g. their text, value, style, classes or props) are sent to the client. In edge cases you might need to trigger an explicit |
Beta Was this translation helpful? Give feedback.
Since NiceGUI 0.8.0 this is no longer the case. Event handlers don't automatically update the whole page. Only elements that are directly modified (e.g. their text, value, style, classes or props) are sent to the client. In edge cases you might need to trigger an explicit
ui.update
for individual elements.