diff --git a/corehq/apps/hqwebapp/templatetags/hq_shared_tags.py b/corehq/apps/hqwebapp/templatetags/hq_shared_tags.py index 496acc0ee537..70533be19c8f 100644 --- a/corehq/apps/hqwebapp/templatetags/hq_shared_tags.py +++ b/corehq/apps/hqwebapp/templatetags/hq_shared_tags.py @@ -29,6 +29,7 @@ ) from corehq.apps.hqwebapp.models import Alert from corehq.motech.utils import pformat_json +from corehq.util.soft_assert import soft_assert from corehq.util.timezones.conversions import ServerTime from corehq.util.timezones.utils import get_timezone @@ -733,15 +734,20 @@ def __repr__(self): def render(self, context): if self.name not in context and self.value: + # Check that there isn't already an entry point from the other bundler tool + # If there is, don't add this one, because having both set will cause js errors + other_tag = "js_entry" if self.name == "requirejs_main" else "requirejs_main" + other_value = None + for context_dict in context.dicts: + if other_tag in context_dict: + other_value = context_dict.get(other_tag) + msg = f"Discarding {self.value} {self.name} value because {other_value} is using {other_tag}" + soft_assert('jschweers@dimagi.com', notify_admins=False, send_to_ops=False)(False, msg) # set name in block parent context - other_name = "js_entry" if self.name == "requirejs_main" else "requirejs_main" - other_values = [d.get(other_name) for d in context.dicts if other_name in d] - if any(other_values): - raise TemplateSyntaxError(f""" - Cannot use both {self.name} ({self.value}) and {other_name} ({other_values[0]}) - """.strip()) - context.dicts[-2]['use_js_bundler'] = True - context.dicts[-2][self.name] = self.value + if not other_value: + context.dicts[-2]['use_js_bundler'] = True + context.dicts[-2][self.name] = self.value + return '' diff --git a/corehq/apps/hqwebapp/templatetags/tests/test_tag.py b/corehq/apps/hqwebapp/templatetags/tests/test_tag.py index b0291d06ab3a..d53b95f8216e 100644 --- a/corehq/apps/hqwebapp/templatetags/tests/test_tag.py +++ b/corehq/apps/hqwebapp/templatetags/tests/test_tag.py @@ -242,12 +242,10 @@ def test_js_entry_mismatched_delimiter(self): """) def test_requirejs_main_js_entry_conflict(self): - with self.assertRaises(TemplateSyntaxError) as e: + msg = "Discarding module/two js_entry value because module/one is using requirejs_main" + with self.assertRaisesMessage(AssertionError, msg): self.render(""" {% load hq_shared_tags %} {% requirejs_main "module/one" %} {% js_entry "module/two" %} """) - self.assertEqual(""" - Cannot use both js_entry (module/two) and requirejs_main (module/one) - """.strip(), str(e.exception))