Fixes for console socket disconnecting with HMR enabled
This commit is contained in:
parent
2b68e5a984
commit
49de1d0ed4
5 changed files with 61 additions and 24 deletions
|
@ -4,7 +4,7 @@ import { ServerContext } from '@/state/server';
|
|||
|
||||
export default () => {
|
||||
const server = ServerContext.useStoreState(state => state.server.data);
|
||||
const instance = ServerContext.useStoreState(state => state.socket.instance);
|
||||
const { instance, connected } = ServerContext.useStoreState(state => state.socket);
|
||||
const setServerStatus = ServerContext.useStoreActions(actions => actions.status.setServerStatus);
|
||||
const { setInstance, setConnectionState } = ServerContext.useStoreActions(actions => actions.socket);
|
||||
|
||||
|
@ -32,5 +32,15 @@ export default () => {
|
|||
};
|
||||
}, [ server ]);
|
||||
|
||||
// Prevent issues with HMR in development environments. This might need to also
|
||||
// exist outside of dev? Will need to see how things go.
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
useEffect(() => {
|
||||
if (!connected && instance) {
|
||||
instance.connect();
|
||||
}
|
||||
}, [ connected ]);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
|
Reference in a new issue