Skip to content

Commit

Permalink
Avoid hiding all non-storybook body children (#346)
Browse files Browse the repository at this point in the history
Fixes #343

This replaces the blunt hammer of 

```css
body > * {
  display: none !important;
}
```

with something a bit more nuanced, taken from the storybook default head styles.  

This is only necessary until vitejs/vite#7786 is released, then we can remove the workaround and ask users to update vite in order to avoid this flash.
  • Loading branch information
IanVS committed Apr 22, 2022
1 parent 1651135 commit 0491c33
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/builder-vite/plugins/no-fouc.ts
Expand Up @@ -21,22 +21,27 @@ export function noFouc(): Plugin {
};
}

/**
* Insert default styles to hide storybook elements as the page loads until JS can
* add the official storybook default head styles and scripts. These lines are mostly
* taken from https://github.com/storybookjs/storybook/blob/next/lib/core-common/templates/base-preview-head.html#L6-L20
*/
function insertHeadStyles(html: string) {
return html.replace(
'</head>',
`
<style>
/* Fix for elements flashing */
body > * {
display: none !important;
.sb-show-preparing-story:not(.sb-show-main) > :not(.sb-preparing-story) {
display: none;
}
.sb-show-preparing-docs:not(.sb-show-main) > :not(.sb-preparing-docs) {
display: none;
}
.sb-show-preparing-story > .sb-preparing-story,
.sb-show-preparing-docs > .sb-preparing-docs,
.sb-show-nopreview > .sb-nopreview,
.sb-show-errordisplay > .sb-errordisplay,
.sb-show-main > #root,
.sb-show-main > #docs-root {
display: block !important;
:not(.sb-show-preparing-story) > .sb-preparing-story,
:not(.sb-show-preparing-docs) > .sb-preparing-docs,
:not(.sb-show-nopreview) > .sb-nopreview,
:not(.sb-show-errordisplay) > .sb-errordisplay {
display: none;
}
#root[hidden],
#docs-root[hidden] {
Expand Down

0 comments on commit 0491c33

Please sign in to comment.