Skip to content

Commit

Permalink
Merge pull request #21832 from storybookjs/fix/polyfill-global
Browse files Browse the repository at this point in the history
Vite: Polyfill global by default
  • Loading branch information
yannbf authored Mar 30, 2023
2 parents acace30 + fabac28 commit 79b1fde
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 22 deletions.
1 change: 1 addition & 0 deletions code/addons/interactions/src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference types="node" />

import { addons } from '@storybook/preview-api';
import { global } from '@storybook/global';
import { FORCE_REMOUNT, STORY_RENDER_PHASE_CHANGED } from '@storybook/core-events';
import type {
Renderer,
Expand Down
1 change: 1 addition & 0 deletions code/lib/builder-vite/input/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// We do this so that "module && module.hot" etc. in Storybook source code
// doesn't fail (it will simply be disabled)
window.module = undefined;
window.global = window;
</script>
<!-- [HEAD HTML SNIPPET HERE] -->
</head>
Expand Down
22 changes: 0 additions & 22 deletions code/lib/cli/src/generators/baseGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,6 @@ export async function baseGenerator(

await configurePreview({ frameworkPreviewParts, storybookConfigFolder, language, rendererId });

// FIXME: temporary workaround for https://github.com/storybookjs/storybook/issues/17516
// Vite workaround regex for internal and external frameworks as f.e:
// Internal: @storybook/xxxxx-vite
// External: storybook-xxxxx-vite
if (
frameworkPackages.find(
(pkg) =>
pkg.match(/^(@storybook\/|storybook).*-vite$/) ||
pkg === '@storybook/sveltekit' ||
pkg === ''
)
) {
const previewHead = dedent`
<script>
window.global = window;
</script>
`;
await fse.writeFile(`${storybookConfigFolder}/preview-head.html`, previewHead, {
encoding: 'utf8',
});
}

const babelDependencies =
addBabel && builder !== CoreBuilder.Vite
? await getBabelDependencies(packageManager, packageJson)
Expand Down

0 comments on commit 79b1fde

Please sign in to comment.