Skip to content

Commit 8d610f1

Browse files
sarg3ntclaude
andcommitted
fix: defer _charLimitInit flag until after DOM parent check
Moving el._charLimitInit = true to after the parentElement guard prevents elements called before DOM insertion from being permanently marked as initialized. Now callers can safely retry initCharLimit() after inserting the element into the DOM. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3412cb6 commit 8d610f1

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

gearbox/static/js/utils/char-limit.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
function initCharLimit(el) {
1313
const limit = parseInt(el.getAttribute('data-charlimit'), 10);
1414
if (!limit || el._charLimitInit) return;
15-
el._charLimitInit = true;
1615

1716
el.maxLength = limit;
1817

@@ -25,6 +24,10 @@ function initCharLimit(el) {
2524
// Guard against elements not yet inserted into the DOM (no parentElement).
2625
const parent = el.parentElement;
2726
if (!parent) return;
27+
28+
// Mark as initialized only after confirming the element is in the DOM,
29+
// so callers can retry after insertion if the element wasn't ready yet.
30+
el._charLimitInit = true;
2831
if (getComputedStyle(parent).position === 'static') {
2932
parent.style.position = 'relative';
3033
}

0 commit comments

Comments
 (0)