question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSF referenced in MDX does not work the expected way in Docs mode

See original GitHub issue

Describe the bug

When viewing a CSF that is imported in MDX by the use of <Story id="yourID" />, a strange Docs view is shown when clicking on the CSF story in the Storybook UI.

To Reproduce Steps to reproduce the behavior:

  1. Create an .mdx (using @open-wc/demoing-storybook + es-dev-server but this is essentially just re-exports made to work without a build/compile step, don’t worry about them, you can import from @storybook/docs-addon/blocks directly with your own preferred way e.g. using webpack):
import { Meta, Story, html } from '@open-wc/demoing-storybook';

<Meta title="Bug Repro" />

# Bug Repro

Hello there, this is a bug reproduction.

Sup..

<Story name="Default">
  {html`
    <div>Sup Planet</div>
  `}
</Story>

Some text

<Story id="bug-repro--hello-world" />

And then create a demo.stories.js with CSF:

export default {
  title: 'Bug Repro',
};

export const helloWorld = () => {
  const myNode = document.createElement('div');
  myNode.innerHTML = 'Hello, World!';
  myNode.style.color = 'red';
  return myNode;
};

Start storybook, and click on “default” and go into docs mode (not canvas). Everything looks great!

Screenshot 2020-01-09 at 11 49 48

Now click on “Hello World” and note that you get a very weird docs view, while the expectation is to get the exact same view (it should only scroll down to the hello world story, which is already in view):

Screenshot 2020-01-09 at 11 49 56

The only thing visible are the two Story’s and suddenly they are wrapped in Preview which we never specified. And all of the markdown text is missing now…?

Expected behavior Precisely the same view in docs mode when clicking the MDX story as when clicking the CSF story.

System:

System:
    OS: macOS Mojave 10.14.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 13.3.0 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.10.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 79.0.3945.88
    Safari: 13.0.4
  npmPackages:
    @storybook/addon-a11y: ~5.0.0 => 5.0.11 

Further Thoughts

It seems to me like CSF imported in MDX e.g. by use of just reference <Story id="someID"/> kind of “works” as a soft reference. E.g. clicking the Story reference in the Storybook sidebar normally will scroll you to the right place in docs mode, but if your Story originates from an external CSF, this feature does not work.

Is the CSF considered its own thing even if referenced in the MDX? This may explain why suddenly there’s a <Preview> element with code snippet wrapped around it, because it only looks at the CSF file… where a preview element is default? Let me know if I’m thinking in the right direction.

And perhaps someone can tell me if there’s another way to import CSF into MDX in a “hard” way, so that it’s actually part of the MDX, I assume that will make it work as expected

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jorenbroekemacommented, Jan 10, 2020

Ahhh that makes sense, so not a bug then, thanks for pointing me to those docs, currently we have to use external CSF imported inside the MDX because dynamic imports don’t work in MDX (MDX-to-JS issue).

I don’t have the time to try this, I’m off on vacation for the next week so feel free to close it, I trust both of those documented ways will resolve my issue 😉.

0reactions
stale[bot]commented, Mar 12, 2020

Hey there, it’s me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

Read more comments on GitHub >

github_iconTop Results From Across the Web

MicroStrategy MDX Cube Reporting Guide
Each report can only reference one specific MDX cube, due to the structure in MDX cube sources where queries can only be run...
Read more >
Vehicle Technology Assessment, Model Development, and ...
Government does not endorse products or manufacturers. ... Like most hybrid vehicles, the 2019 Acura MDX has two distinct working voltages. The high-....
Read more >
Setup CSF + MDX stories with @storybook/addon-docs - GitLab
Component Story Format (CSF) is a new way to write stories that drops ... It apparently doesn't work in MDX yet, but it's...
Read more >
100DaysOfGatsby - Paul Scanlon
Today i've been building out a customers reviews section, nothing new here, just more Formik and using Theme UI to style stuff. Tomorrow...
Read more >
MDX Docs doesn't display after upgrades to React ... - Issuehunt
When running npm run storybook , it loads to the browser and Docs do not load. ... node_modules/@storybook/mdx2-csf/loader.js): Expected a closing tag for ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found