Skip to content

Commit

Permalink
[bugfix] De-dup <script> tags. #5883 (#5890)
Browse files Browse the repository at this point in the history
* Fix adding duplicate script tags.

* add more empty lines

* rename function
  • Loading branch information
kristw authored and williaster committed Sep 19, 2018
1 parent 8cb734d commit 325e7c0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
9 changes: 9 additions & 0 deletions superset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,21 @@ def get_css_manifest_files(filename):
return entry_files.get('css', [])


def get_unloaded_chunks(files, loaded_chunks):
filtered_files = [f for f in files if f not in loaded_chunks]
for f in filtered_files:
loaded_chunks.add(f)
return filtered_files


parse_manifest_json()


@app.context_processor
def get_manifest():
return dict(
loaded_chunks=set(),
get_unloaded_chunks=get_unloaded_chunks,
js_manifest=get_js_manifest_files,
css_manifest=get_css_manifest_files,
)
Expand Down
6 changes: 3 additions & 3 deletions superset/templates/superset/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
{% block head_css %}
{{super()}}
<link rel="icon" type="image/png" href="/static/assets/images/favicon.png">
{% for entry in css_manifest('theme') %}
{% for entry in get_unloaded_chunks(css_manifest('theme'), loaded_chunks) %}
<link rel="stylesheet" type="text/css" href="{{ entry }}" />
{% endfor %}
{% endblock %}

{% block head_js %}
{{super()}}
{% for entry in js_manifest('theme') %}
{% for entry in get_unloaded_chunks(js_manifest('theme'), loaded_chunks) %}
<script src="{{ entry }}"></script>
{% endfor %}
{% endblock %}

{% block tail_js %}
{{super()}}
{% for entry in js_manifest('common') %}
{% for entry in get_unloaded_chunks(js_manifest('common'), loaded_chunks) %}
<script src="{{ entry }}"></script>
{% endfor %}
{% endblock %}
10 changes: 5 additions & 5 deletions superset/templates/superset/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
<link rel="stylesheet" type="text/css" href="/static/appbuilder/css/flags/flags16.css" />
<link rel="stylesheet" type="text/css" href="/static/appbuilder/css/font-awesome.min.css">

{% for entry in css_manifest('theme') %}
{% for entry in get_unloaded_chunks(css_manifest('theme'), loaded_chunks) %}
<link rel="stylesheet" type="text/css" href="{{ entry }}" />
{% endfor %}

{% if entry %}
{% set entry_files = css_manifest(entry) %}
{% for entry in entry_files %}
{% for entry in get_unloaded_chunks(entry_files, loaded_chunks) %}
<link rel="stylesheet" type="text/css" href="{{ entry }}" />
{% endfor %}
{% endif %}

{% endblock %}

{% for entry in js_manifest('theme') %}
{% for entry in get_unloaded_chunks(js_manifest('theme'), loaded_chunks) %}
<script src="{{ entry }}"></script>
{% endfor %}
{% for entry in js_manifest('common') %}
{% for entry in get_unloaded_chunks(js_manifest('common'), loaded_chunks) %}
<script src="{{ entry }}"></script>
{% endfor %}

Expand Down Expand Up @@ -80,7 +80,7 @@ <h4 class="modal-title"></h4>
{% block tail_js %}
{% if entry %}
{% set entry_files = js_manifest(entry) %}
{% for entry in entry_files %}
{% for entry in get_unloaded_chunks(entry_files, loaded_chunks) %}
<script src="{{ entry }}"></script>
{% endfor %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion superset/templates/superset/partials/_script_tag.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% block tail_js %}
{% for entry in js_manifest(filename) %}
{% for entry in get_unloaded_chunks(js_manifest(filename), loaded_chunks) %}
<script src="{{ entry }}"></script>
{% endfor %}
{% endblock %}

0 comments on commit 325e7c0

Please sign in to comment.