jackmoore / autosize

Autosize is a small, stand-alone script to automatically adjust textarea height to fit text.
http://www.jacklmoore.com/autosize/
MIT License
5.1k stars 702 forks source link

Uncaught TypeError: e.has is not a function with dist/autosize #409

Open Petercopter opened 7 months ago

Petercopter commented 7 months ago

I'm using autosize with a Stimulus controller inside a Ruby on Rails application.

I've been seeing an intermittent error related to autosize for little while, and I finally tracked it down.

At first I thought this was happening because we are loading autosize in a modal that gets injected into the dom from a network request, but today I found a case where the autosize is failing outside of a modal. This could totally be because of Turbo, which does all kinds of magic with navigation and updating the DOM.

So I noticed that autosize/dist/autosize.esm.js has var e=new Map; right at the top.

Nothing worked, so I replaced the import with autosize/src/autosize and it seems that did the trick. So I'm not sure if this is a problem with minification or what's happening.

Here's my Stimulus controller. All it does is autosize when a textarea connects to the DOM:

import { Controller } from '@hotwired/stimulus'
import autosize from 'autosize'

export default class extends Controller {
  static targets = ['textarea']

  textareaTargetConnected(element) {
    autosize(element)
  }
}
application-da509b0f…b331d1bcca.js:78379 Uncaught TypeError: e.has is not a function
    at application-da509b0f…1d1bcca.js:78379:65
    at application-da509b0f…31d1bcca.js:78408:6
    at Array.forEach (<anonymous>)
    at r2 (application-da509b0f…1d1bcca.js:78377:40)
    at extended.textareaTargetConnected (application-da509b0f…31d1bcca.js:78422:5)
    at Context.invokeControllerMethod (application-da509b0f…1d1bcca.js:74825:29)
    at Context.targetConnected (application-da509b0f…1d1bcca.js:74811:10)
    at application-da509b0f…d1bcca.js:74502:103
    at ElementObserver.pause (application-da509b0f…31d1bcca.js:73774:5)
    at AttributeObserver.pause (application-da509b0f…1d1bcca.js:73900:26)
(anonymous) @   application-da509b0f…b331d1bcca.js:78379
(anonymous) @   application-da509b0f…b331d1bcca.js:78408
r2  @   application-da509b0f…b331d1bcca.js:78377
textareaTargetConnected @   application-da509b0f…b331d1bcca.js:78422
invokeControllerMethod  @   application-da509b0f…b331d1bcca.js:74825
targetConnected @   application-da509b0f…b331d1bcca.js:74811
(anonymous) @   application-da509b0f…b331d1bcca.js:74502
pause   @   application-da509b0f…b331d1bcca.js:73774
pause   @   application-da509b0f…b331d1bcca.js:73900
pause   @   application-da509b0f…b331d1bcca.js:74184
connectTarget   @   application-da509b0f…b331d1bcca.js:74502
tokenMatched    @   application-da509b0f…b331d1bcca.js:74492
tokenMatched    @   application-da509b0f…b331d1bcca.js:74216
(anonymous) @   application-da509b0f…b331d1bcca.js:74210
tokensMatched   @   application-da509b0f…b331d1bcca.js:74210
elementMatchedAttribute @   application-da509b0f…b331d1bcca.js:74199
elementMatched  @   application-da509b0f…b331d1bcca.js:73921
addElement  @   application-da509b0f…b331d1bcca.js:73870
refresh @   application-da509b0f…b331d1bcca.js:73796
start   @   application-da509b0f…b331d1bcca.js:73766
start   @   application-da509b0f…b331d1bcca.js:73897
start   @   application-da509b0f…b331d1bcca.js:74181
start   @   application-da509b0f…b331d1bcca.js:74480
connect @   application-da509b0f…b331d1bcca.js:74763
connectContextForScope  @   application-da509b0f…b331d1bcca.js:74930
scopeConnected  @   application-da509b0f…b331d1bcca.js:75302
elementMatchedValue @   application-da509b0f…b331d1bcca.js:75211
tokenMatched    @   application-da509b0f…b331d1bcca.js:74279
tokenMatched    @   application-da509b0f…b331d1bcca.js:74216
(anonymous) @   application-da509b0f…b331d1bcca.js:74210
tokensMatched   @   application-da509b0f…b331d1bcca.js:74210
elementMatchedAttribute @   application-da509b0f…b331d1bcca.js:74199
elementMatched  @   application-da509b0f…b331d1bcca.js:73921
addElement  @   application-da509b0f…b331d1bcca.js:73870
processTree @   application-da509b0f…b331d1bcca.js:73850
processAddedNodes   @   application-da509b0f…b331d1bcca.js:73838
processMutation @   application-da509b0f…b331d1bcca.js:73812
processMutations    @   application-da509b0f…b331d1bcca.js:73803
(anonymous) @   application-da509b0f…b331d1bcca.js:73760
childList (async)       
renderElement   @   application-da509b0f…b331d1bcca.js:71704
assignNewBody   @   application-da509b0f…b331d1bcca.js:71844
(anonymous) @   application-da509b0f…b331d1bcca.js:71770
preservingPermanentElements @   application-da509b0f…b331d1bcca.js:69493
preservingPermanentElements @   application-da509b0f…b331d1bcca.js:69568
replaceBody @   application-da509b0f…b331d1bcca.js:71768
render  @   application-da509b0f…b331d1bcca.js:71730
renderSnapshot  @   application-da509b0f…b331d1bcca.js:69343
render  @   application-da509b0f…b331d1bcca.js:69309
await in render (async)     
renderPage  @   application-da509b0f…b331d1bcca.js:72028
(anonymous) @   application-da509b0f…b331d1bcca.js:70319
Promise.then (async)        
renderChange    @   application-da509b0f…b331d1bcca.js:69943
renderPageSnapshot  @   application-da509b0f…b331d1bcca.js:70318
(anonymous) @   application-da509b0f…b331d1bcca.js:70135
render  @   application-da509b0f…b331d1bcca.js:70314
await in render (async)     
loadResponse    @   application-da509b0f…b331d1bcca.js:70128
visitRequestCompleted   @   application-da509b0f…b331d1bcca.js:70360
recordResponse  @   application-da509b0f…b331d1bcca.js:70115
requestSucceededWithResponse    @   application-da509b0f…b331d1bcca.js:70224
await in requestSucceededWithResponse (async)       
receive @   application-da509b0f…b331d1bcca.js:68795
perform @   application-da509b0f…b331d1bcca.js:68773
await in perform (async)        
issueRequest    @   application-da509b0f…b331d1bcca.js:70096
visitStarted    @   application-da509b0f…b331d1bcca.js:70348
start   @   application-da509b0f…b331d1bcca.js:70052
startVisit  @   application-da509b0f…b331d1bcca.js:70792
visitProposedToLocation @   application-da509b0f…b331d1bcca.js:70340
visitProposedToLocation @   application-da509b0f…b331d1bcca.js:72308
proposeVisit    @   application-da509b0f…b331d1bcca.js:70783
visit   @   application-da509b0f…b331d1bcca.js:72212
followedLinkToLocation  @   application-da509b0f…b331d1bcca.js:72300
clickBubbled    @   application-da509b0f…b331d1bcca.js:69427

Thanks for the great library!