Skip to content

Commit 81891a3

Browse files
committed
Check Alpine.js is loaded when morph is called to deal with it being loaded with defer.
1 parent 90e408f commit 81891a3

File tree

9 files changed

+265
-254
lines changed

9 files changed

+265
-254
lines changed

django_unicorn/static/unicorn/js/morphers/alpine.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
export class AlpineMorpher {
22
constructor(options) {
3-
// Check if window has Alpine and Alpine Morph
4-
if (!window.Alpine || !window.Alpine.morph) {
5-
throw Error(`
6-
Alpine morpher requires Alpine to be loaded. Add Alpine and Alpine Morph to your page.
7-
See https://www.django-unicorn.com/docs/custom-morphers/#alpine for more information.
8-
`);
9-
}
10-
113
this.options = options;
124
}
135

146
morph(dom, htmlElement) {
157
if (htmlElement) {
8+
// Check if window has Alpine and Alpine Morph
9+
if (!window.Alpine || !window.Alpine.morph) {
10+
throw Error(`
11+
Alpine.js and the Alpine morph plugin can not be found.
12+
See https://www.django-unicorn.com/docs/custom-morphers/#alpine for more information.
13+
`);
14+
}
15+
1616
return window.Alpine.morph(dom, htmlElement, this.getOptions());
1717
}
1818
}

django_unicorn/static/unicorn/js/unicorn.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

django_unicorn/templates/unicorn/scripts.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
{% if MINIFIED %}
66
<script src="{% static 'unicorn/js/unicorn.min.js' %}"></script>
7+
{% comment %} <script src="../static/unicorn/js/unicorn.min.js"></script> {% endcomment %}
8+
79
<script>
810
const url = "{% url 'django_unicorn:message' %}";
911
const morpherSettings = JSON.parse(document.getElementById("unicorn:settings:morpher").textContent);

docs/source/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.56.1
4+
5+
- Handle Alpine.js being loaded with defer.
6+
37
## 0.56.0
48

59
- Add support for using both Alpine.js and `Unicorn` together in a component ([#597](https://github.com/adamghill/django-unicorn/pull/597) by [imankulov](https://github.com/imankulov)).

example/www/templates/www/base.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
<script defer src="https://unpkg.com/@alpinejs/[email protected]/dist/cdn.min.js"></script>
2727
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
28+
2829
{% unicorn_scripts %}
2930
</head>
3031

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.56.0",
2+
"version": "0.56.1",
33
"name": "django-unicorn",
44
"scripts": {
55
"build": "npx rollup -c",

poetry.lock

Lines changed: 242 additions & 239 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-unicorn"
3-
version = "0.56.0"
3+
version = "0.56.1"
44
description = "A magical full-stack framework for Django."
55
authors = ["Adam Hill <[email protected]>"]
66
license = "MIT"
@@ -144,6 +144,7 @@ tp = { cmd = "nox -r", help = "Run the entire Python test suite with nox" }
144144
tj = { cmd = "npm run-script test", help = "Run the JavaScript unit tests" }
145145
ta = ["tp", "tj"]
146146
jb = { cmd = "npm run build", help = "Build the JavaScript library" }
147+
ji = { cmd = "npm install", help = "Install JS" }
147148
t = { cmd = "pytest -m 'not slow'", help = "Run Python unit tests" }
148149
tb = { cmd = "pytest tests/benchmarks/ --benchmark-autosave --benchmark-only", help = "Run Python unit tests with benchmarks" }
149150
tbc = { cmd = "pytest tests/benchmarks/ --benchmark-only --benchmark-compare", help = "Run Python unit tests with compared benchmarks" }
@@ -155,7 +156,7 @@ rf = { cmd = "ruff .", help = "Run ruff" }
155156
tm = ["b", "rf", "tc", "my"]
156157
sa = { cmd = "sphinx-autobuild -W docs/source docs/build", help = "Sphinx autobuild" }
157158
sb = { cmd = "sphinx-build -W docs/source docs/build", help = "Build documentation" }
158-
build = ["b", "rf", "tc", "tj", "jb", "sb"]
159+
build = ["b", "rf", "tc", "ji", "tj", "jb", "sb"]
159160
publish = { shell = "poetry publish --build -r test && poetry publish" }
160161

161162
[build-system]

0 commit comments

Comments
 (0)