Skip to content

Commit 7672f73

Browse files
authored
Merge pull request #1315 from stlehmann/update-title
Configure document-title during updates
2 parents e255f8b + 087774d commit 7672f73

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

5+
## Unreleased
6+
### Added
7+
- [#1315](https://github.com/plotly/dash/pull/1315) Add `update_title` parameter to set or disable the "Updating...." document title during updates. Closes [#856](https://github.com/plotly/dash/issues/856) and [#732](https://github.com/plotly/dash/issues/732)
8+
59
## [1.13.4] - 2020-06-25
610
### Fixed
711
- [#1310](https://github.com/plotly/dash/pull/1310) Fix a regression since 1.13.0 preventing more than one loading state from being shown at a time.

dash-renderer/src/components/core/DocumentTitle.react.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import PropTypes from 'prop-types';
55
class DocumentTitle extends Component {
66
constructor(props) {
77
super(props);
8+
const {update_title} = props.config;
89
this.state = {
910
initialTitle: document.title,
11+
update_title,
1012
};
1113
}
1214

1315
UNSAFE_componentWillReceiveProps(props) {
14-
if (props.isLoading) {
15-
document.title = 'Updating...';
16+
if (this.state.update_title && props.isLoading) {
17+
document.title = this.state.update_title;
1618
} else {
1719
document.title = this.state.initialTitle;
1820
}
@@ -29,8 +31,10 @@ class DocumentTitle extends Component {
2931

3032
DocumentTitle.propTypes = {
3133
isLoading: PropTypes.bool.isRequired,
34+
config: PropTypes.shape({update_title: PropTypes.string}),
3235
};
3336

3437
export default connect(state => ({
3538
isLoading: state.isLoading,
39+
config: state.config,
3640
}))(DocumentTitle);

dash/dash.py

+3
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def __init__(
252252
prevent_initial_callbacks=False,
253253
show_undo_redo=False,
254254
plugins=None,
255+
update_title="Updating...",
255256
**obsolete
256257
):
257258
_validate.check_obsolete(obsolete)
@@ -299,6 +300,7 @@ def __init__(
299300
),
300301
prevent_initial_callbacks=prevent_initial_callbacks,
301302
show_undo_redo=show_undo_redo,
303+
update_title=update_title,
302304
)
303305
self.config.set_read_only(
304306
[
@@ -506,6 +508,7 @@ def _config(self):
506508
"props_check": self._dev_tools.props_check,
507509
"show_undo_redo": self.config.show_undo_redo,
508510
"suppress_callback_exceptions": self.config.suppress_callback_exceptions,
511+
"update_title": self.config.update_title,
509512
}
510513
if self._dev_tools.hot_reload:
511514
config["hot_reload"] = {

tests/integration/renderer/test_loading_states.py

+45
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from multiprocessing import Lock
22

3+
import pytest
34
import dash
45
from dash.dependencies import Input, Output
6+
from dash.testing.wait import until
57

68
import dash_core_components as dcc
79
import dash_html_components as html
@@ -167,3 +169,46 @@ def find_text(spec):
167169

168170
find_spinners()
169171
find_text({1: 1, 2: 1, 3: 1, 4: 1})
172+
173+
174+
@pytest.mark.parametrize(
175+
"kwargs, expected_update_title",
176+
[
177+
({}, "Updating..."),
178+
({"update_title": None}, "Dash"),
179+
({"update_title": ""}, "Dash"),
180+
({"update_title": "Hello World"}, "Hello World"),
181+
]
182+
)
183+
def test_rdls003_update_title(dash_duo, kwargs, expected_update_title):
184+
app = dash.Dash("Dash", **kwargs)
185+
lock = Lock()
186+
187+
app.layout = html.Div(
188+
children=[
189+
html.H3("Press button see document title updating"),
190+
html.Div(id="output"),
191+
html.Button("Update", id="button", n_clicks=0),
192+
]
193+
)
194+
195+
@app.callback(
196+
Output("output", "children"),
197+
[Input("button", "n_clicks")]
198+
)
199+
def update(n):
200+
with lock:
201+
return n
202+
203+
with lock:
204+
dash_duo.start_server(app)
205+
# check for update-title during startup
206+
until(lambda: dash_duo.driver.title == expected_update_title, timeout=1)
207+
208+
# check for original title after loading
209+
until(lambda: dash_duo.driver.title == "Dash", timeout=1)
210+
211+
with lock:
212+
dash_duo.find_element("#button").click()
213+
# check for update-title while processing callback
214+
until(lambda: dash_duo.driver.title == expected_update_title, timeout=1)

0 commit comments

Comments
 (0)