Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,7 @@ async def menu_links():
and "ds_actor" in request.cookies
and request.actor,
"app_css_hash": self.app_css_hash(),
"static_hash": self.static_hash,
"zip": zip,
"body_scripts": body_scripts,
"format_bytes": format_bytes,
Expand Down
1 change: 1 addition & 0 deletions datasette/handle_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async def inner():
info,
urls=datasette.urls,
app_css_hash=datasette.app_css_hash(),
static_hash=datasette.static_hash,
menu_links=lambda: [],
)
),
Expand Down
4 changes: 2 additions & 2 deletions datasette/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link rel="stylesheet" href="{{ url.url }}"{% if url.get("sri") %} integrity="{{ url.sri }}" crossorigin="anonymous"{% endif %}>
{% endfor %}
<script>window.datasetteVersion = '{{ datasette_version }}';</script>
<script src="{{ urls.static('datasette-manager.js') }}" defer></script>
<script src="{{ urls.static('datasette-manager.js') }}?{{ static_hash('datasette-manager.js') }}" defer></script>
{% for url in extra_js_urls %}
<script {% if url.module %}type="module" {% endif %}src="{{ url.url }}"{% if url.get("sri") %} integrity="{{ url.sri }}" crossorigin="anonymous"{% endif %}></script>
{% endfor %}
Expand Down Expand Up @@ -70,7 +70,7 @@
{% endfor %}

{% if select_templates %}<!-- Templates considered: {{ select_templates|join(", ") }} -->{% endif %}
<script src="{{ urls.static('navigation-search.js') }}" defer></script>
<script src="{{ urls.static('navigation-search.js') }}?{{ static_hash('navigation-search.js') }}" defer></script>
<navigation-search url="/-/jump"></navigation-search>
</body>
</html>
6 changes: 3 additions & 3 deletions datasette/templates/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

{% block extra_head %}
{{- super() -}}
<script src="{{ urls.static('column-chooser.js') }}" defer></script>
<script src="{{ urls.static('table.js') }}" defer></script>
<script src="{{ urls.static('mobile-column-actions.js') }}" defer></script>
<script src="{{ urls.static('column-chooser.js') }}?{{ static_hash('column-chooser.js') }}" defer></script>
<script src="{{ urls.static('table.js') }}?{{ static_hash('table.js') }}" defer></script>
<script src="{{ urls.static('mobile-column-actions.js') }}?{{ static_hash('mobile-column-actions.js') }}" defer></script>
<script>DATASETTE_ALLOW_FACET = {{ datasette_allow_facet }};</script>
<style>
@media only screen and (max-width: 576px) {
Expand Down
24 changes: 23 additions & 1 deletion tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,26 @@ async def test_404(ds_client, path):
)


@pytest.mark.asyncio
@pytest.mark.parametrize(
"filename,template_path",
[
("datasette-manager.js", "/"),
("navigation-search.js", "/"),
("table.js", "/fixtures/facetable"),
("column-chooser.js", "/fixtures/facetable"),
("mobile-column-actions.js", "/fixtures/facetable"),
],
)
async def test_js_content_hash(ds_client, filename, template_path):
response = await ds_client.get(template_path)
assert response.status_code == 200
expected = (
f'<script src="/-/static/{filename}?{ds_client.ds.static_hash(filename)}"'
)
assert expected in response.text


@pytest.mark.asyncio
@pytest.mark.parametrize(
"path,expected_redirect",
Expand Down Expand Up @@ -1038,7 +1058,9 @@ async def test_navigation_menu_links(
navigation_search_script = soup.find(
"script", {"src": re.compile(r"navigation-search\.js")}
)
assert navigation_search_script["src"] == "/-/static/navigation-search.js"
assert navigation_search_script["src"] == (
f"/-/static/navigation-search.js?{ds_client.ds.static_hash('navigation-search.js')}"
)
assert details.find("li").find("button") == search_button
if not actor_id:
# The app menu is always visible, but anonymous users do not see logout
Expand Down