Skip to content

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

Closed

Description

@sarora2073

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.

Activity

  1. added
    needs triage
    on Mar 18, 2020
  2. self-assigned this
    on Mar 30, 2020
  3. added
    P4
    and removed
    needs triage
    on Mar 30, 2020
  4. added a commit that references this issue on Mar 30, 2020
    36dc1cf
  5. added a commit that references this issue on Apr 4, 2021
    b366222
  6. added a commit that references this issue on Jan 3, 2022
    6f7f9f4
  7. added 2 commits that reference this issue on Jan 13, 2022
    e2a0b9e
    9752b1d
  8. angular-automatic-lock-bot commented on Feb 13, 2022

    @angular-automatic-lock-bot

    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.

  9. locked and limited conversation to collaborators on Feb 13, 2022
  10. added a commit that references this issue on Apr 3, 2022
    b7aa207
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P4area: material/table

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions