Skip to content

Conversation

@sfc-gh-pchiu
Copy link
Contributor

@sfc-gh-pchiu sfc-gh-pchiu commented Oct 24, 2024

Describe your changes

Update:
In this update, we revamped the preferredLayouts state in App.tsx (previously pageLayouts) and fixed a number of issues with

  1. apps flickering (when not calling set_page_config)
  2. apps having fragments rerunning
  3. wide mode in User Settings

Here's a breakdown of the implementation by functions/files:

  1. handlePageConfigChanged & saveSetting: set_page_config and User Settings panel are the 2 only places that could change the layout. As a result, we save the layout value to preferredLayouts in these 2 handlers
  2. handleNewSession (not changed): For every rerun, we apply previously saved preferredLayouts of the corresponding page. If none matches, apply CENTERED
  3. handleNavigation: If we get a new page script hash from navigation which has never been initialized in preferredLayouts, we carry over the layout from previous page for the new one.

--

We are seeing an unexpected behavior such that when an MPA page containing fragments reruns, the page layout would change to centered. This is an issue reported in our forum flagged by @raethlein. Upon investigation, we have identified that the fix in #9479 introduced this behavior change.

The root cause is that after a triggered rerun the page script hash changes, causing the pageLayouts object state not recognizing the new hash value and assigning the default/centered layout.
Our proposed fix here is to only perform layout update when there is no fragment running.

I also added new e2e test cases with fragments to verify the fix.

GitHub Issue Link (if applicable)

Post in discuss forum

Testing Plan

  • E2E Tests: new test case in MPAv2 that mocks fragment rerunning

Manually testing app reported in forum

Before

Screen.Recording.2024-10-24.at.5.09.41.PM.mov

After

Screen.Recording.2024-10-24.at.5.07.00.PM.mov

Contribution License Agreement

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

@sfc-gh-pchiu sfc-gh-pchiu changed the title Fix/mpa page layout fragment [fix] MPA page layout resetting if page has fragment Oct 24, 2024
@sfc-gh-pchiu sfc-gh-pchiu added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Oct 25, 2024
@sfc-gh-pchiu sfc-gh-pchiu force-pushed the fix/mpa-page-layout-fragment branch from 0f5c431 to cddb812 Compare October 25, 2024 00:15
@sfc-gh-pchiu sfc-gh-pchiu force-pushed the fix/mpa-page-layout-fragment branch from cddb812 to ccca79e Compare October 25, 2024 00:18
@sfc-gh-pchiu sfc-gh-pchiu marked this pull request as ready for review October 25, 2024 00:18
@sfc-gh-pchiu sfc-gh-pchiu marked this pull request as draft October 28, 2024 17:58
@sfc-gh-pchiu sfc-gh-pchiu changed the title [fix] MPA page layout resetting if page has fragment [fix] Revamp preferredLayouts state for set_page_config and layout in User Settings Oct 29, 2024
@sfc-gh-pchiu sfc-gh-pchiu marked this pull request as ready for review October 29, 2024 18:27
@sfc-gh-pchiu sfc-gh-pchiu requested a review from a team as a code owner October 29, 2024 18:27
@sfc-gh-pchiu sfc-gh-pchiu marked this pull request as draft October 29, 2024 19:18
@sfc-gh-pchiu sfc-gh-pchiu marked this pull request as ready for review October 29, 2024 19:22
@sfc-gh-pchiu sfc-gh-pchiu removed the request for review from a team October 29, 2024 19:22
Copy link
Collaborator

@kmcgrady kmcgrady left a comment

Choose a reason for hiding this comment

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

LGTM. Very simple and easy to follow

@sfc-gh-pchiu sfc-gh-pchiu merged commit 8cfd316 into develop Oct 30, 2024
kmcgrady added a commit that referenced this pull request Oct 30, 2024
…nd layout in User Settings (#9723)"

This reverts commit 8cfd316.
edegp pushed a commit to edegp/streamlit that referenced this pull request Jan 19, 2025
…t in User Settings (streamlit#9723)

## Describe your changes

Update:
In this update, we revamped the `preferredLayouts` state in `App.tsx`
(previously `pageLayouts`) and fixed a number of issues with
1. apps flickering (when not calling `set_page_config`) 
2. apps having fragments rerunning
3. wide mode in User Settings

Here's a breakdown of the implementation by functions/files:
1. `handlePageConfigChanged` & `saveSetting`: `set_page_config` and User
Settings panel are the 2 only places that could change the layout. As a
result, we save the layout value to `preferredLayouts` in these 2
handlers
2. `handleNewSession` (not changed): For every rerun, we apply
previously saved `preferredLayouts` of the corresponding page. If none
matches, apply `CENTERED`
3. `handleNavigation`: If we get a new page script hash from navigation
which has never been initialized in `preferredLayouts`, we carry over
the layout from previous page for the new one.

--

~~We are seeing an unexpected behavior such that when an MPA page
containing fragments reruns, the page layout would change to centered.
This is an [issue reported in our
forum](https://discuss.streamlit.io/t/bad-setin-index-issue-with-using-fragments-that-do-not-render-anything-within-multipage-app/82675/9?u=raethlein)
flagged by @raethlein. Upon investigation, we have identified that the
fix in streamlit#9479 introduced this behavior change.~~

~~The root cause is that after a triggered rerun the page script hash
changes, causing the `pageLayouts` object state not recognizing the new
hash value and assigning the default/centered layout.
Our proposed fix here is to only perform layout update when there is no
fragment running.~~

~~I also added new e2e test cases with fragments to verify the fix.~~

## GitHub Issue Link (if applicable)
[Post in discuss
forum](https://discuss.streamlit.io/t/bad-setin-index-issue-with-using-fragments-that-do-not-render-anything-within-multipage-app/82675?u=raethlein)

## Testing Plan

- E2E Tests: new test case in MPAv2 that mocks fragment rerunning

### Manually testing app reported in forum
#### Before


https://github.com/user-attachments/assets/41c3f629-5f69-42c3-9e5f-e0fec9d1bff3

#### After


https://github.com/user-attachments/assets/77de515e-2e89-47d4-b49d-c03126d61f41


---

**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 security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants