-
Notifications
You must be signed in to change notification settings - Fork 664
Description
Describe the bug
While working on the internship assessment, I noticed that updating one component’s state (like a checkbox) causes all components to re-render, including heavy ones like tables. This leads to unnecessary performance hits and noticeable UI lag for large components.
The should_render
function in utils.py
(called in render_tracking.py
) is being called twice per component, and the hash-based comparison is not working as expected.
Specifically:
- The code stores a hash of the old component data.
- But when comparing, it does not hash the new data — instead, it compares raw cleaned values, which causes
has_changed
to returnTrue
even when values are the same. - Also, after each update, the
state_cache
does not retain updated state, which breaks comparison in the next render.
To Reproduce
Steps to reproduce the behavior:
- Create a
hello.py
file with a table and a checkbox that displays a text. - Go to
utils.py
and find thehas_changed
function. - Log
old_clean
andnew_clean
. - Observe the output after toggling the checkbox.
Expected behavior
has_changed
should be called once per component, not twice.- If a component hasn’t changed,
old_clean
andnew_clean
should be equal. should_render
should returnFalse
if values are identical.
Screenshots
Below, I modified the code to compare the hash of both old and new values, exposing the issue of should_render
always returning True
:
Environment:
- OS: macOS
- Browser: Chrome
- Version: 137
Additional context
In render_tracking.py
, I attempted the following change to avoid double invocation of should_render
:
from this
component['shouldRender'] = service.should_render(component_id, component)
# Append component only if changed
if service.should_render(component_id, component):
to this
component['shouldRender'] = service.should_render(component_id, component)
# Append component only if changed
if component['shouldRender']:
still the issue is there