justpy icon indicating copy to clipboard operation
justpy copied to clipboard

deleted components show up at button callback

Open eudoxos opened this issue 4 years ago • 4 comments

I am refreshing portions (div, contains the configuration section) of a page by periodically deleting the div's content using delete_components, re-creating it (from fresh data) and calling jp.run_task(wp.update()) afterwards. This works well (no flickering or anything).

The moment I click a button, however, the div appears with the content twice (as if not deleted, maybe it is the previous content somehow hanging around?), until the page refreshes itself again, as shown in the video. The self.update() is only called explicitly from within the periodic refresher.

Is that something known (and workaroundable) or should I provide a MWE?

aaa1-2020-11-24_11 20 34

eudoxos avatar Nov 24 '20 10:11 eudoxos

An example would be very helpful, if possible.

elimintz avatar Nov 24 '20 18:11 elimintz

Here you go :)

import justpy as jp
import asyncio

@jp.SetRoute('/')
class MainPage(jp.QuasarPage):
    def __init__(self):
        super().__init__(delete_flag=False)
        self.div=jp.Div(a=self)
        self.butt=jp.QButton(text='Button',a=self)
        self.butt.on('click',self.onButtClick)
        jp.run_task(self.pageUpdater())
    def onButtClick(self,b):
        return
    async def pageUpdater(self):
        while True:
            self.div.delete_components()
            jp.QMarkupTable(a=self.div,children=[jp.AutoTable(values=[['A','B','C','D'],['1','2','3','4']])])
            jp.run_task(self.update())
            await asyncio.sleep(1)

jp.justpy()

eudoxos avatar Nov 24 '20 18:11 eudoxos

It is a weird bug. For now, I don't have an answer as to why this is happening but there is a simple workaround. Change onButtClitck to:

def onButtClick(self,b):
        return True

This will cause the page not to update once the click event handler is done running.

elimintz avatar Nov 24 '20 19:11 elimintz

Confirming that returning True from the handler (in the MWE and also in the more complicated script I use) prevents the refresh from happening. Thanks :)

eudoxos avatar Nov 24 '20 20:11 eudoxos