Skip to content
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

VirtualScroll Can't read property length of null #11439

Closed
aggarwalankush opened this issue Apr 29, 2017 · 23 comments
Closed

VirtualScroll Can't read property length of null #11439

aggarwalankush opened this issue Apr 29, 2017 · 23 comments
Assignees
Labels
ionitron: v3 moves the issue to the ionic-v3 repository

Comments

@aggarwalankush
Copy link
Contributor

Ionic version: (check one with "x")
[ ] 1.x
[ ] 2.x
[x] 3.x

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:
I got Null exception at https://github.com/driftyco/ionic/blob/master/src/components/virtual-scroll/virtual-scroll.ts#L601

Expected behavior:
Check for null before calling length function

Steps to reproduce:

Don't know how to reproduce. Got it only a few times.

Related code:

insert any relevant code here

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

Your system information:

Cordova CLI: 6.5.0 
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.6
ios-deploy version: 1.9.1 
ios-sim version: 5.0.13 
OS: macOS Sierra
Node Version: v7.3.0
Xcode version: Xcode 8.3.2 Build version 8E2002

@manucorporat
Copy link
Contributor

manucorporat commented Apr 30, 2017

@aggarwalankush this._nodes should never set to null during runtime, can you provide some source code that reproduces the issue?

@manucorporat manucorporat self-assigned this Apr 30, 2017
@aggarwalankush
Copy link
Contributor Author

Happened few times only. Don't know how to reproduce. Closing this as there are other important issues than this one.

@ADCJustinH
Copy link

This happens for me after upgrading to ionic 3.

Closing this as there are other important issues than this one.

Issues can be prioritized I don't think you should have closed this just because other issues exist...

filteredCourses: ICourseResult[];
ngOnInit() {
        this.cSrv.getNearbyCourses(this.nearbyCount)
            .first().subscribe(courses => {
                this.filteredCourses = courses;
            });
    }

<ion-list [virtualScroll]="filteredCourses" approxItemHeight="85px">

gets the exception every time for me. It happens If I change this around to use the async pipe too. The only fix is to change the first line to:
filteredCourses: ICourseResult[]=[];

which is not a great solution because I don't know how many times this pattern is used in my app and I'll probably miss one or two :/

@aggarwalankush aggarwalankush reopened this May 3, 2017
@manucorporat
Copy link
Contributor

@ADCJustinH I think you have a different issue, this time: this._nodes is null.
Which version are you using? make sure you update to 3.1.1

@ADCJustinH
Copy link

ADCJustinH commented May 3, 2017

@manucorporat Thanks for taking a look. I am indeed using 3.1.1 but the stack is slightly different:

> virtual-scroll.js:535 Uncaught TypeError: Cannot read property 'length' of undefined
>     at VirtualScroll._stepDOMWrite (virtual-scroll.js:535)
>     at virtual-scroll.js:496
>     at dispatch (dom-controller.js:214)
>     at DomController._flush (dom-controller.js:158)
>     at rafCallback (dom-controller.js:147)
Your system information:

 ordova CLI: 6.5.0
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.4
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.10.0
Xcode version: Not installed

and yes, the C in cordova is missing in the console output lol

@aggarwalankush
Copy link
Contributor Author

@manucorporat I am getting the similar error again but now for set property.

