1.7.0 (2023-01-14)
Features
Using MSW in a decorator works for most scenarios, but there's a slight chance the service worker will not get registered in time. As a result, a story that requests data might actually request real data. A potential solution to that is to use Storybook loaders. They get executed before a story renders, differently than decorators, which execute as the story renders. This release provides a mswLoader
now, so you can replace your decorator with a loader, and potentially fix race conditions you might have. It works the same, respecting the parameters
you set, so there's no need to change anything else in your codebase.
// .storybook/preview.js
-import { initialize, mswDecorator } from 'msw-storybook-addon'
+import { initialize, mswLoader } from 'msw-storybook-addon'
initialize()
-export const decorators = [mswDecorator]
+export const loaders = [mswLoader]