LeaVerou / stretchy

Form element autosizing, the way it should be
https://stretchy.verou.me/
Other
1.27k stars 87 forks source link

Binding to 'input' and 'change' events too early? #29

Open SirRawlins opened 7 years ago

SirRawlins commented 7 years ago

I've come across a race condition this morning whereby typing in a form field before Stretchy has inited results in the field being resized, even if it doesn't match the filter criteria.

My current hunch on this is that we're binding to the 'input' and 'change' events on the document before the plugin has inited, meaning it can receive resize() calls before the filters are in place.

It looks like listener() is checking an active flag, but the flag is always true, even before init() is run, so doesn't really add any protection.

I'd propose that active() should be false, until init() is complete, or that the binding of the input and change events should happen within or after the init() to prevent this race condition.

Any thoughts?