-
Notifications
You must be signed in to change notification settings - Fork 4k
[fix] Scroll element into view race condition fix #11552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
✅ PR preview is ready!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request fixes a race condition encountered when scrolling target elements into view and introduces a new end-to-end test to verify anchor scrolling behavior.
- Refactors the StreamlitMarkdown component to remove the delayed scroll logic and instead use an immediate scroll call.
- Adds a new pytest marker and an end-to-end test in Playwright to verify anchor scrolling functionality.
- Updates the app fixture in the test configuration to support URL hash fragments.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.tsx | Refactors scroll behavior by removing an intermediate state and useEffect handler for scroll, directly scrolling the element when its ref is set. |
| e2e_playwright/st_markdown_test.py | Introduces a new test case to ensure that anchor scrolling brings the target header into view. |
| e2e_playwright/conftest.py | Modifies the app fixture to append a URL hash based on a pytest marker, enabling testing of hash-based navigation. |
Comments suppressed due to low confidence (2)
frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.tsx:223
- Removing the delayed scroll mechanism may cause the element to be scrolled to before it is fully rendered, especially in edge cases. Please ensure that this immediate scroll behavior is verified across various page load timings.
scrollNodeIntoView(node)
e2e_playwright/conftest.py:308
- Review the URL construction in the app fixture to ensure that appending the hash fragment does not lead to unintended formatting (such as an extra slash) which could affect routing. Consider clarifying this behavior with inline comments or tests.
response = page.goto(f"http://localhost:{app_port}/{hash_fragment}")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: This was a bit of a drive-by change to better leverage JSX since I was already working in this file.
|
Awesome! Can you add a test that this works with MPAv2 as well? Something like: import streamlit as st
def page1():
st.title("Page1")
st.write("""
Instructions:
* Click the button below.
* A new tab will open (that's OK)
* The app in that tab should scroll down to 'My title 2' -- but it won't!
""")
st.link_button("Open new tab", "/page2#my-title-2")
def page2():
st.title("Page2")
st.header("My title 1")
for _ in range(30):
st.text("blah " * 100)
st.header("My title 2")
for _ in range(30):
st.text("blah " * 100)
page = st.navigation(
[
st.Page(page1, title="Page1"),
st.Page(page2, title="Page2"),
]
)
page.run() |
70756bb to
5850f29
Compare
|
@sfc-gh-tteixeira Good idea, just added a test for this! |
sfc-gh-tteixeira
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had no idea you could use ref that way!
Describe your changes
GitHub Issue Link (if applicable)
Fixes #11551
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.