Skip to content

Fix dataframe maximum update depth error #9490

Merged
lukasmasuch merged 13 commits intodevelopfrom
fix/dataframe-max-update-depth-error
Sep 19, 2024
Merged

Fix dataframe maximum update depth error #9490
lukasmasuch merged 13 commits intodevelopfrom
fix/dataframe-max-update-depth-error

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Sep 17, 2024

Describe your changes

Fixes an issue with the dataframe component that causes random crashes:

image

The crash can happen on low-resolution monitors if dataframes are rendered with use_container_width=True are used in some of our containers (popover, tabs, sidebar, columns). It appears that our width calculation in the Block component causes this. If the width can't be determined yet by the resize observer, it can be -1 for some time. This seems to be a trigger for the maximum update depth. Unfortunately, I don't have a validated explanation of why it actually leads to the error :(

GitHub Issue Link (if applicable)

Testing Plan

  • Add e2e test to discover similar breakage.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@lukasmasuch lukasmasuch added security-assessment-completed change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Sep 17, 2024
@lukasmasuch lukasmasuch changed the title Fix dataframe maximum update depth error [WIP] Fix dataframe maximum update depth error Sep 17, 2024
@lukasmasuch lukasmasuch marked this pull request as ready for review September 18, 2024 00:53
@lukasmasuch lukasmasuch changed the title [WIP] Fix dataframe maximum update depth error Fix dataframe maximum update depth error Sep 18, 2024
Comment on lines +15 to +16
"""This test checks that the dataframe component renders without crashing
when used in different containers.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test always failing without the fix? I assumed its pretty difficult to hit the issue. If it usually does not fail even without the fix, it might make sense to add a comment here.

Copy link
Copy Markdown
Collaborator Author

@lukasmasuch lukasmasuch Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, I was able to trigger the error in the st_popver case in CI run when configuring the one dataframe to use container width. But not consistently. Based on that, I believe it could happen in CI, probably also because the CI uses a resolution around ~1200x700. But I think the test is mostly about giving us some safeguarding around similar types of crashes for dataframe.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a comment.

Comment on lines +111 to 124
let maxWidth = availableWidth

if (element.useContainerWidth) {
// Always use the full container width
initialWidth = containerWidth
// If user has set use_container_width,
// use the full container width.
initialWidth = availableWidth
} else if (element.width) {
// User has explicitly configured a width
initialWidth = Math.min(
Math.max(element.width, MIN_TABLE_WIDTH),
containerWidth
availableWidth
)
maxWidth = Math.min(Math.max(element.width, maxWidth), containerWidth)
maxWidth = Math.min(Math.max(element.width, maxWidth), availableWidth)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the multiple usage of nested min-max calls make it sufficiently hard to read and understand to warrant moving this into its own function and add some comments 😅 I think it would be good to have a list of the different widths in bullet points below each other giving a brief explanation why its needed and what the differences are and how it is calculated in a few words.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a lot more comments 👍

Copy link
Copy Markdown
Collaborator

@raethlein raethlein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for getting to the bottom of this very gnarly issue 🚀 And thanks for adding the comments 👍

@lukasmasuch lukasmasuch merged commit 7f43ef6 into develop Sep 19, 2024
@lukasmasuch lukasmasuch deleted the fix/dataframe-max-update-depth-error branch September 19, 2024 10:09
edegp pushed a commit to edegp/streamlit that referenced this pull request Jan 19, 2025
## Describe your changes

Fixes an issue with the dataframe component that causes random crashes:


![image](https://github.com/user-attachments/assets/da32e051-95ac-4562-aee6-bdb82a2fbd27)

The crash can happen on low-resolution monitors if dataframes are
rendered with `use_container_width=True` are used in some of our
containers (popover, tabs, sidebar, columns). It appears that our width
calculation in the Block component causes this. If the width can't be
determined yet by the resize observer, it can be -1 for some time. This
seems to be a trigger for the maximum update depth. Unfortunately, I
don't have a validated explanation of why it actually leads to the error
:(

## GitHub Issue Link (if applicable)

- Closes streamlit#7949

## Testing Plan

- Add e2e test to discover similar breakage. 

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

st.dataframe crashes with maximum update depth exceeded

2 participants