File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
apps/reactotron-app/src/renderer/contexts/Standalone Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -135,12 +135,15 @@ export function reducer(state: State, action: Action) {
135
135
return
136
136
}
137
137
138
- draftState . commandListeners . forEach ( ( cl ) => cl ( action . payload ) )
139
-
140
138
const connection = draftState . connections . find (
141
139
( c ) => c . clientId === action . payload . clientId
142
140
)
143
141
142
+ if ( ! connection ) {
143
+ console . error ( "Command received for unknown connection" , action . payload )
144
+ return
145
+ }
146
+
144
147
connection . commands = [ action . payload , ...connection . commands ]
145
148
} )
146
149
case ActionTypes . ClearConnectionCommands :
@@ -205,9 +208,16 @@ function useStandalone() {
205
208
} , [ ] )
206
209
207
210
// Called when commands are flowing in.
208
- const commandReceived = useCallback ( ( command : any ) => {
209
- dispatch ( { type : ActionTypes . CommandReceived , payload : command } )
210
- } , [ ] )
211
+ const commandReceived = useCallback (
212
+ ( command : any ) => {
213
+ // First dispatch to update state
214
+ dispatch ( { type : ActionTypes . CommandReceived , payload : command } )
215
+
216
+ // Then notify listeners
217
+ state . commandListeners . forEach ( ( cl ) => cl ( command ) )
218
+ } ,
219
+ [ state . commandListeners ]
220
+ )
211
221
212
222
// Called when a client disconnects. NOTE: They could be coming back. This could happen with a reload of the simulator!
213
223
const connectionDisconnected = useCallback ( ( connection : ReactotronConnection ) => {
You can’t perform that action at this time.
0 commit comments