Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TableState does not account for options.state properties being set as undefined #5909

Open
2 tasks done
Beiufin opened this issue Feb 6, 2025 · 0 comments
Open
2 tasks done

Comments

@Beiufin
Copy link

Beiufin commented Feb 6, 2025

TanStack Table version

v8.20.6

Framework/Library version

Core

Describe the bug and the steps to reproduce it

The CoreOptions#state is set to Partial<TableState> allowing consumers to omit any property on the state. However, this also means that consumers can set properties to undefined. This is not accounted for when merging in new options.state. When a state property is passed in as undefined, it will still overwrite whatever value was there before.

The type of table.options.state and return of table.getState() (TableState) has many (all?) of its properties as required, so when the above occurs, undefined can be set for a required property. This type violation is being hidden by the type assertion in setOptions

As a result, various places throughout the code base that trust the TableState type can end up try to access fields on undefined values, and causing a crash. Such as #4697

Some places account for this by checking for undefined (even though the type says it is not possible), however there are still cases where this is not considered, such as:

Either:

The type for table.options.state and return of table.getState() should be changed to Partial<TableState>
OR
The setOptions should account for undefined values by utilizing something like Object.keys(newState).forEach((key) => { if (key in newState && newState[key] === undefined) delete newOptions.state[key]}) prior to merging it with the current state.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

N/A

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

None

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant