Skip to content
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/observers/executedCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ const observer: IStoreObserverDefinition<IStoreState> = {
childrenPropPath,
appliedProps
);
if (!children) {
if (children === undefined) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This also fixes children="" and children=0, which had the same stale-paths bug. Can you add a renderer test or a second case in the integration test so nobody puts back a !children check later?

return;
}

Expand Down
58 changes: 58 additions & 0 deletions tests/integration/callbacks/test_layout_paths_with_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
import json
from multiprocessing import Value
import time

import pytest
from dash import Dash, Input, Output, dcc, html
import dash.testing.wait as wait

Expand Down Expand Up @@ -248,3 +251,58 @@ def check_call_counts(chapters, count):
)
check_chapter("chapter1")
snapshot(name="chapter-1-again")


@pytest.mark.parametrize(
"replacement", [None, "", 0], ids=["none", "empty-string", "zero"]
)
def test_cblp002_callback_replaces_children_with_falsy_value_and_can_remount(
dash_duo, replacement
):
view_calls = []

app = Dash(__name__, suppress_callback_exceptions=True)
app.layout = html.Div(
[
html.Button("Toggle", id="toggle"),
dcc.Interval(id="tick", interval=200),
html.Div(id="container"),
]
)

@app.callback(
Output("container", "children"),
Input("toggle", "n_clicks"),
prevent_initial_call=True,
)
def toggle_view(n_clicks):
if n_clicks % 2:
return html.Div(html.Span(id="view-child"), id="view")
return replacement

@app.callback(Output("view-child", "children"), Input("tick", "n_intervals"))
def update_view(n_intervals):
view_calls.append(n_intervals)
return f"tick {n_intervals}"

dash_duo.start_server(app)

dash_duo.find_element("#toggle").click()
dash_duo.wait_for_element("#view-child")
wait.until(lambda: "view-child" in dash_duo.redux_state_paths["strs"], timeout=3)
dash_duo.wait_for_contains_text("#view-child", "tick")
wait.until(lambda: view_calls, timeout=3)

dash_duo.find_element("#toggle").click()
dash_duo.wait_for_no_elements("#view-child")
wait.until(
lambda: "view-child" not in dash_duo.redux_state_paths["strs"], timeout=3
)
calls_after_unmount = len(view_calls)
time.sleep(0.5)
assert len(view_calls) == calls_after_unmount

dash_duo.find_element("#toggle").click()
dash_duo.wait_for_element("#view-child")
wait.until(lambda: "view-child" in dash_duo.redux_state_paths["strs"], timeout=3)
dash_duo.wait_for_contains_text("#view-child", "tick")
Loading