mswjs / msw-storybook-addon

Mock API requests in Storybook with Mock Service Worker.
https://msw-sb.vercel.app
MIT License
407 stars 39 forks source link

Storybook keeps reloading when this add-on is enabled #113

Open szymonnowak-st opened 1 year ago

szymonnowak-st commented 1 year ago

Hi!

I've got an issue that whenever this add-on is enabled and Chrome dev tools is opened, Storybook keeps reloading the page, which makes it impossible to use. When I unregister the worker (via Chrome dev tools: Application -> Storage -> Clear site data), it stops reloading, but then when I manually reload the page it starts reloading the page constantly again. When I close Chrome dev tools it works again.

Has anyone else encountered such behavior before? It happens in incognito mode as well, so it's most likely not caused by some extensions, but rather because of some strange setting that I have enabled. It only happens in Chrome for me, it works correctly in Firefox and Safari. Other people on the team do not have this issue...

I'm using storybook/react 6.5.16, msw 1.2.1, and msw-storybook-addon 1.8.0 and webpack 5.

Unfortunately, I don't have a small example that reproduces this problem, but I recorded a video:

https://github.com/mswjs/msw-storybook-addon/assets/107425534/a5931f24-9569-44bc-b620-97b621f83e01

boonya commented 11 months ago

Do you use mock service worker? Because I do. Once removed the issue disappeared. I am just trying to say that the root cause somewhere under the hood of MSW, maybe.

P.S. Sorry, I see you use it.

FYI, in my case

boonya commented 11 months ago

P.S. Upgrade to

did not help

AdrianDiazG commented 4 months ago

Same problem here

AdrianDiazG commented 4 months ago

it can be related to this one: https://github.com/mswjs/msw-storybook-addon/issues/36

boonya commented 4 months ago

With the setup below no issue anymore on my end. But it's not possible to open a story in a separate window now. Seems loader is defined somewhere outside of iframe.

// .storybook/preview.tsx
import type {Preview, Decorator, Parameters} from '@storybook/react';
import {initialize, mswDecorator, mswLoader} from 'msw-storybook-addon';

initialize({
    serviceWorker: {url: `${APP_PREFIX}mockServiceWorker.js`},
    onUnhandledRequest: 'bypass',
});

export const decorators: Decorator[] = [
    ...
    mswDecorator,
    ...
];

const parameters: Parameters = {
    loaders: [mswLoader],
    ...
};
aygee commented 1 week ago

I experienced the same issue on one of my google chrome profile. Interestingly, it works fine on my other chrome profile.

I tried to disable all extensions but could not get rid of the issue on the problematic profile.

Maybe try to run it on a different google chrome profile and see if it behaves differently?

aygee commented 1 week ago

Update: Deleting the profile and adding the same one (I have mine synced) fixes it. It's a weird bug but hopefully it helps.