Skip to content

Commit 4d93652

Browse files
authored
Merge pull request #335 from plotly/css-include-order
CSS/JS external resources loaded before the assets
2 parents 5fc998a + 0e46327 commit 4d93652

File tree

8 files changed

+70
-19
lines changed

8 files changed

+70
-19
lines changed

.circleci/config.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ jobs:
1010

1111
steps:
1212
- checkout
13+
14+
- run:
15+
name: Write deps cache key
16+
command: cat "$REQUIREMENTS_FILE" > reqs.txt
17+
1318
- restore_cache:
14-
key: deps1-{{ .Branch }}-{{ checksum "dev-requirements.txt" }}
19+
key: deps1-{{ .Branch }}-{{ checksum "reqs.txt" }}
1520

1621
- run:
1722
name: Install dependencies
@@ -22,7 +27,7 @@ jobs:
2227
pip install -r $REQUIREMENTS_FILE
2328
2429
- save_cache:
25-
key: deps1-{{ .Branch }}-{{ checksum "dev-requirements.txt" }}
30+
key: deps1-{{ .Branch }}-{{ checksum "reqs.txt" }}
2631
paths:
2732
- "venv"
2833

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.25.1 - 2018-08-20
2+
## Fixed
3+
- Ensure CSS/JS external resources are loaded before the assets. [#335](https://github.com/plotly/dash/pull/335)
4+
15
## 0.25.0 - 2018-08-14
26
## Added
37
- Take configs values from init or environ variables (Prefixed with `DASH_`). [#322](https://github.com/plotly/dash/pull/322)

dash/dash.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,8 @@ def _relative_url_path(relative_package_path='', namespace=''):
331331
return srcs
332332

333333
def _generate_css_dist_html(self):
334-
links = self._collect_and_register_resources(
335-
self.css.get_all_css()
336-
) + self._external_stylesheets
334+
links = self._external_stylesheets + \
335+
self._collect_and_register_resources(self.css.get_all_css())
337336

338337
return '\n'.join([
339338
_format_tag('link', link, opened=True)
@@ -353,13 +352,11 @@ def _generate_scripts_html(self):
353352
srcs = self._collect_and_register_resources(
354353
self.scripts._resources._filter_resources(
355354
dash_renderer._js_dist_dependencies
356-
) +
357-
self.scripts.get_all_scripts() +
358-
self.scripts._resources._filter_resources(
359-
dash_renderer._js_dist
360-
)
361-
)
362-
srcs = srcs[:-1] + self._external_scripts + [srcs[-1]]
355+
)) + self._external_scripts + self._collect_and_register_resources(
356+
self.scripts.get_all_scripts() +
357+
self.scripts._resources._filter_resources(
358+
dash_renderer._js_dist
359+
))
363360

364361
return '\n'.join([
365362
_format_tag('script', src)

dash/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.25.0'
1+
__version__ = '0.25.1'

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dash_core_components>=0.4.0
1+
dash_core_components>=0.27.1
22
dash_html_components>=0.12.0rc3
33
dash_flow_example==0.0.3
44
dash-dangerously-set-inner-html

tests/assets/load_first.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
window.tested = ['load_first'];
1+
window.tested = ['load_first'];
2+
var ramdaTest = document.getElementById('ramda-test');
3+
if (ramdaTest) {
4+
ramdaTest.innerHTML = R.join(' ', R.concat(['hello'], ['world']).map(function(x) {
5+
return _.capitalize(x);
6+
}));
7+
}

tests/assets/reset.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
body {margin: 0;}
2+
button {height: 18px}

tests/test_integration.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,17 @@ def test_external_files_init(self):
452452
'https://www.google-analytics.com/analytics.js',
453453
{'src': 'https://cdn.polyfill.io/v2/polyfill.min.js'},
454454
{
455-
'src': 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.core.js',
456-
'integrity': 'sha256-Qqd/EfdABZUcAxjOkMi8eGEivtdTkh3b65xCZL4qAQA=',
455+
'src': 'https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js',
456+
'integrity': 'sha256-YN22NHB7zs5+LjcHWgk3zL0s+CRnzCQzDOFnndmUamY=',
457+
'crossorigin': 'anonymous'
458+
},
459+
{
460+
'src': 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.min.js',
461+
'integrity': 'sha256-VKITM616rVzV+MI3kZMNUDoY5uTsuSl1ZvEeZhNoJVk=',
457462
'crossorigin': 'anonymous'
458463
}
459464
]
465+
460466
css_files = [
461467
'https://codepen.io/chriddyp/pen/bWLwgP.css',
462468
{
@@ -467,8 +473,30 @@ def test_external_files_init(self):
467473
}
468474
]
469475

470-
app = dash.Dash(
471-
external_scripts=js_files, external_stylesheets=css_files)
476+
app = dash.Dash(__name__,
477+
external_scripts=js_files,
478+
external_stylesheets=css_files)
479+
480+
app.index_string = '''
481+
<!DOCTYPE html>
482+
<html>
483+
<head>
484+
{%metas%}
485+
<title>{%title%}</title>
486+
{%css%}
487+
</head>
488+
<body>
489+
<div id="tested"></div>
490+
<div id="ramda-test"></div>
491+
<button type="button" id="btn">Btn</button>
492+
{%app_entry%}
493+
<footer>
494+
{%config%}
495+
{%scripts%}
496+
</footer>
497+
</body>
498+
</html>
499+
'''
472500

473501
app.layout = html.Div()
474502

@@ -482,3 +510,13 @@ def test_external_files_init(self):
482510
(("//script[@src='{}']", x) for x in js_urls),
483511
(("//link[@href='{}']", x) for x in css_urls)):
484512
self.driver.find_element_by_xpath(fmt.format(url))
513+
514+
# Ensure the button style was overloaded by reset (set to 38px in codepen)
515+
btn = self.driver.find_element_by_id('btn')
516+
btn_height = btn.value_of_css_property('height')
517+
518+
self.assertEqual('18px', btn_height)
519+
520+
# ensure ramda was loaded before the assets so they can use it.
521+
lo_test = self.driver.find_element_by_id('ramda-test')
522+
self.assertEqual('Hello World', lo_test.text)

0 commit comments

Comments
 (0)