Skip to content

bug([material/table]): breaks on subsequent data updates if passed null #18859

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

Closed
sarora2073 opened this issue Mar 18, 2020 · 1 comment · Fixed by #18953
Closed

bug([material/table]): breaks on subsequent data updates if passed null #18859

sarora2073 opened this issue Mar 18, 2020 · 1 comment · Fixed by #18953
Assignees
Labels
area: material/table P4 A relatively minor issue that is not relevant to core functions

Comments

@sarora2073
Copy link

Bug, enhancement request, or proposal:
Bug report on mat-table

CodePen and steps to reproduce the issue:
If you don't pass an array as the data source to mat-table, it of course won't be able to show data, HOWEVER, if you later pass it an array of data, it still won't work i.e. it breaks until you restart the app or otherwise force the component to reload.

Detailed Reproduction Steps:
I'm using the standard pattern of creating a MatTableDataSource:

dataSource = new MatTableDataSource();
then pulling data from the db and assigning it like so:
this.dataSource.data = data;

As you can see in the stack trace image, i get the error "Cannot read property 'slice' of null as expected:

image

The underlying code in table.js line 861 is as follows:

image

What is the expected behavior?
If the data is bad (e.g. null), it should be resilient to display good data when reset.

What is the current behavior?
Table stops working.

What is the use-case or motivation for changing an existing behavior?
Even though I have code on the backend to ensure an empty array is passed, due to the complexity of scenarios, its possible the fail-safe code isn't hit and I get a bad result (null, undefined, etc.). On the front-end due to how mat-table behaves, I now have to sanity check the result as well. Ideally the mat-table itself would be resilient / tolerate occasional bad data.

Which versions of AngularJS, Material, OS, and browsers are affected?
using all latest / greatest as of 3.18.2020, namely:
angular material 9.1.3
angular 9.0.6

Browsers:
latest Chrome
Is there anything else we should know? Stack Traces, Screenshots, etc.
Hopefully the issue / request is apparent from looking at the stack trace. I don't have a stackblitz to offer at the moment but can work on it if warranted.

@sarora2073 sarora2073 added the needs triage This issue needs to be triaged by the team label Mar 18, 2020
@crisbeto crisbeto self-assigned this Mar 30, 2020
@crisbeto crisbeto added has pr P4 A relatively minor issue that is not relevant to core functions and removed needs triage This issue needs to be triaged by the team labels Mar 30, 2020
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 30, 2020
The table data source is set up to expect an array and will throw a cryptic error down the line if the value is anything different. While typings should be enough to enforce this, if the value comes from somewhere in the view it may not get caught. Since the effort for handling it on our end is minimal, these changes add some logic that fall back to an empty array if the value is invalid.

Fixes angular#18859.
crisbeto added a commit to crisbeto/material2 that referenced this issue Apr 4, 2021
The table data source is set up to expect an array and will throw a cryptic error down the line if the value is anything different. While typings should be enough to enforce this, if the value comes from somewhere in the view it may not get caught. Since the effort for handling it on our end is minimal, these changes add some logic that fall back to an empty array if the value is invalid.

Fixes angular#18859.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 3, 2022
The table data source is set up to expect an array and will throw a cryptic error down the line if the value is anything different. While typings should be enough to enforce this, if the value comes from somewhere in the view it may not get caught. Since the effort for handling it on our end is minimal, these changes add some logic that fall back to an empty array if the value is invalid.

Fixes angular#18859.
andrewseguin pushed a commit that referenced this issue Jan 13, 2022
The table data source is set up to expect an array and will throw a cryptic error down the line if the value is anything different. While typings should be enough to enforce this, if the value comes from somewhere in the view it may not get caught. Since the effort for handling it on our end is minimal, these changes add some logic that fall back to an empty array if the value is invalid.

Fixes #18859.
andrewseguin pushed a commit that referenced this issue Jan 13, 2022
The table data source is set up to expect an array and will throw a cryptic error down the line if the value is anything different. While typings should be enough to enforce this, if the value comes from somewhere in the view it may not get caught. Since the effort for handling it on our end is minimal, these changes add some logic that fall back to an empty array if the value is invalid.

Fixes #18859.

(cherry picked from commit e2a0b9e)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 13, 2022
forsti0506 pushed a commit to forsti0506/components that referenced this issue Apr 3, 2022
The table data source is set up to expect an array and will throw a cryptic error down the line if the value is anything different. While typings should be enough to enforce this, if the value comes from somewhere in the view it may not get caught. Since the effort for handling it on our end is minimal, these changes add some logic that fall back to an empty array if the value is invalid.

Fixes angular#18859.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/table P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants