Skip to content

Commit 0ca1a20

Browse files
authored
feat: use outerHTML instead innerHTML, remove script after execute (#2)
* feat: changed innerHTML to outerHTML & auto-remove loader script * feat(tests): added matrix python x django
1 parent 7183009 commit 0ca1a20

File tree

7 files changed

+80
-44
lines changed

7 files changed

+80
-44
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v4
1313

14-
- name: Set up Python 3.11
15-
uses: actions/setup-python@v4
14+
- name: Set up Python 3.12
15+
uses: actions/setup-python@v5
1616
with:
17-
python-version: "3.11"
17+
python-version: 3.12
1818

1919
- name: Build source and wheel distributions
2020
run: |

.github/workflows/tests.yml

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,85 @@ on:
55
branches: [main]
66
paths:
77
- '**.py'
8+
- 'pyproject.toml'
89
pull_request:
910
branches: [main]
1011
paths:
1112
- '**.py'
13+
- 'pyproject.toml'
1214

1315
jobs:
1416
tests:
1517
runs-on: ubuntu-latest
1618
strategy:
19+
fail-fast: false
1720
matrix:
18-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
19-
21+
# https://docs.djangoproject.com/en/5.1/faq/install/#what-python-version-can-i-use-with-django
22+
include:
23+
# 3.9 -- 3.2, 4.0, 4.1, 4.2
24+
- python-version: "3.9"
25+
django-version: "3.2"
26+
- python-version: "3.9"
27+
django-version: "4.0"
28+
- python-version: "3.9"
29+
django-version: "4.1"
30+
- python-version: "3.9"
31+
django-version: "4.2"
32+
# 3.10 -- 3.2, 4.0, 4.1, 4.2, 5.0, 5.1
33+
- python-version: "3.10"
34+
django-version: "3.2"
35+
- python-version: "3.10"
36+
django-version: "4.0"
37+
- python-version: "3.10"
38+
django-version: "4.1"
39+
- python-version: "3.10"
40+
django-version: "4.2"
41+
- python-version: "3.10"
42+
django-version: "5.0"
43+
- python-version: "3.10"
44+
django-version: "5.1"
45+
# 3.11 -- 4.1, 4.2, 5.0, 5.1
46+
- python-version: "3.11"
47+
django-version: "4.1"
48+
- python-version: "3.11"
49+
django-version: "4.2"
50+
- python-version: "3.11"
51+
django-version: "5.0"
52+
- python-version: "3.11"
53+
django-version: "5.1"
54+
# 3.12 -- 4.2, 5.0, 5.1
55+
- python-version: "3.12"
56+
django-version: "4.2"
57+
- python-version: "3.12"
58+
django-version: "5.0"
59+
- python-version: "3.12"
60+
django-version: "5.1"
61+
# 3.13 -- 5.1
62+
- python-version: "3.13"
63+
django-version: "5.1"
2064
steps:
2165
- uses: actions/checkout@v4
2266

2367
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v4
68+
uses: actions/setup-python@v5
2569
with:
2670
python-version: ${{ matrix.python-version }}
2771

72+
- uses: pre-commit/[email protected]
73+
if: matrix.python-version == 3.11
74+
2875
- name: Install dependencies
2976
run: |
3077
pip install pytest pytest-django pytest-cov
31-
pip install -r requirements.txt
78+
pip install "Django~=${{ matrix.django-version }}"
3279
3380
- name: Run tests
3481
run: |
3582
pytest --cov
3683
3784
- name: Upload coverage reports to Codecov
38-
uses: codecov/codecov-action@v3
85+
# optimal value
86+
if: matrix.python-version == 3.10 && matrix.django-version == 5.0
87+
uses: codecov/codecov-action@v5
3988
env:
4089
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
41-
42-
pre-commit:
43-
runs-on: ubuntu-latest
44-
steps:
45-
- uses: actions/checkout@v4
46-
- name: Set up Python
47-
uses: actions/setup-python@v4
48-
with:
49-
python-version: 3.11
50-
- uses: pre-commit/[email protected]

README.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ TEMPLATES = [
3232
"APP_DIRS": True,
3333
"OPTIONS": {
3434
"context_processors": [
35-
"django.template.context_processors.debug",
36-
"django.template.context_processors.request",
37-
"django.contrib.auth.context_processors.auth",
38-
"django.contrib.messages.context_processors.messages",
35+
# ... list of default processors
3936
],
40-
"builtins": ["suspense.templatetags.suspense"],
37+
"builtins": ["suspense.templatetags.suspense"], # <--
4138
},
4239
},
4340
]
@@ -63,25 +60,25 @@ def view(request):
6360

