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' ;
28import {
39 path ,
410 concat ,
@@ -21,7 +27,12 @@ import {useSelector, useDispatch, batch} from 'react-redux';
2127import ComponentErrorBoundary from '../components/error/ComponentErrorBoundary.react' ;
2228import { DashLayoutPath , UpdatePropsPayload } from '../types/component' ;
2329import { DashConfig } from '../config' ;
24- import { notifyObservers , onError , updateProps } from '../actions' ;
30+ import {
31+ notifyObservers ,
32+ onError ,
33+ updateProps ,
34+ resetComponentState
35+ } from '../actions' ;
2536import { getWatchedKeys , stringifyId } from '../actions/dependencies' ;
2637import {
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 /> }
0 commit comments