Skip to content

Commit 0fa9480

Browse files
authored
fix: load JS synchronously in fragment to prevent race conditions
Previously, when loading JS for virtualdom and drag_and_drop (which depends on virtualdom) from cache, there was a risk that drag_and_drop could load before virtualdom. This would cause virtualdom to be undefined, resulting in the XBlock failing to load. With these changes, the JavaScript code is now inlined in the HTML fragment. This guarantees the correct loading order and prevents such race conditions.
1 parent 6e0e6ac commit 0fa9480

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Drag and Drop XBlock changelog
44
Unreleased
55
---------------------------
66

7+
Version 5.0.3 (2025-06-26)
8+
---------------------------
9+
10+
* Load JS synchronously in the fragment to prevent race conditions.
11+
712
Version 5.0.2 (2025-04-07)
813
---------------------------
914

drag_and_drop_v2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
""" Drag and Drop v2 XBlock """
22
from .drag_and_drop_v2 import DragAndDropBlock
33

4-
__version__ = "5.0.2"
4+
__version__ = "5.0.3"

drag_and_drop_v2/drag_and_drop_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def student_view(self, context):
348348
for css_url in css_urls:
349349
fragment.add_css_url(self.runtime.local_resource_url(self, css_url))
350350
for js_url in js_urls:
351-
fragment.add_javascript_url(self.runtime.local_resource_url(self, js_url))
351+
fragment.add_javascript(loader.load_unicode(js_url))
352352

353353
statici18n_js_url = self._get_statici18n_js_url()
354354
if statici18n_js_url:

0 commit comments

Comments
 (0)