6461
### 3. Use `suspense` in your template:
6562
Let's now add the output of the received data to the template. At this point, we still haven't made a database query, so we can easily and quickly show the template right away.
66-
```html
63+
```jinja
6764
{% load suspense %}
6865
69-
<div class="list">
66+
<ul>
7067
{% suspense %}
7168
{% fallback %}
72-
<div class="skeleton">Loading ... </div>
69+
<li class="skeleton">Loading ... </li>
7370
{% endfallback %}
7471
75-
<ul>
76-
{% for data in obj %}
77-
<li>{{ data }}</li>
78-
{% endfor %}
79-
</ul>
72+
{% for data in obj %}
73+
<li>{{ data }}</li>
74+
{% endfor %}
8075
{% endsuspense %}
81-
</div>
76+
</ul>
8277
```
8378
Once obj is ready for use, we will show it. But until it is ready, fallback works. While we are waiting for the data to be displayed, a request is made on the client side.
8479

80+
> Suspense does not add additional DOM elements after rendering the final result. That's why syntactically the code above will be valid.
81+
8582
### 4. Hooray! Everything is ready to use it.
8683

8784

@@ -99,15 +96,15 @@ See [webkit issue #252413](https://bugs.webkit.org/show_bug.cgi?id=252413)
9996

10097
If you are experiencing this issue, you can use the additional `{% webkit_extra_invisible_bytes %}` template tag to add a few extra invisible bytes in Safari.
10198

102-
```html
99+
```jinja
103100
{% load suspense %}
104101
105102
{% webkit_extra_invisible_bytes %}
106103
```
107104

108105
By default the `webkit_extra_invisible_bytes` adds 200 bytes but you can specify a different amount:
109106

110-
```html
107+
```jinja
111108
{% webkit_extra_invisible_bytes 300 %}
112109
```
113110

@@ -119,8 +116,9 @@ You can override the `suspense/replacer.html` template and add the `nonce` attri
119116

120117
With [django-csp](https://django-csp.readthedocs.io/en/latest/nonce.html#middleware):
121118

122-
```html
119+
```jinja
123120
{% extends "suspense/replacer.html" %}
121+
124122
{% block script_attributes %}nonce="{{request.csp_nonce}}"{% endblock %}
125123
```
126124

example/requirements.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
asgiref==3.7.2
2-
Django==4.2.7
3-
sqlparse==0.4.4
4-
5-
#django-suspense
1+
Django>=3.2
2+
# django-suspense

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ classifiers = [
1919
"Framework :: Django :: 3.2",
2020
"Framework :: Django :: 4.1",
2121
"Framework :: Django :: 4.2",
22+
"Framework :: Django :: 5.0",
23+
"Framework :: Django :: 5.1",
2224
"Intended Audience :: Developers",
2325
"License :: OSI Approved :: MIT License",
2426
"Programming Language :: Python",

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
asgiref==3.7.2
2-
Django==4.2.6
3-
sqlparse==0.4.4
1+
# Supported 3.2, 4.0, 4.1, 4.2, 5.0, 5.1
2+
Django>=3.2
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<script {% block script_attributes %}{% endblock %}>
2-
document.getElementById("suspense-loader-{{uid}}").innerHTML = `{{escaped_string | safe}}`;
2+
document.getElementById("suspense-loader-{{uid}}").outerHTML = `{{escaped_string | safe}}`;
3+
document.currentScript.remove()
34
</script>

0 commit comments

Comments
 (0)