Skip to main content

max / makenotwork

Fix bundle JS init: use setTimeout for DOM readiness after HTMX swap Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author: Max J. <87768334+MaxJMath@users.noreply.github.com> · 2026-05-10 19:01 UTC
Commit: 711a5b77428e7d836fee25aceaa2112e8b7c1753
Parent: fb959f3
1 file changed, +6 insertions, -5 deletions
@@ -11,7 +11,7 @@
11 11 var itemId = container.dataset.itemId;
12 12 if (!itemId) return;
13 13
14 - initBundles(itemId);
14 + try { initBundles(itemId); } catch(e) { console.error('initBundles failed:', e); }
15 15 initSections(itemId);
16 16 initTagSearch(itemId);
17 17 initAiTierToggle();
@@ -51,7 +51,8 @@
51 51
52 52 // "Add Item" row button
53 53 var addRowBtn = document.getElementById('bundle-add-row-btn');
54 - if (addRowBtn) {
54 + if (addRowBtn && !addRowBtn.dataset.bound) {
55 + addRowBtn.dataset.bound = '1';
55 56 addRowBtn.addEventListener('click', function() {
56 57 var container = document.getElementById('bundle-new-rows');
57 58 var row = document.createElement('div');
@@ -360,10 +361,10 @@
360 361 // Run on initial load
361 362 init();
362 363
363 - // Re-run when HTMX swaps in the details tab
364 + // Re-run when HTMX swaps in tab content
364 365 document.body.addEventListener('htmx:afterSwap', function(e) {
365 - if (e.detail.target.id === 'tab-content') {
366 - init();
366 + if (e.detail.target && e.detail.target.id === 'tab-content') {
367 + setTimeout(init, 0);
367 368 }
368 369 });
369 370 })();