Skip to content

Commit 90fa4c3

Browse files
committed
Fix #3366
1 parent 6afd6f9 commit 90fa4c3

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,16 @@ function refErr(errors: any, paths: any) {
226226
const getVals = (input: any) =>
227227
Array.isArray(input) ? pluck('value', input) : input.value;
228228

229-
const zipIfArray = (a: any, b: any) =>
230-
Array.isArray(a) ? zip(a, b) : [[a, b]];
229+
const zipIfArray = (a: any, b: any) => {
230+
if (Array.isArray(a)) {
231+
// For client-side callbacks with multiple Outputs, only return a single dash_clientside.no_update
232+
if (b?.description === 'Return to prevent updating an Output.') {
233+
return zip(a, [b]);
234+
}
235+
return zip(a, b);
236+
}
237+
return [[a, b]];
238+
};
231239

232240
function cleanOutputProp(property: string) {
233241
return property.split('@')[0];
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from dash import (
2+
Dash,
3+
Input,
4+
Output,
5+
html,
6+
clientside_callback,
7+
)
8+
9+
10+
def test_cmorsnu001_clientside_multiple_output_return_single_no_update(dash_duo):
11+
app = Dash(__name__)
12+
app.layout = html.Div(
13+
[
14+
html.Button("trigger", id="trigger-demo"),
15+
html.Div("demo1", id="output-demo1"),
16+
html.Div("demo2", id="output-demo2"),
17+
],
18+
style={"padding": 50},
19+
)
20+
21+
clientside_callback(
22+
"""(n_clicks) => {
23+
try {
24+
return window.dash_clientside.no_update;
25+
} catch (e) {
26+
return [null, null];
27+
}
28+
}""",
29+
Output("output-demo1", "children"),
30+
Output("output-demo2", "children"),
31+
Input("trigger-demo", "n_clicks"),
32+
prevent_initial_call=True,
33+
)
34+
35+
dash_duo.start_server(app)
36+
37+
trigger_clicker = dash_duo.wait_for_element("#trigger-demo")
38+
trigger_clicker.click()
39+
dash_duo.wait_for_text_to_equal(
40+
"#output-demo1",
41+
"demo1",
42+
)
43+
dash_duo.wait_for_text_to_equal(
44+
"#output-demo2",
45+
"demo2",
46+
)

0 commit comments

Comments
 (0)