Skip to content

[BUG] Issue in should_render: incorrect old/new state comparison and redundant calls #768

@Subham1100

Description

@Subham1100

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 return True 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:

  1. Create a hello.py file with a table and a checkbox that displays a text.
  2. Go to utils.py and find the has_changed function.
  3. Log old_clean and new_clean.
  4. 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 and new_clean should be equal.
  • should_render should return False 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:

Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions