Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- [#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

### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@
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(
Expand Down Expand Up @@ -263,10 +267,39 @@
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();
}

Check warning on line 298 in dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.react.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Handle this exception, don't catch it at all, or explain in a comment why it is ignored.

See more on https://sonarcloud.io/project/issues?id=plotly_dash&issues=AaH6qFjlqX3MR3ThN5Cv&open=AaH6qFjlqX3MR3ThN5Cv&pullRequest=4166
},
[cytoscape, elements]
);

// Adds callbacks once cyctoscape is initialized.
useCytoscapeEffect(
cy => {
Expand Down Expand Up @@ -393,18 +426,12 @@
}
}

const cyLayout =
chosenType === layoutType
? graphLayout
: mergeRight(layouts[layoutType], {ready: setPresetLayout});

return (
<div className='dash-callback-dag--container'>
<CytoscapeComponent
style={{width: '100%', height: '100%'}}
cy={setCytoscape}
elements={elements}
layout={cyLayout}
stylesheet={stylesheet}
/>
{selected ? (
Expand Down Expand Up @@ -440,6 +467,11 @@
</option>
))}
</select>
{layoutFailed ? (
<div className='dash-callback-dag--layoutNote'>
The {layoutType} layout failed, showing force instead.
</div>
) : null}
</div>
);
}
Expand Down
135 changes: 134 additions & 1 deletion tests/integration/devtools/test_devtools_ui.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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__)

Expand Down
Loading