Skip to content

Commit e190cc9

Browse files
committed
fix logic
1 parent 66bb5d3 commit e190cc9

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

Diff for: dash-renderer/src/components/core/DocumentTitle.react.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ class DocumentTitle extends Component {
77
super(props);
88
const {update_title} = props.config;
99
this.state = {
10+
title: document.title,
1011
update_title,
1112
};
1213
}
1314

1415
UNSAFE_componentWillReceiveProps(props) {
15-
if (this.state.update_title && props.isLoading) {
16-
document.title = this.state.update_title;
16+
if (props.isLoading) {
17+
this.setState({title: document.title});
18+
if (this.state.update_title) {
19+
document.title = this.state.update_title;
20+
}
21+
} else {
22+
document.title = this.state.title;
1723
}
1824
}
1925

Diff for: tests/integration/renderer/test_loading_states.py

+41-12
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,21 @@ def find_text(spec):
172172

173173

174174
@pytest.mark.parametrize(
175-
"kwargs, expected_update_title",
175+
"kwargs, expected_update_title, clientside_title",
176176
[
177-
({}, "Updating..."),
178-
({"update_title": None}, "Dash"),
179-
({"update_title": ""}, "Dash"),
180-
({"update_title": "Hello World"}, "Hello World"),
181-
]
177+
({}, "Updating...", False),
178+
({"update_title": None}, "Dash", False), # fail
179+
({"update_title": ""}, "Dash", False), # fail
180+
({"update_title": "Hello World"}, "Hello World", False),
181+
({}, "Updating...", True), # fail
182+
({"update_title": None}, "Dash", True), # fail
183+
({"update_title": ""}, "Dash", True), # fail
184+
({"update_title": "Hello World"}, "Hello World", True), # fail
185+
],
182186
)
183-
def test_rdls003_update_title(dash_duo, kwargs, expected_update_title):
187+
def test_rdls003_update_title(
188+
dash_duo, kwargs, expected_update_title, clientside_title
189+
):
184190
app = dash.Dash("Dash", **kwargs)
185191
lock = Lock()
186192

@@ -189,13 +195,23 @@ def test_rdls003_update_title(dash_duo, kwargs, expected_update_title):
189195
html.H3("Press button see document title updating"),
190196
html.Div(id="output"),
191197
html.Button("Update", id="button", n_clicks=0),
198+
html.Button("Update Page", id="page", n_clicks=0),
199+
html.Div(id="dummy"),
192200
]
193201
)
202+
if clientside_title:
203+
app.clientside_callback(
204+
"""
205+
function(n_clicks) {
206+
document.title = 'Page ' + n_clicks;
207+
return n_clicks;
208+
}
209+
""",
210+
Output("dummy", "children"),
211+
[Input("page", "n_clicks")],
212+
)
194213

195-
@app.callback(
196-
Output("output", "children"),
197-
[Input("button", "n_clicks")]
198-
)
214+
@app.callback(Output("output", "children"), [Input("button", "n_clicks")])
199215
def update(n):
200216
with lock:
201217
return n
@@ -206,9 +222,22 @@ def update(n):
206222
until(lambda: dash_duo.driver.title == expected_update_title, timeout=1)
207223

208224
# check for original title after loading
209-
until(lambda: dash_duo.driver.title == "Dash", timeout=1)
225+
until(lambda: dash_duo.driver.title == "Page 0" if clientside_title else "Dash", timeout=1)
210226

211227
with lock:
212228
dash_duo.find_element("#button").click()
213229
# check for update-title while processing callback
214230
until(lambda: dash_duo.driver.title == expected_update_title, timeout=1)
231+
232+
dash_duo.find_element("#page").click()
233+
dash_duo.wait_for_text_to_equal("dummy", "1")
234+
if clientside_title:
235+
until(lambda: dash_duo.driver.title == "Page 1", timeout=1)
236+
else:
237+
until(lambda: dash_duo.driver.title == "Dash", timeout=1)
238+
239+
dash_duo.find_element("#button").click()
240+
if clientside_title:
241+
until(lambda: dash_duo.driver.title == "Page 2", timeout=1)
242+
else:
243+
until(lambda: dash_duo.driver.title == "Dash", timeout=1)

0 commit comments

Comments
 (0)