Persistent Issue with Property Updates in Custom Components (Beta Designer Specific)

Hello Anvil Community,

I am reaching out for assistance regarding a persistent issue I’ve encountered with property updates in custom components, specifically within the [Beta] Anvil designer.

Issue Overview: In my custom components, I’ve been facing challenges with property updates not being retained. This issue is not confined to a single property but affects various properties. To illustrate, I’ll reference the spacing_above property, but it’s important to note that this is part of a broader problem.

Here’s an example setup for context:

pythonCopy code

@property
def spacing_above(self):
    return self.column_panel.spacing_above

@spacing_above.setter
def spacing_above(self, value):
   self.column_panel.spacing_above = value

Problematic Behavior: The expected behavior is for updates made to properties in the custom components to persist. However, I observe that when I close and then reopen the Form containing these components in the [Beta] Anvil designer, the changes are not retained.

Error Encountered in Beta Designer: Additionally, each time I open this Form in the [Beta] designer, I encounter the following error:

javascriptCopy code

[An internal error has occurred] - see browser console for more details
TypeError: Cannot read properties of null (reading 'addEventListener')
    at [URL]

This issue seems specific to the [Beta] version of the Anvil designer. I’m seeking insights into why these property changes are not being preserved and how to resolve the error encountered in the designer. Any advice, shared experiences, or suggestions from the community would be immensely helpful.

Thank you for your time and assistance!

I don’t have any problem with property value persistency with my custom components, so this seems to be a problem specific of your specific case.

I would investigate the error first. I have the feeling that fixing that error will allow the IDE to complete whatever it’s doing and fix the persistency problem.

Try to remove any code that is executed when changing any of your component properties, and see if the error keeps happening.

Chances are that the setter for property1 has a problem and raises the error, then the IDE stops processing your changes, and forgets about persisting property2. The problem could be in the setter of any property, or on anything that happens during the rendering of the component, which is triggered after any of the properties is edited.

You can use in_designer to avoid running code that would fail in the IDE.

If you’re not able to debug the error, can you replicate the error in a simple app that you can provide a clone link to?

2 Likes

In my code it is spelled “@property”.

1 Like

Lol, thanks. I must have been typing really quickly when I wrote this post! I’m also a horrible speller :face_with_spiral_eyes:

Thank goodness for spell check (which, I obviously did not use when posting).

Thanks, for looking into it. When I get more time to dive into it, I will try what you have suggested and see if I can nail down the culprit. I know I have had issues using the in_designer function. If memory serves me, I have run into import issues, so I’ve just replaced many of the areas I would have used it with try/except (which, I know is not the most pythonic, but I just don’t have the time to fiddle with it).