Skip to content

Commit a96ab64

Browse files
committed
updating to pull in the changed props and only goes down one descendant
1 parent 8d94cc2 commit a96ab64

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

dash/dash-renderer/src/wrapper/selectors.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,68 @@ interface ChangedPropsRecord {
1414
renderType: string;
1515
}
1616

17-
const previousHashes = {};
17+
interface Hashes {
18+
[key: string]: any; // Index signature for string keys with number values
19+
}
20+
21+
const previousHashes: Hashes = {};
22+
23+
const isFirstLevelPropsChild = (
24+
updatedPath: string,
25+
strPath: string
26+
): [boolean, string[]] => {
27+
const updatedSegments = updatedPath.split(',');
28+
const fullSegments = strPath.split(',');
29+
30+
// Check that strPath actually starts with updatedPath
31+
const startsWithPath = fullSegments.every(
32+
(seg, i) => updatedSegments[i] === seg
33+
);
34+
35+
if (!startsWithPath) return [false, []];
36+
37+
// Get the remaining path after the prefix
38+
const remainingSegments = updatedSegments.slice(fullSegments.length);
39+
40+
const propsCount = remainingSegments.filter(s => s === 'props').length;
41+
42+
return [propsCount < 2, remainingSegments];
43+
};
1844

1945
function determineChangedProps(
2046
state: any,
2147
strPath: string
2248
): ChangedPropsRecord {
2349
let combinedHash = 0;
24-
const renderType = 'update'; // Default render type, adjust as needed
50+
let renderType: any; // Default render type, adjust as needed
51+
const changedProps: Record<string, any> = {};
2552
Object.entries(state.layoutHashes).forEach(([updatedPath, pathHash]) => {
26-
if (updatedPath.startsWith(strPath)) {
53+
const [descendant, remainingSegments] = isFirstLevelPropsChild(
54+
updatedPath,
55+
strPath
56+
);
57+
if (descendant) {
2758
const previousHash: any = pathOr({}, [updatedPath], previousHashes);
2859
combinedHash += pathOr(0, ['hash'], pathHash);
2960
if (previousHash !== pathHash) {
30-
previousHash[updatedPath] = pathHash;
61+
if (updatedPath !== strPath) {
62+
Object.assign(changedProps, {[remainingSegments[1]]: true});
63+
renderType = 'components';
64+
} else {
65+
Object.assign(
66+
changedProps,
67+
pathOr({}, ['changedProps'], pathHash)
68+
);
69+
renderType = pathOr({}, ['renderType'], pathHash);
70+
}
71+
previousHashes[updatedPath] = pathHash;
3172
}
3273
}
3374
});
3475

3576
return {
3677
hash: combinedHash,
37-
changedProps: {},
78+
changedProps,
3879
renderType
3980
};
4081
}

tests/integration/renderer/test_descendant_listening.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from dash import dcc, html, Input, Output, Patch, Dash
22

3-
from dash.testing.wait import until
4-
53

64
def test_dcl001_descendant_tabs(dash_duo):
75
app = Dash()
@@ -49,7 +47,7 @@ def toggle_tabs(store_data):
4947
return True, True
5048

5149
dash_duo.start_server(app)
52-
dash_duo.wait_for_text_to_equal("#button", f"Enable Tabs")
50+
dash_duo.wait_for_text_to_equal("#button", "Enable Tabs")
5351
dash_duo.find_element("#tab-a.tab--disabled")
5452
dash_duo.find_element("#button").click()
5553
dash_duo.find_element("#tab-a:not(.tab--disabled)")

0 commit comments

Comments
 (0)