anjunatl / react-table-bug-repro

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Row deselection bug in react-table

Summary

react-table (seen in both v7.5.1 & v7.6.3) with manualPagination & useRowSelect crashes when deselecting rows that are not on the currently visible page. Data for this example is provided by Laravel's server-side pagination

Reproduction steps

toggleAllRowSelected - not all rows get cleared

  1. Run docker-compose up to start the example
  2. Choose one to many rows on the first page
  3. Change to another page
  4. Choose another one to many rows
  5. Click the "Do something" button

Expected behavior

The selected row counter should reset to 0.

Actual behavior

The selected row counter is not 0 & is the sum of selected rows on non-visible pages

toggleRowSelected - crashes

  1. Run docker-compose up to start the example
  2. Click the "Mode" button to change it from "All" to "Row" to enable use of toggleRowSelected
  3. Choose one to many rows on the first page
  4. Change to another page
  5. Choose another one to many rows
  6. Click the "Do something" button

Expected behavior

The selected row counter should reset to 0.

Actual behavior

The page crashes

Bug details

This started when trying to use toggleAllRowsSelected(false) to clear all the selected rows, but that resulted in only the current visible rows being deselected - you could go to the other pages with previously selected rows and still see them selected.

To work around this, I tried tracking the selected row IDs externally & using toggleRowSelected(rowId, false) to iterate over the selected IDs to set selected=false but then the page crashed when it tried to toggle a row that was not visible.

Using toggleRowSelected, the following lines in useRowSelect.js break when a not-visible row is being deselected:

const row = rowsById[id]    // off-page row = undefined
if (!row.isGrouped) { ...   // errors here
  • By design when server-side pagination is enabled, only the displayed rows are returned from the API - IE page[] = rows[]
  • useRowSelect seems to expects rows[] to have all possible, not just the currently visible ones

Potential fix

Example source highlights

Related GitHub issues / PRs

About


Languages

Language:Shell 100.0%