Fixes for console socket disconnecting with HMR enabled

This commit is contained in:
Dane Everitt 2019-09-17 21:59:35 -07:00
parent 2b68e5a984
commit 49de1d0ed4
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 61 additions and 24 deletions

View file

@ -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;
};