Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] De-dup <script> tags. #5883 #5890

Merged
merged 3 commits into from
Sep 19, 2018
Merged
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
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 %}