From 57ac262f8f97ee05562572dfd30a0dcbcc571bc3 Mon Sep 17 00:00:00 2001 From: Agrendalath Date: Tue, 7 Jan 2025 22:05:54 +0100 Subject: [PATCH] fix(xblock): ensure `TagCountFactory` is bundled in production Remove the `static:webpack` directive and use `add_webpack_js_to_fragment` to properly include TagCountFactory in production. The previous solution did not correctly bundle this factory, causing the `ReferenceError: TagCountFactory is not defined` JS error in the Studio preview. --- cms/djangoapps/contentstore/views/preview.py | 1 + cms/templates/studio_xblock_wrapper.html | 13 +++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index 9c9926a5b25d..2831a6ebb392 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -328,6 +328,7 @@ def _studio_wrap_xblock(xblock, view, frag, context, display_name_only=False): } add_webpack_js_to_fragment(frag, "js/factories/xblock_validation") + add_webpack_js_to_fragment(frag, "js/factories/tag_count") html = render_to_string('studio_xblock_wrapper.html', template_context) frag = wrap_fragment(frag, html) diff --git a/cms/templates/studio_xblock_wrapper.html b/cms/templates/studio_xblock_wrapper.html index 282629456633..b6c627e6dcb3 100644 --- a/cms/templates/studio_xblock_wrapper.html +++ b/cms/templates/studio_xblock_wrapper.html @@ -44,17 +44,14 @@ ${bool(block_is_unit) | n, dump_js_escaped_json}, // block_is_unit will be None or a boolean $('div.xblock-validation-messages[data-locator="${xblock.location | n, js_escaped_string}"]') ); - - -<%static:webpack entry="js/factories/tag_count"> TagCountFactory({ - tags_count: "${tags_count | n, js_escaped_string}", - content_id: "${xblock.location | n, js_escaped_string}", - course_authoring_url: "${course_authoring_url | n, js_escaped_string}", - }, + tags_count: "${tags_count | n, js_escaped_string}", + content_id: "${xblock.location | n, js_escaped_string}", + course_authoring_url: "${course_authoring_url | n, js_escaped_string}", + }, $('li.tag-count[data-locator="${xblock.location | n, js_escaped_string}"]') ); - + % if not is_root: % if is_reorderable: