Skip to content

Commit

Permalink
Hotfix: Prevent infinite event loop & remove visual noise
Browse files Browse the repository at this point in the history
krschacht committed May 21, 2024
1 parent 09a9e5c commit cfd8491
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ setInterval(() => {
if (elem) {
elem.classList.remove('bg-red-400')
elem.classList.remove('text-white')
elem.classList.add('text-red-500')
elem.classList.add('text-gray-200')
}
}
}
4 changes: 2 additions & 2 deletions app/javascript/stimulus/textarea_autogrow_controller.js
Original file line number Diff line number Diff line change
@@ -25,14 +25,14 @@ export default class extends Controller {
window.removeEventListener('main-column-changed', this.throttledAutogrow)
}

throttledAutogrow = throttle(() => this.autogrow(), 50)
throttledAutogrow = throttle((event) => { if (!event.detail.fromAutogrow) this.autogrow(event) }, 50)
autogrow() {
const prevHeight = getComputedStyle(this.element).height
this.element.style.height = 'auto'
const newHeight = `${this.element.scrollHeight+2}px` // scrollHeight is two less than computedHeight, this prevents jumps
this.element.style.height = newHeight

if (prevHeight != newHeight) window.dispatchEvent(new CustomEvent('main-column-changed'))
if (prevHeight != newHeight) window.dispatchEvent(new CustomEvent('main-column-changed', { detail: { fromAutogrow: true } })) // TODO: prevents infinite event loop, why is this happening sometimes?
}

submitForm() {

0 comments on commit cfd8491

Please sign in to comment.