Skip to content

Commit 4fe351e

Browse files
authored
Merge pull request #3641 from i-murray/bugfix/loading-all-wildcard-3619
fix: flatten outputs before building loadingOutputs
2 parents 3c4af8e + 830271c commit 4fe351e

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

components/dash-core-components/tests/integration/loading/test_loading_component.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from multiprocessing import Lock
2-
from dash import Dash, Input, Output, dcc, html
2+
from dash import Dash, Input, Output, dcc, html, MATCH, ALL
33
from dash.dependencies import stringify_id
44
from dash.testing import wait
55
import time
@@ -417,7 +417,7 @@ def updateDiv(n_clicks):
417417

418418
# update multiple props of same component, only targeted id/prop triggers spinner
419419
# test that target_components id can be a dict id
420-
def test_ldcp011_loading_component_target_components(dash_dcc):
420+
def test_ldcp010_loading_component_target_components(dash_dcc):
421421
lock = Lock()
422422

423423
app = Dash(__name__)
@@ -461,7 +461,7 @@ def updateDiv2(n_clicks):
461461

462462
dash_dcc.start_server(app)
463463

464-
btn1id = "#" + stringify_id({"type": "button", "index": "one"})
464+
btn1id = "[id='" + stringify_id({"type": "button", "index": "one"}) + "']"
465465

466466
dash_dcc.wait_for_text_to_equal(btn1id, "content 1")
467467

@@ -839,3 +839,50 @@ def update_btn1_children(n_clicks):
839839
assert spinners == []
840840

841841
assert dash_dcc.get_logs() == []
842+
843+
844+
# loading spinner triggers when callback Output uses ALL wildcard
845+
def test_ldcp019_loading_component_pattern_matching(dash_dcc):
846+
lock = Lock()
847+
848+
app = Dash(__name__)
849+
850+
app.layout = html.Div(
851+
[
852+
dcc.Loading(
853+
[
854+
html.Div(
855+
id={"type": "div-1", "index": 1, "name": "test"},
856+
className="div-1",
857+
)
858+
],
859+
className="loading",
860+
)
861+
],
862+
id={"type": "root", "index": 1, "name": "test"},
863+
className="root",
864+
)
865+
866+
@app.callback(
867+
Output({"type": "div-1", "index": ALL, "name": MATCH}, "children"),
868+
Input({"type": "root", "index": ALL, "name": MATCH}, "n_clicks"),
869+
)
870+
def updateDiv(n_clicks):
871+
if n_clicks == [1]:
872+
time.sleep(0.1)
873+
return ["changed"]
874+
return ["content"]
875+
876+
with lock:
877+
dash_dcc.start_server(app)
878+
dash_dcc.wait_for_text_to_equal(".div-1", "content")
879+
880+
dash_dcc.find_element(".root").click()
881+
882+
dash_dcc.find_element(".loading .dash-spinner")
883+
# mounted but hidden, so looks like no text
884+
dash_dcc.wait_for_text_to_equal(".div-1", "")
885+
886+
dash_dcc.wait_for_text_to_equal(".div-1", "changed")
887+
888+
assert dash_dcc.get_logs() == []

dash/dash-renderer/src/actions/callbacks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ export function executeCallback(
791791
}
792792

793793
const __execute = async (): Promise<CallbackResult> => {
794-
const loadingOutputs = outputs.map(out => ({
794+
const loadingOutputs = flatten(outputs).map(out => ({
795795
path: getPath(paths, out.id),
796796
property: out.property?.split('@')[0],
797797
id: stringifyId(out.id)

0 commit comments

Comments
 (0)