Initialize all columns when appending rows to data_editor#13916
Initialize all columns when appending rows to data_editor#13916lukasmasuch merged 3 commits intodevelopfrom
data_editor#13916Conversation
…editor When a user adds a row to a data_editor with num_rows='dynamic', cells were only created for currently visible columns. If the index column was hidden when adding the row, no cell was created for it. Later, when showing the hidden column via the "show/hide columns" menu, the code tried to access the cell but it didn't exist, causing the error "No cell found for an added row". The fix ensures cells are initialized for all columns (including hidden ones) when a new row is added. This allows columns to be shown/hidden without errors. Changes: - useDataEditor: Use allColumns instead of columns when initializing new rows - DataFrame: Pass allColumns parameter to useDataEditor - Tests: Updated all test cases and added a new test for this specific scenario
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
@cursor review |
data_editor
✅ PR preview is ready!
|
SummaryThis PR fixes issue #13915 where adding a row to a The fix is a one-line change in Code QualityThe change is minimal, well-targeted, and follows existing patterns in the codebase:
No issues found with code structure or maintainability. Test CoverageUnit tests: A dedicated test ("creates cells for hidden columns when row is appended (issue #13915)") directly reproduces the bug scenario by:
The test includes both positive assertions (cells exist for all columns) and the existing test ("allows to add new rows via onRowAppended") continues to validate the basic row-addition path. E2E tests: No new e2e test was added. The PR mentions manual Playwright verification. Given this is a targeted internal bugfix in the data grid editing logic, the unit test coverage is adequate. One minor gap: The test could additionally assert that no cells exist for the hidden column before the row append (negative/baseline assertion), which would strengthen the test. However, this is a very minor point and does not block approval. Backwards CompatibilityThis change is fully backwards compatible:
Security & RiskNo security concerns. The change is a low-risk bugfix:
AccessibilityNo accessibility impact. This is a data-layer fix in a React hook — no DOM elements, ARIA attributes, or keyboard interactions are affected. RecommendationsNo blocking issues. One minor suggestion:
VerdictAPPROVED: Clean, minimal, and well-tested bugfix that correctly initializes cells for hidden columns when appending rows, preventing a crash when those columns are later made visible. This is an automated AI review by |
| columns.forEach(column => { | ||
| // We use allColumns (including hidden columns) to ensure that | ||
| // cells are created for all columns. This prevents issues when | ||
| // a hidden column is later made visible. |
There was a problem hiding this comment.
nit: Could consider linking back to the original bug report in the comments for more context: #13916
- Add baseline assertion in test to verify row count before onRowAppended() - Add reference to issue #13915 in code comment for better context
Describe your changes
When a user adds a row to a
data_editorwithnum_rows='dynamic'and then shows a previously hidden column (like the index column) via the "show/hide columns" menu, the app crashes with "No cell found for an added row" error.Root cause: Cells were only initialized for currently visible columns when a row was added. When hidden columns were later made visible, the cells for those columns didn't exist, causing the error.
Fix: Initialize cells for all columns (including hidden ones) when a new row is appended. This is achieved by using
allColumnsinstead ofcolumnsin theappendEmptyRowfunction.GitHub Issue Link
Fixes #13915
Testing Plan
allColumnsparameter. All tests pass.Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.