TypeError: Cannot set property 'length' of null
      at VirtualScroll.readUpdate (....

@pantonis
Copy link

pantonis commented Jun 3, 2017

same here. I get:

Cannot read property 'length' of null
    at VirtualScroll._stepDOMWrite (virtual-scroll.js:591)
    at virtual-scroll.js:551
    at dispatch (dom-controller.js:214)
    at DomController._flush (dom-controller.js:158)
    at rafCallback (dom-controller.js:147)

after I updated from 2.2.0 to 3.3.0

@pantonis
Copy link

pantonis commented Jun 3, 2017

@ADCJustinH Tried your workaround to change filteredCourses: ICourseResult[]=[]; but doesnt work either.

@pablomaurer
Copy link

pablomaurer commented Jun 22, 2017

Here are my tests using 3.4.2

Oh there is already a huuuge list: #8744

other libs

@viveksinha121
Copy link

Getting this issue too. Tried this:

`public hotelsarray: any[] = [];`
<ion-list [virtualScroll]="hotelsarray" approxItemHeight="50px">
      <div tappable ion-item *virtualItem="let hotel" class="item-inner-hotel" (click)="hotelClicked(hotel)">

@Kevin-Hamilton
Copy link

Kevin-Hamilton commented Aug 21, 2017

@manucorporat I believe the source of this particular bug is a race condition between requestAnimationFrame and ngOnDestroy.

ngOnDestroy nulls out _nodes, _cells, _date, etc. at https://github.com/ionic-team/ionic/blob/master/src/components/virtual-scroll/virtual-scroll.ts#L819 but there are scheduled raf calls in renderVirtual and in _dom.read() / _dom.write() which might execute after ngOnDestroy has free'd those object properties.

@danielcrk
Copy link

Getting this as well. Has anyone found a workaround?

@manucorporat
Copy link
Contributor

fixed! 88b2e83

@Kevin-Hamilton
Copy link

I'm not so sure that commit fixes this bug.

I still see the exact same use of, for example, data.topCell being accessed here: https://github.com/ionic-team/ionic/blob/88b2e8316dad5c504695405fa2199aacbea5b5d6/src/components/virtual-scroll/virtual-scroll.ts#L552 without any prior checks to verify data is not null. And I still see data being set to null here: https://github.com/ionic-team/ionic/blob/88b2e8316dad5c504695405fa2199aacbea5b5d6/src/components/virtual-scroll/virtual-scroll.ts#L820 without cancelling the scheduled requestAnimationFrame that wraps the aforementioned access of data.topCell.

Maybe I'm missing something. @masimplo which of your code changes did you think addressed this bug?

@masimplo
Copy link
Contributor

masimplo commented Oct 7, 2017

@Kevin-Hamilton I will have to check and get back to you as I can't remember from the top of my head. I do remember that this error was triggered in a couple situations, maybe yours is different. Are you starting with a null collection or nulling the collection at some other point?

Maybe it is a good idea to cancelRaf on ngOnDestroy anyway for race conditions. Will see what I can do. Which ionic version are you using so I can create a bundle for you to try?

@pavini
Copy link

pavini commented Oct 20, 2017

I´m getting the same error "VirtualScroll Can't read property length of null"
Ionic 3.13.2

No resolution for this bug?

@masimplo
Copy link
Contributor

@pavini this PR will probably be solving your issue. #13107

@UnderTheMoonspell
Copy link

UnderTheMoonspell commented Nov 14, 2017

I'm getting this error with just a simple test array:

home-container.html
<ion-list [virtualScroll]="testArray" approxItemHeight="'100px'"> <ion-item *virtualItem="let test"> {{article.title}} </ion-item> </ion-list>

home-container.ts

export class HomeContainer { testArray = [{title:'a'}, {title: 'b'}]; constructor() { } }

In this same home-container I am using an input array (received from an Observable from the parent container) and it works normally with *ngFor. With virtualScroll not even that simple testArray works.

@suryabhanbarai
Copy link

suryabhanbarai commented Nov 15, 2017

@UnderTheMoonspell
Assign array like:-
public items: any[] = [];
and in constructor() {
items = [{title:'a'}, {title: 'b'}];
}
will fix the issue.

@UnderTheMoonspell
Copy link

@suryabhanbarai it didn't.

The only element inside ion-list is

<div class="virtual-last"></div>

@therealchrif
Copy link

I NEED HELP PLEASE!

I am loading data from .json file:
provider ts

This is home.ts file
home ts

and here is the home.html file
home html

The error
error

@adamdbradley adamdbradley added the ionitron: v3 moves the issue to the ionic-v3 repository label Nov 1, 2018
@imhoffd imhoffd removed ionitron: v3 moves the issue to the ionic-v3 repository labels Nov 28, 2018
@Ionitron Ionitron added the ionitron: v3 moves the issue to the ionic-v3 repository label Nov 28, 2018
@ionitron-bot
Copy link

ionitron-bot bot commented Nov 28, 2018

This issue has been automatically identified as an Ionic 3 issue. We recently moved Ionic 3 to its own repository. I am moving this issue to the repository for Ionic 3. Please track this issue over there.

If I've made a mistake, and if this issue is still relevant to Ionic 4, please let the Ionic Framework team know!

Thank you for using Ionic!

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 28, 2018

Issue moved to: ionic-team/ionic-v3#279

@ionitron-bot ionitron-bot bot closed this as completed Nov 28, 2018
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ionitron: v3 moves the issue to the ionic-v3 repository
Projects
None yet
Development

No branches or pull requests