widgetti / solara

A Pure Python, React-style Framework for Scaling Your Jupyter and Web Apps
https://solara.dev
MIT License
1.6k stars 104 forks source link

feat: detect mutation to values of reactive vars #595

Open maartenbreddels opened 3 weeks ago

maartenbreddels commented 3 weeks ago

A common source of error is mutation of values in reactive vars. The reactive var cannot notice a change in its value (e.g. a list) if the list is mutated in place.

A user can be mislead that it is working correctly, when another reactive variable triggers a rerender, teaching bad habits.

Detecting mutations in Python without using proxies can be done by making a deepcopy of the object, and comparing the reference to the deepcopy.

This comes at the cost of performance and memory usage, therefore we should enabled this by default in development mode (tests run in this mode by default), so app builders are aware of mistakes while developing. In production mode we can disable the mutation checks and behave as before.

TODO:

render[bot] commented 3 weeks ago

Your Render PR Server URL is https://solara-stable-pr-595.onrender.com.

Follow its progress at https://dashboard.render.com/web/srv-cobsprocmk4c73e74mng.