Skip to content

Commit

Permalink
Fix Service Worker in GH Pages (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessbell authored Jun 14, 2024
1 parent 5832785 commit c0eb0ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import graphqlLoader from "vite-plugin-graphql-loader";

const config: StorybookConfig = {
stories: ["./**/*.mdx", "./**/*.stories.@(js|jsx|mjs|ts|tsx)"],
staticDirs: ["../public"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
Expand Down
25 changes: 13 additions & 12 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import type { Preview } from "@storybook/react";
import { initialize, mswLoader, getWorker } from "msw-storybook-addon";
import "./stories/input.css";

let options = {};

if (location.hostname === "apollographql.github.io") {
options = {
serviceWorker: {
url: "/graphql-testing-library/mockServiceWorker.js",
},
};
}

// Initialize MSW
initialize(options);

const preview: Preview = {
// calling getWorker().start() is a workaround for an issue
// where Storybook doesn't wait for MSW before running:
Expand All @@ -17,16 +30,4 @@ const preview: Preview = {
},
};

let options = {};
if (location.hostname === "apollographql.github.io") {
options = {
serviceWorker: {
url: "/graphql-testing-library/mockServiceWorker.js",
},
};
}

// Initialize MSW
initialize(options);

export default preview;

0 comments on commit c0eb0ad

Please sign in to comment.