Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

TypeError Cannot read property 'length' of null in velocity-component.js (v1.4.1) #249

Open
gfx opened this issue Mar 5, 2019 · 5 comments

Comments

@gfx
Copy link

gfx commented Mar 5, 2019

I use this module via https://github.com/storybooks/react-treebeard and saw an error:

TypeError Cannot read property 'length' of null in velocity-component.js

It seems here (line 158):

_clearVelocityCache(target) {
if (target.length) {
_.forEach(target, this._clearVelocityCache);

From our sentry:

screen shot 2019-03-05 at 15 58 34

For now I'll disable animations on react-treebeard to avoid this issue; I've reported it for those who saw the same errors, anyway.

@nomar22
Copy link

nomar22 commented May 20, 2019

I'm on the same situation, actually disable animations doesn't work for me. Any idea?

@fionawhim
Copy link
Collaborator

Hrm. Looks like _clearVelocityCache in VelocityComponent could be updated to have an existence check.

This can come up if the child of your VelocityComponent renders to null it seems.

@nomar22
Copy link

nomar22 commented May 21, 2019

I think my problem is related in fact I'm using this react-tree-beard with react-router , in some way this clearVelocityCache doesn't find the component when redirecting router. To solve this I just unmount this component before execute redirect in my react router.

@RrNn
Copy link

RrNn commented Oct 9, 2019

@nomar22 this might be a late answer, but just make sure the child of VelocityComponent doesn't return null all should be good, like @fionawhim pointed out, took me a while to figure it out too.

@Natas0007
Copy link

I see this issue has been opened for quite a long time. I'm having a similar issue with the same _clearVelocityCache function when using a native html select input (rendered by Material-UI's Select component using the native prop). Interestingly, if I remove all <option> elements under the select, it works without issue. It's trying to run this against all children/decendants and erroring out when it gets to the options.

 _clearVelocityCache(target) { 
   if (target.length) { 
     _.forEach(target, this._clearVelocityCache);

If do something like the below, checking for this, it also works fine.

 _clearVelocityCache(target) { 
   if (target.length) { 
     _.forEach(target, this ? this._clearVelocityCache : console.log('no this here!'));

I'm going to create a PR for this unless someone has a fix for this in the current version (1.4.3)? I could also include the parent this check to resolve the original Cannot read property 'length' of null from the topic of this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants