`preview-body.html` not working as expected (?)
See original GitHub issueHi, thanks for taking the time to look into this.
Describe the bug
The rendered content is not being appended in the preview-body.html
file as the documentation suggests:
https://storybook.js.org/docs/configurations/add-custom-body/
To Reproduce
Add a preview-body.html
file inside the .storybook
config folder as suggested in the docs, containing a single custom <div id="custom-root"></div>
div wrapper.
Expected behavior
I would expect this element to be the root of the rendered content, unless I’m missing something. Instead, the usual #root
div container is used.
Screenshots
As shown in the screenshot, an extra div is added to the content, but this div is empty and is not serving the purpose of being the root for the rendered content.

System:
Environment Info:
System:
OS: macOS Mojave 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
Node: 12.7.0 - ~/.nvm/versions/node/v12.7.0/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.10.0 - ~/.nvm/versions/node/v12.7.0/bin/npm
Browsers:
Chrome: 80.0.3987.163
Firefox: 74.0.1
Safari: 13.1
npmPackages:
@storybook/react: ^5.0.6 => 5.2.8
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:24 (14 by maintainers)
Top Results From Across the Web
Why is my HTML file not displaying to the browser?
Possible Reasons: · You might not have saved the changes after writing the code (most likely). · Problem with the browser (load it...
Read more >Handling common HTML and CSS problems - MDN Web Docs
Basically, it is a matter of checking whether your HTML and CSS code is well formed and doesn't contain any syntax errors. Note:...
Read more >iFrame not working as expected - CSS-Tricks
I need to add an element that allows the content of the generated HTML page to encapsulate the written content of the story...
Read more >Story rendering - Storybook
Storybook will inject these tags into the preview iframe where your components render, not the Storybook application UI. Similarly to the preview head...
Read more >Outlook HTML Emails: How to Fix 11 Common Rendering Issues
Get advice for troubleshooting Outlook issues. ... the biggest blockers standing in the way of email campaigns that render as expected.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s extremely surprising that using the documented
custom root
file just injects that into the DOM and continues to use an unaltereddiv#root
.I expected that the custom root would be used instead, so that I can put the custom classes I need on that root.
I had no issue with the
div#root
itself, but I needed to wrap my Stories into a specific div with a class (eg.class="v-app"
). I expected that thepreview-body.html
will help solving this, but as already mentioned by others, its not.Workaround
The way @IuliiaBondarieva mentioned here would also work, I did this temporary for me:
Final Solution: Global decorators
Documentation Finally I found out that its probably the cleanest way to simply solve it with a “global decorator”:
This solves my problem. It took me some time to understand this, so maybe it helps someone else too:
Maybe it would be good to make this more clear in the documentation?!