Skip to content

Default row id is not stable or unique when data is modified #4162

Closed

Description

@krispya

Describe the bug

The cell id is meant to be a unique id, but it is based on the indice of the cell in the data representation. What this means is if you move a cell around or modify data by deleting or adding cells then its id changes. Even worst, other cells will inherit the id the cell previously had leading to all sorts of shenanigans in React if it is used as a key. I think the cell id should be made stable and unique such that it can be safely used as a key.

Your minimal, reproducible example

x

Steps to reproduce

x

Expected behavior

x

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

x

react-table version

8.2.6

TypeScript version

No response

Additional context

No response

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Activity

  1. tannerlinsley commented on Jul 17, 2022

    @tannerlinsley
    Member

    As far as I know, no IDs in the system are index based other than the default row ID accessor. Can you elaborate a bit more? Maybe link to the source or an example?

  2. krispya commented on Jul 17, 2022

    @krispya
    ContributorAuthor

    I'm sorry I just realized this was an example of me not understanding the docs the first time I read them. getRowId solved my issue.

    To be more specific, the issue was that the row id was by default based on its index which causes everything that uses an id as key to be brittle, including the cell id. Maybe the solution here is give a big warning in the docs, but also I wonder if there is interest in having the default row id be more stable to data updates.

    To elaborate on my doc experience, what I had done first was go to the the Cell API documentation and read that id was unique and then carried on with my day. I didn't think to look at the Row or Table documentation to read further. 😅

  3. changed the title [-]Cell `id` is not stable or unique when data is modified[/-] [+]Default row `id` is not stable or unique when data is modified[/+] on Jul 17, 2022
  4. tannerlinsley commented on Jul 17, 2022

    @tannerlinsley
    Member

    Yeah I get your sentiment. But we can only know so much about the nature of your data. The alternative of requiring a row id accessor is also not that wonderful. This is the happy medium :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions