From 2b298670938ccf83e1418735cff5b1e0163bb4fc Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Fri, 27 Feb 2026 11:22:29 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20Alpine.js=20defer=20race=20condition=20?= =?UTF-8?q?=E2=80=94=20blank=20pages=20on=20first=20load?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dynamic script creation (document.createElement) ignores the defer attribute per HTML spec — scripts are async regardless. Alpine.js CDN loaded fast and auto-initialized before page scripts had executed, causing ReferenceError for x-data functions (adminStores, dark, isSideMenuOpen, etc.) and blank pages. Fix: Replace dynamic script creation with static - - - - + {% block chartjs_script %}{% endblock %} - + {% block flatpickr_script %}{% endblock %} - + {% block quill_script %}{% endblock %} - + {% block extra_scripts %}{% endblock %} + + + diff --git a/app/templates/merchant/base.html b/app/templates/merchant/base.html index 17555e5c..88734252 100644 --- a/app/templates/merchant/base.html +++ b/app/templates/merchant/base.html @@ -71,26 +71,11 @@ - - - - + {% block extra_scripts %}{% endblock %} + + + diff --git a/app/templates/store/base.html b/app/templates/store/base.html index 76a17699..b671c1df 100644 --- a/app/templates/store/base.html +++ b/app/templates/store/base.html @@ -94,26 +94,11 @@ - - - - + {% block extra_scripts %}{% endblock %} + + + diff --git a/app/templates/storefront/base.html b/app/templates/storefront/base.html index c55e8b40..7e2da460 100644 --- a/app/templates/storefront/base.html +++ b/app/templates/storefront/base.html @@ -380,28 +380,13 @@ {# 6. API Client #} - {# 7. Alpine.js with CDN fallback (deferred - loads last) #} - - - {# 8. Page-specific JavaScript #} + {# 7. Page-specific JavaScript (MUST load before Alpine.js) #} {% block extra_scripts %}{% endblock %} + {# 8. LAST: Alpine.js (must be last defer script — auto-initializes on load) #} + + {# Toast notification container #}