From 5acdc8b6cc513ff9f9fff4f932e0ea9aad5aef17 Mon Sep 17 00:00:00 2001 From: Otso Lehdonvirta Date: Mon, 23 Nov 2026 14:34:11 +0200 Subject: [PATCH 1/2] Skip empty clientside no_update component results --- CHANGELOG.md | 5 + dash/dash-renderer/src/actions/callbacks.ts | 2 +- .../clientside/test_clientside_no_update.py | 100 ++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 tests/integration/clientside/test_clientside_no_update.py diff --git a/CHANGELOG.md b/CHANGELOG.md index ef3c33f9cf..7122f05b80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to `dash` will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [UNRELEASED] + +### Fixed +- Fix clientside callbacks dispatching empty property updates and unnecessarily rendering components whose outputs all return `dash_clientside.no_update`. + ## [4.5.1] - 2026-11-19 ### Removed diff --git a/dash/dash-renderer/src/actions/callbacks.ts b/dash/dash-renderer/src/actions/callbacks.ts index 83d3fe5e93..1016069b28 100644 --- a/dash/dash-renderer/src/actions/callbacks.ts +++ b/dash/dash-renderer/src/actions/callbacks.ts @@ -353,8 +353,8 @@ async function handleClientside( zipIfArray(outi, reti).forEach(([outij, retij]) => { const {id, property} = outij; const idStr = stringifyId(id); - const dataForId = (result[idStr] = result[idStr] || {}); if (retij !== dc.no_update) { + const dataForId = (result[idStr] = result[idStr] || {}); dataForId[cleanOutputProp(property)] = retij; } }); diff --git a/tests/integration/clientside/test_clientside_no_update.py b/tests/integration/clientside/test_clientside_no_update.py new file mode 100644 index 0000000000..8754eaa7b4 --- /dev/null +++ b/tests/integration/clientside/test_clientside_no_update.py @@ -0,0 +1,100 @@ +import pytest +from dash import ALL, Dash, Input, Output, html +from dash.testing.wait import until +import dash_test_components as dt + + +@pytest.mark.parametrize( + "outputs", ["single", "mixed", "all", "all-sentinel", "pattern"] +) +def test_clnu001_no_update_does_not_redraw(dash_duo, outputs): + app = Dash(__name__) + pattern = outputs == "pattern" + counters = ( + [dt.DrawCounter(id={"type": "counter", "index": i}) for i in range(2)] + if pattern + else [dt.DrawCounter(id="counter"), dt.DrawCounter(id="other")] + ) + app.layout = html.Div( + [html.Button("Run", id="run"), html.Div(id="active"), *counters] + ) + callback_outputs = [Output("counter", "id")] + body = "return dc.no_update;" + if outputs in ("mixed", "all", "all-sentinel"): + callback_outputs = [ + Output("counter", "id"), + Output("active", "children"), + Output("other", "id"), + ] + body = { + "mixed": "return [dc.no_update, n, dc.no_update];", + "all": "return [dc.no_update, dc.no_update, dc.no_update];", + "all-sentinel": "return dc.no_update;", + }[outputs] + elif pattern: + callback_outputs = [Output({"type": "counter", "index": ALL}, "id")] + body = "return [dc.no_update, dc.no_update];" + + app.clientside_callback( + "function(n) { const dc = window.dash_clientside; " + "window.noUpdateCalls = (window.noUpdateCalls || 0) + 1; " + body + "}", + *callback_outputs, + Input("run", "n_clicks"), + prevent_initial_call=True, + ) + dash_duo.start_server(app) + selectors = ( + [ + '[id=\'{"index":0,"type":"counter"}\']', + '[id=\'{"index":1,"type":"counter"}\']', + ] + if pattern + else ["#counter", "#other"] + ) + for selector in selectors: + dash_duo.wait_for_text_to_equal(selector, "1") + for n in range(1, 4): + dash_duo.find_element("#run").click() + until( + lambda: dash_duo.driver.execute_script("return window.noUpdateCalls;") == n + and not dash_duo.redux_state_is_loading, + timeout=5, + ) + dash_duo.driver.execute_async_script( + "const done = arguments[0]; requestAnimationFrame(() => requestAnimationFrame(done));" + ) + for selector in selectors: + assert dash_duo.find_element(selector).text == "1" + if outputs == "mixed": + dash_duo.wait_for_text_to_equal("#active", str(n)) + assert dash_duo.get_logs() == [] + + +def test_clnu002_no_update_with_another_prop_on_the_same_component(dash_duo): + app = Dash(__name__) + app.layout = html.Div( + [ + html.Button("Run", id="run"), + html.Div("initial", id="result", title="original"), + ] + ) + app.clientside_callback( + """function(n) { + const skip = window.dash_clientside.no_update; + return n % 2 ? [skip, String(n)] : [String(n), skip]; + }""", + Output("result", "children"), + Output("result", "title"), + Input("run", "n_clicks"), + prevent_initial_call=True, + ) + dash_duo.start_server(app) + for n in range(1, 4): + dash_duo.find_element("#run").click() + until( + lambda: dash_duo.find_element("#result").get_attribute("title") + == str(n if n % 2 else n - 1), + timeout=5, + ) + dash_duo.wait_for_text_to_equal("#result", "initial" if n == 1 else "2") + assert dash_duo.get_logs() == [] From c871bcc014ca00ce9700e9597c157617c7f807ff Mon Sep 17 00:00:00 2001 From: Otso Lehdonvirta Date: Mon, 23 Nov 2026 14:36:42 +0200 Subject: [PATCH 2/2] Link no_update fix changelog to its pull request --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7122f05b80..e1a9583858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## [UNRELEASED] ### Fixed -- Fix clientside callbacks dispatching empty property updates and unnecessarily rendering components whose outputs all return `dash_clientside.no_update`. +- [#4175](https://github.com/plotly/dash/pull/4175) Fix clientside callbacks dispatching empty property updates and unnecessarily rendering components whose outputs all return `dash_clientside.no_update`. Fixes [#4173](https://github.com/plotly/dash/issues/4173). ## [4.5.1] - 2026-11-19