You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
The text was updated successfully, but these errors were encountered:
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 toundefined
. This is not accounted for when merging in newoptions.state
. When a state property is passed in asundefined
, it will still overwrite whatever value was there before.The type of
table.options.state
and return oftable.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 setOptionsAs 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 #4697Some 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:grouping
can be undefined when accessinggrouping.length
in getGroupedRowModel.pagination
in getPaginationRowModelEither:
The type for
table.options.state
and return oftable.getState()
should be changed toPartial<TableState>
OR
The setOptions should account for
undefined
values by utilizing something likeObject.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
The text was updated successfully, but these errors were encountered: