trackBy is broken in version 9.3
See original GitHub issueHello.
I’m using gridster as a dashboard creating tool, so items dynamically change (they can be added or removed on demand). To prevent refreshing item views too many times, I’m using my own trackBy function. Up to 9.2 version everything was working as it should, but now i get the following errors when adding and removing the same item in the same “session” (without reloading page / gridster in between):
vpsc.ts:554 ERROR TypeError: Cannot read property 'gridRenderer' of undefined at GridsterItemComponent.push../node_modules/angular-gridster2/__ivy_ngcc__/fesm5/angular-gridster2.js.GridsterItemComponent.setSize (vpsc.ts:554) at GridsterComponent.push../node_modules/angular-gridster2/__ivy_ngcc__/fesm5/angular-gridster2.js.GridsterComponent.calculateLayout (vpsc.ts:554) at later (vpsc.ts:554) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:3504) at Object.onInvokeTask (vpsc.ts:554) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:3503) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (polyfills.js:3271) at push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask (polyfills.js:3586) at ZoneTask.invoke (polyfills.js:3575) at timer (polyfills.js:6117)
I tried to change my trackBy function to only track by index and the problem remains.
I saw that some additional trackBy functionalities were added in 9.3. Would it be possible, to add option to disable them on demand?
Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)

Top Related StackOverflow Question
Fixed in v10.1.3 Thank you for reporting the issue and reproducing in stackblits @tmtron and @robleka
I think I hit the same problem.
IMHO: adding a timeout is not a solution - not even a workaround, because then it may sometimes work and sometimes fail: e.g. when the CPU is busy or on slow mobile devices, etc.
Here is a Stackblitz example to reproduce the issue.
Notes:
OnPush)Reproduction steps:
ID: 0text to remove the itemID: 0againIt seems that the error occurs in the
setSizefunction as outlined in the comment above.In this case, maybe the
calculateLayoutfunction can first check if this item has already been destroyed?