Form_show fires twice

I have a form that shows inside a content panel (material template style). It’s set to show full width.

The form’s show event calls a server function that takes a few seconds to run (about 5-10). During this time the form is not shown at full width. Once it’s finished running and returns a value, the form then expands to full width.

Problem is, it fires the form’s show event again, causing the long server function to be called a second time, delaying the form’s usability.

I can get around it by having a “debounce” property that’s set on first event execution and tested against before running the server function, but should the event fire a second time?

Are you able to share a clone link, perhaps for a cut-down app that contains only the problem?

I can’t share the original project as it’s a little sprawling, but I’ve recreated what I believe to be the relevant bits and it doesn’t go wrong in a new project.

The original project was created in may '18 and is the old style admin template. Might be something to do with that. Not sure, but I’m not going to get too worried about it. It’s a slight pain as it slows down a customer project but I’m intending to rewrite it using the material design anyway at some point.

The loaded form definitely doesn’t expand until the long running server call in its show event has returned, but it does appear to fire the show event only once.

Nice to hear it works properly in a new project - perhaps a debounce as a workaround for the old project is the best way to go, it doesn’t sound like we can get enough information to figure out what’s wrong.

Regarding the full_width problem, I’ve been tinkering and I can’t seem to reproduce it. I’ve created a server function that runs for 7 seconds and called it from a Form’s form_show method. Then I’ve included that Form in another Form, programatically on button push as well as by drag-and-drop as a custom component. In any case I don’t see a change in display width, with various different things set to full_width_row.

Can you describe the exact layout/procedure of the cut-down app, or maybe share the clone link?

This shows the delay in going full width :

https://anvil.works/build#clone:2TE4TKGKUAUPE7F6=AW3EFDAE2CF3DSQSMPW3JSMR

but yeah the workaround is absolutely fine for the double firing.

You could change the version in the yaml (git clone, change version, git push) just to see if it’s a problem that has been resolved.
Changing version of an app is dangerous and could break it, so you should immediately put it back to what it was, but it’s worth trying just to understand if it is an old problem that has already been fixed.

Thanks for that @david.wylie, I think this is a bug, so moving to Bug Reports and raising an issue in our tracker.

Whether or not you can find a workaround depends on your use-case. If it’s ok to not show the new Form until the long-running function has returned, you can set self.visible = False in __init__ and self.visible = True at the end of form_show:

https://anvil.works/build#clone:RDOBUWOMAKLCJNYC=5T53JFFL474MS7RPOEQOK3OA

Will this work for you?

The late expansion of the form is not an issue for me, tbh. It was the double firing of the show event after it expanded that caused the problem. And with the debounce code that’s all fine again.

I might try @stefano.menci 's suggestion just as an exercise, but other than that, I’m all good now.

Cheers.

Ok, I’m glad there’s no problem as far as your app is concerned. Thanks again for letting us know.

I think I am experiencing a version of this bug. Debounce code resolves it, though, giving me back my sanity. Thanks!