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

Fix dynamic callbacks reset graphs. #2700

Merged
merged 1 commit into from
Nov 27, 2023
Merged
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
2 changes: 1 addition & 1 deletion dash/dash-renderer/src/APIController.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function storeEffect(props, events, setErrorLoading) {
);
} else if (
dependenciesRequest.status === STATUS.OK &&
isEmpty(graphs)
(isEmpty(graphs) || graphs.reset)
) {
dispatch(
setGraphs(
Expand Down
5 changes: 3 additions & 2 deletions dash/dash-renderer/src/actions/requestDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {setGraphs} from './index';
import apiThunk from './api';

export function requestDependencies() {
return (dispatch: any) => {
return (dispatch: any, getState: any) => {
batch(() => {
dispatch(setGraphs({}));
const {graphs} = getState();
dispatch(setGraphs({...graphs, reset: true}));
dispatch(
apiThunk('_dash-dependencies', 'GET', 'dependenciesRequest')
);
Expand Down
31 changes: 31 additions & 0 deletions tests/integration/callbacks/test_dynamic_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,34 @@ def on_click2(n_clicks2):

dash_duo.wait_for_element("#dynamic").click()
dash_duo.wait_for_text_to_equal("#output-2", "Dynamic clicks 2")


def test_dync002_dynamic_callback_without_element(dash_duo):
app = Dash()

app.layout = html.Div(
[
html.Button("Add callbacks", id="add-callbacks"),
html.Div(id="output"),
]
)

@app.callback(
Output("output", "children"),
Input("add-callbacks", "n_clicks"),
_allow_dynamic_callbacks=True,
prevent_initial_call=True,
)
def on_add_callback(_):
@app.callback(Output("no-exist", "children"), Input("invalid", "n_clicks"))
def addition(_):
return "additional"

return html.Div("add callbacks")

dash_duo.start_server(app)

dash_duo.wait_for_element("#add-callbacks").click()
dash_duo.wait_for_text_to_equal("#output", "add callbacks")

assert dash_duo.get_logs() == []