Skip to content

Commit 6b6d1cc

Browse files
authored
Merge branch 'dev' into fix-3689-input-min-max
2 parents cc10343 + d2e5bbe commit 6b6d1cc

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

dash/dash-renderer/src/actions/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const actionList = {
1010
ON_ERROR: 1,
1111
SET_HOOKS: 1,
1212
INSERT_COMPONENT: 1,
13-
REMOVE_COMPONENT: 1
13+
REMOVE_COMPONENT: 1,
14+
RESET_COMPONENT_STATE: 1
1415
};
1516

1617
export const getAction = action => {

dash/dash-renderer/src/actions/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export const insertComponent = createAction(getAction('INSERT_COMPONENT'));
2222
export const removeComponent = createAction(getAction('REMOVE_COMPONENT'));
2323

2424
export const onPropChange = createAction(getAction('ON_PROP_CHANGE'));
25+
export const resetComponentState = createAction(
26+
getAction('RESET_COMPONENT_STATE')
27+
);
2528

2629
export function updateProps(payload) {
2730
return (dispatch, getState) => {

dash/dash-renderer/src/reducers/reducer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ const layoutHashes = (state = {}, action) => {
4949
},
5050
state
5151
);
52+
} else if (action.type === 'RESET_COMPONENT_STATE') {
53+
const {itempath} = action.payload;
54+
if (itempath) {
55+
const prefixStr = stringifyPath(itempath);
56+
// Remove all hashes for keys starting with prefixStr
57+
return Object.fromEntries(
58+
Object.entries(state).filter(
59+
([key]) => !key.startsWith(prefixStr)
60+
)
61+
);
62+
}
5263
}
5364
return state;
5465
};

dash/dash-renderer/src/wrapper/DashWrapper.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import React, {useCallback, MutableRefObject, useRef, useMemo} from 'react';
1+
import React, {
2+
useCallback,
3+
MutableRefObject,
4+
useRef,
5+
useMemo,
6+
useEffect
7+
} from 'react';
28
import {
39
path,
410
concat,
@@ -21,7 +27,12 @@ import {useSelector, useDispatch, batch} from 'react-redux';
2127
import ComponentErrorBoundary from '../components/error/ComponentErrorBoundary.react';
2228
import {DashLayoutPath, UpdatePropsPayload} from '../types/component';
2329
import {DashConfig} from '../config';
24-
import {notifyObservers, onError, updateProps} from '../actions';
30+
import {
31+
notifyObservers,
32+
onError,
33+
updateProps,
34+
resetComponentState
35+
} from '../actions';
2536
import {getWatchedKeys, stringifyId} from '../actions/dependencies';
2637
import {
2738
createElement,
@@ -65,6 +76,7 @@ function DashWrapper({
6576
const dispatch = useDispatch();
6677
const memoizedKeys: MutableRefObject<MemoizedKeysType> = useRef({});
6778
const newRender = useRef(false);
79+
const freshRenders = useRef(0);
6880
const renderedPath = useRef<DashLayoutPath>(componentPath);
6981
let renderComponent: any = null;
7082
let renderComponentProps: any = null;
@@ -85,6 +97,7 @@ function DashWrapper({
8597
if (_newRender) {
8698
newRender.current = true;
8799
renderH = 0;
100+
freshRenders.current += 1;
88101
if (renderH in memoizedKeys.current) {
89102
delete memoizedKeys.current[renderH];
90103
}
@@ -432,6 +445,16 @@ function DashWrapper({
432445
return props;
433446
};
434447

448+
useEffect(() => {
449+
if (_newRender) {
450+
dispatch(
451+
resetComponentState({
452+
itempath: componentPath
453+
})
454+
);
455+
}
456+
}, [_newRender]);
457+
435458
const hydrateFunc = () => {
436459
if (newRender.current) {
437460
renderComponent = _passedComponent;
@@ -498,6 +521,7 @@ function DashWrapper({
498521
}
499522
error={_dashprivate_error}
500523
dispatch={dispatch}
524+
key={freshRenders.current}
501525
>
502526
<DashContextProvider componentPath={componentPath}>
503527
{React.isValidElement(hydrated) ? hydrated : <div />}

tests/integration/renderer/test_redraw.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ def on_click(_):
2929

3030
dash_duo.wait_for_text_to_equal("#counter", "1")
3131
dash_duo.find_element("#redraw").click()
32-
dash_duo.wait_for_text_to_equal("#counter", "2")
32+
# dash_duo.wait_for_text_to_equal("#counter", "2")
33+
# time.sleep(1)
34+
# dash_duo.wait_for_text_to_equal("#counter", "2")
35+
36+
## the above was changed due to a mechanism change that generates a new React component, thus resetting the counter
37+
dash_duo.wait_for_text_to_equal("#counter", "1")
3338
time.sleep(1)
34-
dash_duo.wait_for_text_to_equal("#counter", "2")
39+
dash_duo.wait_for_text_to_equal("#counter", "1")

0 commit comments

Comments
 (0)