Skip to content

Commit ca99cf1

Browse files
committed
Fix loading MSW in Storybook in the documentation
1 parent 246e4ca commit ca99cf1

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"frontend/src/gql/**",
1919
"frontend/src/routeTree.gen.ts",
2020
"frontend/.storybook/locales.ts",
21+
"frontend/.storybook/mockServiceWorker.js",
2122
"frontend/locales/*.json",
22-
"frontend/stories/static/**",
2323
"**/coverage/**",
2424
"**/dist/**"
2525
]

frontend/.storybook/main.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import type { StorybookConfig } from "@storybook/react-vite";
99
const config: StorybookConfig = {
1010
stories: ["../{src,stories}/**/*.stories.@(js|jsx|ts|tsx)"],
1111

12-
staticDirs: ["../stories/static"],
13-
1412
addons: [
1513
// Automatic docs pages
1614
"@storybook/addon-docs",
@@ -57,6 +55,13 @@ const config: StorybookConfig = {
5755
env: {
5856
STORYBOOK: "true",
5957
},
58+
59+
viteFinal: async (config) => {
60+
// Host all the assets in the root directory,
61+
// so that the service worker is correctly scoped to the root
62+
config.build.assetsDir = "";
63+
return config;
64+
},
6065
};
6166

6267
export default config;

frontend/.storybook/preview.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ import type {
1313
import { TooltipProvider } from "@vector-im/compound-web";
1414
import { initialize, mswLoader } from "msw-storybook-addon";
1515
import { useLayoutEffect } from "react";
16-
1716
import "../src/shared.css";
1817
import i18n, { setupI18n } from "../src/i18n";
19-
2018
import { DummyRouter } from "../src/test-utils/router";
2119
import { handlers } from "../tests/mocks/handlers";
2220
import localazyMetadata from "./locales";
21+
import swUrl from "./mockServiceWorker.js?url";
2322

2423
initialize(
2524
{
2625
onUnhandledRequest: "bypass",
26+
serviceWorker: {
27+
url: swUrl,
28+
},
2729
},
2830
handlers,
2931
);

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@
9292
"vitest": "^2.1.2"
9393
},
9494
"msw": {
95-
"workerDirectory": ["stories/static"]
95+
"workerDirectory": [".storybook"]
9696
}
9797
}

misc/build-docs.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,4 @@ mv target/doc target/book/rustdoc
5050
cd frontend
5151
npm ci
5252
npx storybook build -o ../target/book/storybook
53-
# Copy the mock service worker to the root of the domain, else it won't load
54-
cp ../target/book/storybook/mockServiceWorker.js ../target/book/mockServiceWorker.js
5553
cd ..

0 commit comments

Comments
 (0)