@@ -24,7 +24,7 @@ import {DashConfig} from '../config';
2424import { notifyObservers , onError , updateProps } from '../actions' ;
2525import { getWatchedKeys , stringifyId } from '../actions/dependencies' ;
2626import { recordUiEdit } from '../persistence' ;
27- import { createElement , isDryComponent } from './wrapping' ;
27+ import { createElement , getComponentLayout , isDryComponent } from './wrapping' ;
2828import Registry from '../registry' ;
2929import isSimpleComponent from '../isSimpleComponent' ;
3030import {
@@ -62,56 +62,61 @@ function DashWrapper({
6262 const setProps = ( newProps : UpdatePropsPayload ) => {
6363 const { id} = componentProps ;
6464 const { _dash_error, ...restProps } = newProps ;
65- const oldProps = componentProps ;
66- const changedProps = pickBy (
67- ( val , key ) => ! equals ( val , oldProps [ key ] ) ,
68- restProps
69- ) ;
70- if ( _dash_error ) {
71- dispatch (
72- onError ( {
73- type : 'frontEnd' ,
74- error : _dash_error
75- } )
65+
66+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
67+ // @ts -ignore
68+ dispatch ( ( dispatch , getState ) => {
69+ const currentState = getState ( ) ;
70+ const { graphs} = currentState ;
71+
72+ const { props : oldProps } = getComponentLayout (
73+ componentPath ,
74+ currentState
7675 ) ;
77- }
78- if ( ! isEmpty ( changedProps ) ) {
79- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
80- // @ts -ignore
81- dispatch ( ( dispatch , getState ) => {
82- const { graphs} = getState ( ) ;
83- // Identify the modified props that are required for callbacks
84- const watchedKeys = getWatchedKeys (
85- id ,
86- keys ( changedProps ) ,
87- graphs
76+ const changedProps = pickBy (
77+ ( val , key ) => ! equals ( val , oldProps [ key ] ) ,
78+ restProps
79+ ) ;
80+ if ( _dash_error ) {
81+ dispatch (
82+ onError ( {
83+ type : 'frontEnd' ,
84+ error : _dash_error
85+ } )
8886 ) ;
87+ }
8988
90- batch ( ( ) => {
91- // setProps here is triggered by the UI - record these changes
92- // for persistence
93- recordUiEdit ( component , newProps , dispatch ) ;
89+ if ( isEmpty ( changedProps ) ) {
90+ return ;
91+ }
9492
95- // Only dispatch changes to Dash if a watched prop changed
96- if ( watchedKeys . length ) {
97- dispatch (
98- notifyObservers ( {
99- id,
100- props : pick ( watchedKeys , changedProps )
101- } )
102- ) ;
103- }
93+ // Identify the modified props that are required for callbacks
94+ const watchedKeys = getWatchedKeys ( id , keys ( changedProps ) , graphs ) ;
95+
96+ batch ( ( ) => {
97+ // setProps here is triggered by the UI - record these changes
98+ // for persistence
99+ recordUiEdit ( component , newProps , dispatch ) ;
104100
105- // Always update this component's props
101+ // Only dispatch changes to Dash if a watched prop changed
102+ if ( watchedKeys . length ) {
106103 dispatch (
107- updateProps ( {
108- props : changedProps ,
109- itempath : componentPath
104+ notifyObservers ( {
105+ id ,
106+ props : pick ( watchedKeys , changedProps )
110107 } )
111108 ) ;
112- } ) ;
109+ }
110+
111+ // Always update this component's props
112+ dispatch (
113+ updateProps ( {
114+ props : changedProps ,
115+ itempath : componentPath
116+ } )
117+ ) ;
113118 } ) ;
114- }
119+ } ) ;
115120 } ;
116121
117122 const createContainer = useCallback (
0 commit comments