reactjs / react-autocomplete

WAI-ARIA compliant React autocomplete (combobox) component
MIT License
2.17k stars 532 forks source link

Cannot read property 'ownerDocument' of null #287

Closed ly-tc closed 6 years ago

ly-tc commented 6 years ago

I see that it already fixed in 1.4.2 but now 1.7.2 this error popup again!

ma-pe commented 6 years ago

same here.

JorisPhilipsen commented 6 years ago

I have this problem as well, can someone merge this please?

Slogo commented 6 years ago

I had this issue but was able to work around it.

In my case I had code like this:

renderItem={(item, isHighlighted) => (
  <MyFunctionalComponent key={item.id} item={item} highlighted={isHighlighted}/>
)}

The problem is that the autocomplete will take the rendered items and apply a ref to them. It calls cloneElement with your rendered item as the element to clone and a ref as an additional property to apply. However, you cannot apply a ref to a functional component (see: https://reactjs.org/docs/refs-and-the-dom.html ). What ended up happening is my refs would be set to null and then later you'd get the error when trying to scroll the highlighted menu item into view (a useful feature).

My solution was simple, though difficult to debug:

renderItem={(item, isHighlighted) => (
  <div key={item.id}>
    <MyFunctionalComponent key={item.id} item={item} highlighted={isHighlighted}/>
  </div>
)}

With this fix the rendered Item can properly a ref applied to it and the issue is avoided. In theory I could have also made MyFunctionalComponent into a non-functional component.

It would be great to at least document this limitation if it can't be avoided.

CMTegner commented 6 years ago

This is already documented in props.renderMenu:

Ensure the returned tree includes every entry in items or else the highlight order and keyboard navigation logic will break.

Please open a new ticket with a detailed explanation if you're experiencing problems that aren't covered in the documentation.

avindra commented 5 years ago

@CMTegner is there a plan to support limiting the list size? I think https://github.com/reactjs/react-autocomplete/issues/374 is going for a similar ask.

When lists have hundreds of items, it quickly becomes unusable as the browser struggles to render the list

avindra commented 5 years ago

@CMTegner that should be called out a bit more clearly in the docs... totally glazed over that sentence. Are you open to a PR for a doc fix?