Skip to content

allow_duplicates to work with Loading #3289

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

Merged
merged 8 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- [#3284](https://github.com/plotly/dash/pull/3284) Fix component as props having the same key when used in the same container.
- [#3287](https://github.com/plotly/dash/pull/3287) Fix typing component generation & explicitize_args.
- [#3282](https://github.com/plotly/dash/pull/3282) Fix incorrect cancellation of pattern matched long callbacks.
- [#3289](https://github.com/plotly/dash/pull/3289) Fixed issue with debugTitle where status doesnt exist and allow_duplicates to ignore the hash for prop loading in the target.

## [3.0.3] - 2025-04-14

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ const loadingSelector = (componentPath, targetComponents) => state => {
return false;
}
if (Array.isArray(target)) {
return includes(l.property, target);
return includes(l.property.split('@')[0], target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it might be better to set that in the reducer or the action.

There is a // duplicate outputs comment that I think may have been a todo here:

To change on the callback would be here:

property: out.property,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious about that, didnt want to mess around with the hash in the callback. Wasnt sure about side-effects of that change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes the debug=True in the loading much nicer, since it strips the hash.

}
return l.property === target;
return l.property.split('@')[0] === target;
}, load)
) {
return acc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CircleSpinner = ({
style,
}) => {
let debugTitle;
if (debug) {
if (debug && status) {
debugTitle = status.map((s) => <DebugTitle {...s} />);
}
let spinnerClass = fullscreen ? 'dash-spinner-container' : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DebugTitle from './DebugTitle.jsx';

const CubeSpinner = ({status, color, fullscreen, debug, className, style}) => {
let debugTitle;
if (debug) {
if (debug && status) {
debugTitle = status.map((s) => <DebugTitle {...s} />);
}
let spinnerClass = fullscreen ? 'dash-spinner-container' : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const DefaultSpinner = ({
style,
}) => {
let debugTitle;
if (debug) {
if (debug && status) {
debugTitle = status.map((s) => <DebugTitle {...s} />);
}
let spinnerClass = fullscreen ? 'dash-spinner-container' : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import DebugTitle from './DebugTitle.jsx';
*/
const DotSpinner = ({status, color, fullscreen, debug, className, style}) => {
let debugTitle;
if (debug) {
if (debug && status) {
debugTitle = status.map((s) => <DebugTitle {...s} />);
}
let spinnerClass = fullscreen ? 'dash-spinner-container' : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DebugTitle from './DebugTitle.jsx';

const GraphSpinner = ({status, fullscreen, debug, className, style}) => {
let debugTitle;
if (debug) {
if (debug && status) {
debugTitle = status.map((s) => <DebugTitle {...s} />);
}
let spinnerClass = fullscreen ? 'dash-spinner-container' : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,3 +689,66 @@ def updateDiv(n_clicks):
dash_dcc.wait_for_text_to_equal("#div-1", "changed")

assert dash_dcc.get_logs() == []

# multiple components, only one triggers the spinner
def test_ldcp017_loading_component_target_components_duplicates(dash_dcc):

lock = Lock()

app = Dash(__name__)

app.layout = html.Div(
[
dcc.Loading(
[
html.Button(id="btn-1"),
html.Button(id="btn-2", children="content 2"),
],
className="loading-1",
target_components={"btn-2": "children"},
debug=True
)
],
id="root",
)

@app.callback(Output("btn-1", "children"), [Input("btn-2", "n_clicks")])
def updateDiv1(n_clicks):
if n_clicks:
with lock:
return "changed 1"

return "content 1"

@app.callback(Output("btn-2", "children", allow_duplicate=True),
[Input("btn-1", "n_clicks")],
prevent_initial_call=True)
def updateDiv2(n_clicks):
if n_clicks:
with lock:
return "changed 2"

return "content 2"

dash_dcc.start_server(app)

dash_dcc.wait_for_text_to_equal("#btn-1", "content 1")
dash_dcc.wait_for_text_to_equal("#btn-2", "content 2")

with lock:
dash_dcc.find_element("#btn-1").click()

dash_dcc.find_element(".loading-1 .dash-spinner")
dash_dcc.wait_for_text_to_equal("#btn-2", "")

dash_dcc.wait_for_text_to_equal("#btn-2", "changed 2")

with lock:
dash_dcc.find_element("#btn-2").click()
spinners = dash_dcc.find_elements(".loading-1 .dash-spinner")
dash_dcc.wait_for_text_to_equal("#btn-1", "")

dash_dcc.wait_for_text_to_equal("#btn-1", "changed 1")
assert spinners == []

assert dash_dcc.get_logs() == []