Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: infinite render loop in List Widget when hiding/unhiding with se…
…lected item (#39262) ## Description When a List widget has a selected item and is hidden then unhidden (unmounted/mounted), an infinite render loop occurs in the following flow: ```typescript // Triggered in componentDidUpdate if (this.shouldUpdateSelectedItemAndView() && isString(this.props.selectedItemKey)) { this.updateSelectedItemAndPageOnResetOrMount(); } ``` ### Root Cause This happens because: 1. `updateSelectedItemAndPageOnResetOrMount` calls `updatePageNumber`. 2. `updatePageNumber` uses `calculatePageNumberFromRowIndex`, which depends on `this.pageSize`. 3. Each page number calculation triggers a meta property update through `onPageChange`. 4. This meta update causes a rerender, repeating the cycle. #### Problematic Calculation `this.pageSize` is calculated dynamically based on widget dimensions: ```typescript calculatePageNumberFromRowIndex = (index: number) => { return Math.ceil((index + 1) / this.pageSize); // Using unstable this.pageSize }; ``` This creates instability during mount/unmount cycles as: - Widget dimensions may not be fully stabilized. - Each meta property update triggers recalculation. - No break in the update-rerender cycle. ### Solution Use `this.props.pageSize` instead of `this.pageSize` in page calculations: ```typescript calculatePageNumberFromRowIndex = (index: number) => { return Math.ceil((index + 1) / this.props.pageSize); // Using stable props value }; ``` ### Why This Works - `this.props.pageSize` represents the last stable value set through the meta property system. - It's protected by the existing `pageSizeUpdated` flag mechanism. - Breaking the dependency on dynamically calculated dimensions prevents the infinite loop. Fixes #37683 ## Automation /ok-to-test tags="@tag.Widget, @tag.Binding, @tag.List, @tag.Sanity" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/13366216706> > Commit: 74028ec > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13366216706&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Widget, @tag.Binding, @tag.List, @tag.Sanity` > Spec: > <hr>Mon, 17 Feb 2025 10:23:19 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved the list widget’s pagination by updating how page numbers are calculated, ensuring accurate reflection of the current page size settings. - **Tests** - Enhanced test coverage for the list widget's visibility, adding new tests to validate user interactions and ensuring the widget behaves as expected when items are selected. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information