question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

loadAsyncOptions raises TypeError in setup (example included)

See original GitHub issue

I have a setup in which the internal loadAsyncOptions of react-select raises a TypeError, which I think is a bug in react-select.

Setup description

Please have a look at the following setup: https://gist.github.com/dotcs/99041355fbae0d5c757c

I have defined two components. RecipientSelect is a wrapper around Select from react-select and makes use of its async call mechanism. AsyncDemoComponent uses ReciepientSelect together with one input field and a textarea to create some basic setup to write messages.

If I search for Test in the RecipientSelect component, I get the three options Test 1, Test 2 and Test 3 from which I then choose one. The click then triggers a setState call in onSelectChangeHandler.

What I expect

I expect is that the name of the selected entry is written in this.state.recipients of the AsyncDemoComponent.

What I get

The Select-Component raises a TypeError (although this.state.recipients is updated correctly):

Uncaught TypeError: Cannot read property ‘length’ of undefined

loadAsyncOptions: function loadAsyncOptions(input, state, callback) {
    var _this6 = this;
    //if (!input) { return; } // this would fix the problem

    var thisRequestId = this._currentRequestId = requestId++;
    if (this.props.cacheAsyncResults) {
        for (var i = 0; i <= input.length; i++) { 
        // ...

The exact line of the error is this one.

First analysis

I have noted a possible fix in the example above, which I have used as a quick fix for the problem. But I think the actual problem is buried somewhere deeper in the code. I think the call to loadAsyncOptions isn’t necessary at all at this point, which is why input is undefined which raises the error.

Interestingly in the setup (without my fix) every attempt to fill one of the other fields ends in the same error which seems to me that somehow this might be related to a problem with how this is treated in the component. But as far as I can tell I have linked all contexts correctly.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
oliversongcommented, Sep 30, 2015

I fixed this by adding if (!input) { return; } as noted in @dotcs’s comment, but input = input || '' is probably more correct

0reactions
JoseJolljacommented, Oct 30, 2019

Lo arreglé agregando if (!input) { return; }como se indica en el comentario de @dotcs , pero input = input || ''probablemente sea más correcto

Si justamente tenia un error parecido, al iniciar en el componente como cuando tenia 0 productos queria mandarle if(productos.length === 0) return null; para que no se vea la cabecera, entonces cuando eliminaba el ultimo producto seleccionado me manda error, busque por varios dias y con esto logres solucionarlo leyendo el comentario del citado. if(!productos || productos.length === 0) return null;

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSZip.loadAsync(data [, options])
Create .zip files using JavaScript. Provides a simple API to place any content generated by JavaScript into a .zip file for your users....
Read more >
electron-amd-nodeIntegration broken in 0.22.3 #2344 - GitHub
Monaco fails to load when loading with electron-amd-nodeIntegration sample It seems to fail with an error similar to the one reported in ...
Read more >
Session: Loading entities | RavenDB 5.0 Documentation
In this example the load will return DynamicStructure entity because we don't ... object_type=Teacher) # Will raise TypeError because the way we convert...
Read more >
Changes to the WebGL loader and templates introduced in ...
When the Decompression Fallback option is enabled, the build files will have a .unityweb extension, and the loader will include a JavaScript ...
Read more >
How to set class attribute with await in __init__ - Stack Overflow
class Foo(object): @classmethod async def create(cls, settings): self = Foo() ... Usage: async def example(): my_obj = await MyAsyncObject("test", 123).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found