You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: django_unicorn/components.py
+13-4Lines changed: 13 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -172,17 +172,25 @@ def render(self):
172
172
root_element["unicorn:checksum"] =checksum
173
173
174
174
ifself.init_js:
175
-
script_tag=soup.new_tag("script")
176
175
init= {
177
176
"id": self.component.component_id,
178
177
"name": nested_component_name,
179
178
"key": self.component.component_key,
180
179
"data": orjson.loads(frontend_context_variables),
181
180
}
182
181
init=orjson.dumps(init).decode("utf-8")
183
-
script_tag["type"] ="module"
184
-
script_tag.string=f"if (typeof Unicorn === 'undefined') {{ console.error('Unicorn is missing. Do you need {{% load unicorn %}} or {{% unicorn-scripts %}}?') }} else {{ Unicorn.componentInit({init}); }}"
185
-
root_element.insert_after(script_tag)
182
+
init_script=f"Unicorn.componentInit({init});"
183
+
184
+
ifself.component.parent:
185
+
self.component._init_script=init_script
186
+
else:
187
+
forchildinself.component.children:
188
+
init_script=f"{init_script}{child._init_script}"
189
+
190
+
script_tag=soup.new_tag("script")
191
+
script_tag["type"] ="module"
192
+
script_tag.string=f"if (typeof Unicorn === 'undefined') {{ console.error('Unicorn is missing. Do you need {{% load unicorn %}} or {{% unicorn-scripts %}}?') }} else {{ {init_script} }}"
0 commit comments