⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Open
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
3 changes: 2 additions & 1 deletion dash/dash-renderer/src/actions/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const actionList = {
ON_ERROR: 1,
SET_HOOKS: 1,
INSERT_COMPONENT: 1,
REMOVE_COMPONENT: 1
REMOVE_COMPONENT: 1,
RESET_COMPONENT_STATE: 1
};

export const getAction = action => {
Expand Down
3 changes: 3 additions & 0 deletions dash/dash-renderer/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const insertComponent = createAction(getAction('INSERT_COMPONENT'));
export const removeComponent = createAction(getAction('REMOVE_COMPONENT'));

export const onPropChange = createAction(getAction('ON_PROP_CHANGE'));
export const resetComponentState = createAction(
getAction('RESET_COMPONENT_STATE')
);

export function updateProps(payload) {
return (dispatch, getState) => {
Expand Down
11 changes: 11 additions & 0 deletions dash/dash-renderer/src/reducers/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ const layoutHashes = (state = {}, action) => {
},
state
);
} else if (action.type === 'RESET_COMPONENT_STATE') {
const {itempath} = action.payload;
if (itempath) {
const prefixStr = stringifyPath(itempath);
// Remove all hashes for keys starting with prefixStr
return Object.fromEntries(
Object.entries(state).filter(
([key]) => !key.startsWith(prefixStr)
)
);
}
}
return state;
};
Expand Down
28 changes: 26 additions & 2 deletions dash/dash-renderer/src/wrapper/DashWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, {useCallback, MutableRefObject, useRef, useMemo} from 'react';
import React, {
useCallback,
MutableRefObject,
useRef,
useMemo,
useEffect
} from 'react';
import {
path,
concat,
Expand All @@ -21,7 +27,12 @@ import {useSelector, useDispatch, batch} from 'react-redux';
import ComponentErrorBoundary from '../components/error/ComponentErrorBoundary.react';
import {DashLayoutPath, UpdatePropsPayload} from '../types/component';
import {DashConfig} from '../config';
import {notifyObservers, onError, updateProps} from '../actions';
import {
notifyObservers,
onError,
updateProps,
resetComponentState
} from '../actions';
import {getWatchedKeys, stringifyId} from '../actions/dependencies';
import {
createElement,
Expand Down Expand Up @@ -65,6 +76,7 @@ function DashWrapper({
const dispatch = useDispatch();
const memoizedKeys: MutableRefObject<MemoizedKeysType> = useRef({});
const newRender = useRef(false);
const freshRenders = useRef(0);
const renderedPath = useRef<DashLayoutPath>(componentPath);
let renderComponent: any = null;
let renderComponentProps: any = null;
Expand All @@ -85,6 +97,7 @@ function DashWrapper({
if (_newRender) {
newRender.current = true;
renderH = 0;
freshRenders.current += 1;
if (renderH in memoizedKeys.current) {
delete memoizedKeys.current[renderH];
}
Expand Down Expand Up @@ -432,6 +445,16 @@ function DashWrapper({
return props;
};

useEffect(() => {
if (_newRender) {
dispatch(
resetComponentState({
itempath: componentPath
})
);
}
}, [_newRender]);

const hydrateFunc = () => {
if (newRender.current) {
renderComponent = _passedComponent;
Expand Down Expand Up @@ -498,6 +521,7 @@ function DashWrapper({
}
error={_dashprivate_error}
dispatch={dispatch}
key={freshRenders.current}
>
<DashContextProvider componentPath={componentPath}>
{React.isValidElement(hydrated) ? hydrated : <div />}
Expand Down
Loading