This guide explains how to deploy your Storybook to GitHub Pages with cross-origin isolation support for SharedArrayBuffer.
This repository is configured to automatically deploy to GitHub Pages when you push to the main branch.
- A GitHub Actions workflow (
/.github/workflows/storybook.yml) triggers on push to main - The workflow builds Storybook and deploys it to GitHub Pages
- The service worker approach ensures cross-origin isolation even without server headers
You can also manually trigger a deployment from the GitHub Actions tab:
- Go to the repository on GitHub
- Click on the "Actions" tab
- Select the "Deploy Storybook to GitHub Pages" workflow
- Click "Run workflow"
After deployment, you can verify that cross-origin isolation is working by:
- Navigate to your GitHub Pages URL
- Append
/coi-check.htmlto the URL (e.g.,https://yourusername.github.io/your-repo/coi-check.html) - The diagnostic page will show if:
- Cross-origin isolation is enabled
- SharedArrayBuffer is available
- The service worker is registered correctly
To run Storybook locally:
npm run storybookTo build Storybook locally:
npm run build-storybookThis project uses a service worker approach for cross-origin isolation:
-
We register a service worker (
coi-serviceworker.js) that adds the required headers:Cross-Origin-Opener-Policy: same-originCross-Origin-Embedder-Policy: require-corp
-
The service worker intercepts navigation requests and adds these headers to responses
-
This ensures SharedArrayBuffer is available, which is required for some advanced features
If you encounter issues with cross-origin isolation:
- Check the browser console for service worker registration errors
- Verify your GitHub Pages site is properly configured
- Try the
/coi-check.htmldiagnostic page to identify specific issues - Make sure your browser supports service workers (most modern browsers do)
The repository has been configured with the following files to ensure proper cross-origin isolation:
.storybook/_headers- Contains COOP/COEP headers as a fallback.storybook/preview-head.html- Includes the service worker registration scriptpublic/coi-serviceworker.js- The service worker that enforces cross-origin isolationpublic/register-coi-sw.js- Script to register the service workerpublic/coi-check.html- Diagnostic page to verify cross-origin isolation
When hosting Storybook, you need cross-origin isolation for SharedArrayBuffer support. This implementation:
- GitHub Pages: Works with our service worker approach
- Netlify: Also works with our approach, with added support via
netlify.toml - Vercel: Supported via our service worker approach
- Azure Static Web Apps: Should work with our service worker approach
- This approach works without requiring server-side header configuration
- It's compatible with GitHub Pages and other static hosting providers
- The service worker approach is more reliable than relying on HTTP headers alone