PromucFlow_constructor/app/client/cypress/e2e/Regression/ClientSide/Widgets
Jacques Ikot c0e073efa3
fix: infinite render loop in List Widget when hiding/unhiding with selected 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: 74028ec9f52aa25daf0d72c7cdf3c4fa9701e86e
> <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 -->
2025-02-17 11:43:24 +01:00
..
Audio chore: AppIDE Folder Structure (#39165) 2025-02-17 10:34:23 +03:00
Button chore: update select component (#38954) 2025-02-06 13:10:25 +05:30
Camera chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Chart chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Checkbox chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
CodeScanner chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
CurrencyInput chore: update select component (#38954) 2025-02-06 13:10:25 +05:30
Custom chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Datepicker test: datepicker3 test fix (#39019) 2025-02-14 08:38:01 +05:30
Divider chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
DocumentViewer chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Dropdown chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Filepicker chore: update select component (#38954) 2025-02-06 13:10:25 +05:30
Form chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Iframe fix: Fix iframe and widget test case for clicking (#38039) 2024-12-09 19:00:43 +05:30
Image chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Input chore: update select component (#38954) 2025-02-06 13:10:25 +05:30
JSONForm fix: Update button property text (#38758) 2025-01-21 10:39:30 +05:30
List chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
ListV2 fix: infinite render loop in List Widget when hiding/unhiding with selected item (#39262) 2025-02-17 11:43:24 +01:00
Modal chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Multiselect chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Others chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
PhoneInput chore: update select component (#38954) 2025-02-06 13:10:25 +05:30
Radio test: new test cases framework functions and Action selector (#37566) 2024-12-16 16:41:54 +05:30
Rating chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
RTE chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Select chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Sliders test: new test cases framework functions and Action selector (#37566) 2024-12-16 16:41:54 +05:30
Statbox chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Switch chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Tab test: fix tabs skipped test CE (#37023) 2024-10-25 21:21:57 +05:30
TableV2 chore: Remove HTML column type feature flag and related code (#39108) 2025-02-10 14:50:25 +05:30
Text chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
TreeSelect chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Video chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Container_spec.js chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
ContainerTest2_spec.ts chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
deprecatedWidgets_spec.js chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Disabled_Widgets_drag_validation_spec.js chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Migration_Spec.js chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Tab_reset_spec.js chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
WidgetCanvas_spec.js test: Cypress - @tag.Video, @tag.Container, @tag.Switch, @tag.Slider, @tag.Tab, @tag.Table, @tag.Select (#29698) 2023-12-18 17:05:27 +05:30
WidgetCopyPaste_spec.js chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
WidgetGrouping_spec.js chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Widgets_Labels_spec.js chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
WidgetSelection_spec.js chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30