webpack-dev-servermiragejs

miragejs '[WDS] Disconnected!' instantly


If I createServer with miragejs, WDS (Webpack Dev Server) get disconnected.

Disconnected

if I disable mirages mock server, WDS works I expected.

Live Reloading enabled

Here is full call stack of [WDS] Disconnected!

Call Stack

src/index.tsx

import { mockServer } from './server';
if (process.env.NODE_ENV === "development") {
    mockServer({ environment: "development" });
}
ReactDOM.render(
    <React.StrictMode>
        <Provider store={store}>
            <ConnectedRouter history={history}>
                <App />
            </ConnectedRouter>
        </Provider>
     </React.StrictMode>,
    document.getElementById('root')
);

src/server.js

import { createServer, Response, Model } from 'miragejs';
export const mockServer = ({ environment = 'test' }) => {

    createServer({
        environment,
        routes() {
            this.namespace = "api";
            this.post('/user/login', (schema, request) => {
                return new Response(200, { }, { id: "admin@gmail.com", email: "qwerty", token: "Edovbkeyd2943kd3" });
            });
        },
    });
}
export default mockServer;

Solution

  • I solved this problem by migrating from React Hot Loader to React Fast Refresh.

    success

    I recommend to read 'Moving towards next step' of React Hot Loader. React Hot Loader is slowly replace to React Fast Refresh.