Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Graph component becomes unresponsive if an invalid figure is passed #3103

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ class PlotlyGraph extends Component {
configClone.typesetMath = mathjax;

const figureClone = {
data: figure.data,
layout: this.getLayout(figure.layout, responsive),
frames: figure.frames,
data: figure?.data,
layout: this.getLayout(figure?.layout, responsive),
frames: figure?.frames,
config: configClone,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,44 @@ def handleClick(clickData):
data = json.loads(data)
assert "customdata" in data["points"][0], "graph clickData must contain customdata"
assert data["points"][0]["customdata"][0] == expected_value


def test_grbs008_graph_with_empty_figure(dash_dcc):
app = Dash(__name__)
app.layout = html.Div(
[
html.Button("Toggle graph", id="btn"),
dcc.Graph(
id="graph",
figure=None,
),
]
)

@app.callback(Output("graph", "figure"), [Input("btn", "n_clicks")])
def toggle_figure(n_clicks):
if int(n_clicks or 0) % 2 == 0:
# a valid figure
return go.Figure([], layout=go.Layout(title="Valid Figure"))
else:
# an invalid figure
return None

dash_dcc.start_server(app)

# Click the toggle button a couple of times and expect the graph to change between the
# valid and invalid figures, using the "title" as the indicator.
dash_dcc.wait_for_element("#graph")
wait.until(
lambda: dash_dcc.find_element(".gtitle").text == "Valid Figure", timeout=2
)

dash_dcc.find_element("#btn").click()
wait.until(lambda: len(dash_dcc.find_elements(".gtitle")) == 0, timeout=2)

dash_dcc.find_element("#btn").click()
wait.until(
lambda: dash_dcc.find_element(".gtitle").text == "Valid Figure", timeout=2
)

assert dash_dcc.get_logs() == []