-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Interference with HMR #36
Comments
I have a similar issue when using fetch-mock - see storybookjs/storybook#18702 |
Faced the same problem when using this. I've found solution from this discussion mswjs/msw#1424 by creating custom worker with filtering by URL. For example, create custom worker: // public/apiMockServiceWorker.js
self.addEventListener('fetch', (event) => {
const url = new URL(event.request.url);
if (!url.pathname.startsWith('/api/')) {
// Do not propagate this event to other listeners (from MSW)
event.stopImmediatePropagation();
}
});
importScripts('./mockServiceWorker.js'); then initialize with custom worker: // .storybook/preview.js
import { initialize, mswDecorator } from 'msw-storybook-addon';
// Initialize MSW with custom worker
initialize({
serviceWorker: { url: '/apiMockServiceWorker.js' },
}); now MSW intercepts only URLs with pathname starts with |
Hey @Arttse thank you so much for providing that solution. I added a troubleshooting section in the docs do refer to your comment as a workaround. @kettanaito I guess there's no better solution than that? In Storybook there are definitely requests which we could potentially filter out by default e.g. hot-update.json but also any request coming from vendors in node_modules, etc to detract the noise and improve performance. However if that's a MSW limitation then there's nothing we can do, right? I also saw this very interesting comment about using request.passthrough on specific requests. Would that help in this situation? |
@yannbf, using rest.get('/hot-update/*', (req) => req.passthrough())
Once we have this set of handlers, we need to initialize MSW with them, allowing the end-user to add their own handlers on top. I'm open to discussion on this if you think this API is unsuitable. But, generally, if you want to affect the network, you do that only via request handlers. |
Unfortunately, the solutions presented here didn't work for me, but I solved it by disabling updateViaCache: initialize({
serviceWorker: {
options: {
updateViaCache: 'none'
}
}
}) |
Versions:
"msw": "0.27.2",
"msw-storybook-addon": "1.1.0",
I often get an error which forces me to reload storybook page.
I suppose that MSW intercepts one of HMR requests and fails.
At the same time I see this error in console:
[MSW] Failed to mock a "GET" request to "http://localhost:6006/4cb31fa2eee22cf5b32f.hot-update.json": TypeError: Cannot read property 'id' of undefined at handleRequest (http://localhost:6006/mockServiceWorker.js:117:34)
The text was updated successfully, but these errors were encountered: