angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.33k stars 6.73k forks source link

help(CdkTable): Cdk Table is not instantiated with production build #20302

Open bvkimball opened 4 years ago

bvkimball commented 4 years ago

When running ng serve everything works

Just upgraded to angular 10 and got everything working, finally got to running a prod build and not of my DataTables are loading. Using ng build --prod && npx angular-http-server --path ./dist -p 3001. It seems like the CdkTable is not instantiated because the DataSource.connect function is never called.

I have a component library that has also been upgraded to angular 10 and works, the component library has a DataTable component that use <cdk-table> like so: (this has been working with prior versions)

 <cdk-table
          [dataSource]="dataSource"
          [trackBy]="trackByFn"
          [class.expandable]="expandable"
          [class.empty]="dataSource?.currentlyEmpty && state.userFiltered"
          [hidden]="dataSource?.totallyEmpty && !state.userFiltered"
          #table
        >

I added @ViewChild('table') tableRef: CdkTable<T>; when I console.log this i get: image

Environment

jelbourn commented 4 years ago

@bvkimball can you share a reproduction?

bvkimball commented 4 years ago

ng10-bug-repo.zip

Tried to make a stack blitz but the project uses a github repo as a dependency. This project will work with npm start but NOT with npm run build && npx angular-http-server --path ./dist/ng10-bug-repo -p 4200

The implementation of our novo-data-table that uses cdk-table is here: https://github.com/bullhorn/novo-elements/blob/master/projects/novo-elements/src/elements/data-table/data-table.component.ts

Our implementation is a little weird we have our own template directive that then dynamically creates all the columnDefs.

bvkimball commented 4 years ago

@jelbourn I know this is probably an Ivy renderer issue or something we are doing that is not compatible with Ivy but I can't even figure out how to debug this in the production build. I have tried everything short of rewriting the component, which is my next step. I just don't know what my component could be doing that could cause the CdkTable not not initialize any ideas on where to look would be helpful

jelbourn commented 4 years ago

I'll try to take a look during my weekly issue triage

bvkimball commented 4 years ago

I noticed something something strange with the *ngIf in this component as well. Believe this issue with treeshaking was removing CommonModule and CdkTableModule for some reason. sideEffects:true fixed this issue for me. Not sure if it is caused by recursive components, i do get a few of those warning but not for code related to my table components.

https://stackoverflow.com/questions/62617305/tree-shaking-for-angular-10-shook-out-asyncpipe-when-using-sideeffects-false

jelbourn commented 3 years ago

Potentially a duplicate of https://github.com/angular/angular/issues/38362