twitter/typeahead.js — pull request #994 by kevindew (2014-09-10 21:12:11+00:00)
Title: Events can fire on when Typeahead has been destroyed

This is a tricky to reproduce bug in the same ballpark as https://github.com/twitter/typeahead.js/issues/970 but the code here doesn't resolve that.

We've only experienced it on Android Chrome and iOS Safari (both tested on latest releases), we have a view in a web app with multiple typeahead inputs on and when the view is closed the error fires if we have focus on a field. So what happens in an instance is the input is blurred, potentially changed, typeahead is destroyed and the parent element for it is removed from the DOM.

This is a stack trace:

TypeError: 'null' is not an object (evaluating 'this.$menu.find')
getSuggestions (manifest_footer.js, line 75418)
getDatumForTopSuggestion (manifest_footer.js, line 75500)
updateHint (manifest_footer.js, line 75693)
onDatasetRendered (manifest_footer.js, line 75607)
onDatasetRendered
flush (manifest_footer.js, line 74963)
(anonymous function) (manifest_footer.js, line 74979)

I'm assuming it's related to https://github.com/twitter/typeahead.js/blob/master/src/typeahead/event_emitter.js#L104 which delays the event so it runs after destroy has run.