From a8798da64249cf489cd5758aea3f3bd249812f01 Mon Sep 17 00:00:00 2001 From: philippe Date: Fri, 20 Nov 2026 15:30:28 -0500 Subject: [PATCH 1/2] Fall back to force layout when the callback graph's dagre layout fails dagre 0.8.5 throws "Cannot set properties of undefined (setting 'order')" on some graph shapes (seen on the Dash docs app, 598 callbacks), which replaced the whole callback graph with an error. Run the layout ourselves instead of through CytoscapeComponent's layout prop, catch the failure, lay out with fcose and show a short note. --- CHANGELOG.md | 5 + .../CallbackGraph/CallbackGraphContainer.css | 12 ++ .../CallbackGraphContainer.react.js | 46 +++++- .../integration/devtools/test_devtools_ui.py | 135 +++++++++++++++++- 4 files changed, 190 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef3c33f9cf..125ec6c73f 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 the dev tools callback graph crashing with `Cannot set properties of undefined (setting 'order')` on some apps. When the dagre layout fails, it now falls back to the force layout and says so. + ## [4.5.1] - 2026-11-19 ### Removed diff --git a/dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.css b/dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.css index 347ee515ab..ded49c35ca 100644 --- a/dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.css +++ b/dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.css @@ -43,3 +43,15 @@ top: 3px; right: 3px; } + +.dash-callback-dag--layoutNote { + position: absolute; + top: 30px; + right: 3px; + padding: 4px 8px; + border-radius: 4px; + background: rgba(255, 255, 255, 0.9); + border: 1px solid #ccc; + font-family: Verdana, sans-serif; + font-size: 12px; +} diff --git a/dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.react.js b/dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.react.js index 939bbece9e..b55032a88a 100644 --- a/dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.react.js +++ b/dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.react.js @@ -213,6 +213,10 @@ function CallbackGraph() { const chosenType = graphLayout?._chosenType; const layoutSelector = useRef(null); const [layoutType, setLayoutType] = useState(chosenType || 'top-down'); + const [layoutFailed, setLayoutFailed] = useState( + Boolean(graphLayout?._layoutFailed) + ); + const layoutFailedRef = useRef(layoutFailed); // Generate and memoize the elements. const elements = useMemo( @@ -263,10 +267,39 @@ function CallbackGraph() { positions, zoom: cy.zoom(), pan: cy.pan(), - _chosenType: layoutSelector.current?.value + _chosenType: layoutSelector.current?.value, + _layoutFailed: layoutFailedRef.current }; } + function markLayoutFailed(failed) { + layoutFailedRef.current = failed; + setLayoutFailed(failed); + } + + // Run the layout here instead of through CytoscapeComponent's layout + // prop, so a dagre failure on some graph shapes can fall back to force. + useCytoscapeEffect( + cy => { + if (chosenType === layoutType) { + cy.layout(graphLayout).run(); + return; + } + try { + markLayoutFailed(false); + cy.layout( + mergeRight(layouts[layoutType], {ready: setPresetLayout}) + ).run(); + } catch (e) { + markLayoutFailed(true); + cy.layout( + mergeRight(forceLayout, {ready: setPresetLayout}) + ).run(); + } + }, + [cytoscape, elements] + ); + // Adds callbacks once cyctoscape is initialized. useCytoscapeEffect( cy => { @@ -393,18 +426,12 @@ function CallbackGraph() { } } - const cyLayout = - chosenType === layoutType - ? graphLayout - : mergeRight(layouts[layoutType], {ready: setPresetLayout}); - return (
{selected ? ( @@ -440,6 +467,11 @@ function CallbackGraph() { ))} + {layoutFailed ? ( +
+ The {layoutType} layout failed, showing force instead. +
+ ) : null}
); } diff --git a/tests/integration/devtools/test_devtools_ui.py b/tests/integration/devtools/test_devtools_ui.py index e10e95613d..b59ad3f891 100644 --- a/tests/integration/devtools/test_devtools_ui.py +++ b/tests/integration/devtools/test_devtools_ui.py @@ -1,7 +1,7 @@ from time import sleep import flask -from dash import Dash, Input, Output, dcc, html +from dash import MATCH, Dash, Input, Output, State, dcc, html, no_update import dash.testing.wait as wait from dash_test_components import WidthComponent @@ -121,6 +121,139 @@ def test_dvui003_callback_graph(dash_duo): ) +def test_dvui008_callback_graph_dagre_failure_falls_back(dash_duo): + # Minimal set reduced from the Dash docs app: dagre's layout throws + # "Cannot set properties of undefined (setting 'order')" on this graph. + # Needs both the location.pathname input/output loop and the unrelated + # callbacks; dropping any one of them lays out fine. + app = Dash(__name__, suppress_callback_exceptions=True) + app.layout = html.Div("callback graph layout", id="content") + + def noop(*_): + return no_update + + def cb(outputs, inputs, state=()): + app.callback(outputs, inputs, list(state), prevent_initial_call=True)(noop) + + cb( + [ + Output("ddk-main-app", "theme"), + Output("sun-icon", "style"), + Output("moon-icon", "style"), + Output("logo-img", "src"), + ], + [Input("dark-mode-switch", "on"), Input("location", "pathname")], + ) + cb( + [ + Output({"type": "links-show", "index": MATCH}, "className"), + Output({"type": "load-more-btn", "index": MATCH}, "style"), + ], + [Input({"type": "load-more-btn", "index": MATCH}, "n_clicks")], + ) + cb( + [ + Output(i, p) + for i, p in [ + ("chapter", "children"), + ("backlinks-top", "children"), + ("backlinks-top", "style"), + ("backlinks-bottom", "children"), + ("pagemenu", "dummy2"), + ("location", "pathname"), + ("url-params", "data"), + ("page-title", "data"), + ("pagemenu", "style"), + ("chapters-sidebar", "updateComponent"), + ("app-catalog-example", "children"), + ("main-app-content", "style"), + ("refresh-page", "data"), + ("chapters-sidebar", "searchIndex"), + ("de-version", "data"), + ("de-version-dropdown", "value"), + ("de-version-dd-container", "style"), + ("location", "hash"), + ("sidebar-image-img", "src"), + ("sidebar-image-link", "href"), + ] + ], + [ + Input("location", "pathname"), + Input("location", "search"), + Input("de-version-dropdown", "value"), + ], + [ + State("location", "hash"), + State("last-path", "data"), + State("de-version", "data"), + ], + ) + cb( + [ + Output("pagemenu", "dummy"), + Output("last-path", "data"), + Output("refresh-page-confirm", "data"), + ], + [Input("page-title", "data")], + [ + State("location", "pathname"), + State("url-params", "data"), + State("location", "hash"), + State("refresh-page", "data"), + ], + ) + cb( + [ + Output("updating-column-maintain-order", "columnDefs"), + Output("btn-init-props-maintain-order", "children"), + ], + [Input("btn-init-props-maintain-order", "n_clicks")], + ) + cb( + Output("updating-column-group2", "columnDefs"), + [ + Input("btn-column-group-set1", "n_clicks"), + Input("btn-column-group-set2", "n_clicks"), + ], + ) + cb( + [ + Output("updating-column-group", "columnDefs"), + Output("btn-toggle-cols", "children"), + ], + [Input("btn-toggle-cols", "n_clicks")], + ) + cb( + [ + Output("toggle-medals-columns", "columnDefs"), + Output("medal-toggle", "children"), + ], + [Input("medal-toggle", "n_clicks")], + ) + + dash_duo.start_server( + app, + debug=True, + use_reloader=False, + use_debugger=True, + dev_tools_hot_reload=False, + dev_tools_disable_version_check=True, + ) + + dash_duo.wait_for_text_to_equal("#content", "callback graph layout") + dash_duo.find_element("#dash-debug-menu__callback-graph-button").click() + dash_duo.wait_for_element('canvas[data-id="layer2-node"]') + note = "The top-down layout failed, showing force instead." + dash_duo.wait_for_contains_text(".dash-callback-dag--layoutNote", note) + + # the fallback and its note persist when the graph is closed and reopened + dash_duo.find_element("#dash-debug-menu__callback-graph-button").click() + dash_duo.wait_for_no_elements(".dash-callback-dag--container") + dash_duo.find_element("#dash-debug-menu__callback-graph-button").click() + dash_duo.wait_for_contains_text(".dash-callback-dag--layoutNote", note) + assert dash_duo.get_logs() == [] + + def test_dvui004_width_props(dash_duo): app = Dash(__name__) From b23a0cc12ad28ca0b77b578294d568e163f98527 Mon Sep 17 00:00:00 2001 From: philippe Date: Fri, 20 Nov 2026 15:30:48 -0500 Subject: [PATCH 2/2] Add PR number to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 125ec6c73f..73637761c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## [UNRELEASED] ### Fixed -- [#]() Fix the dev tools callback graph crashing with `Cannot set properties of undefined (setting 'order')` on some apps. When the dagre layout fails, it now falls back to the force layout and says so. +- [#4166](https://github.com/plotly/dash/pull/4166) Fix the dev tools callback graph crashing with `Cannot set properties of undefined (setting 'order')` on some apps. When the dagre layout fails, it now falls back to the force layout and says so. ## [4.5.1] - 2026-11-19