Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StorySource - Source not loading, tab stuck with "loading source..." #6111

Closed
fgaleano opened this issue Mar 15, 2019 · 4 comments
Closed

StorySource - Source not loading, tab stuck with "loading source..." #6111

fgaleano opened this issue Mar 15, 2019 · 4 comments

Comments

@fgaleano
Copy link

Bug or support request summary

"Story" tab only reads: "loading source..." for any and all stories. I looked at all the comments in issue #3626 and none of that made any difference.

I suspect the issue may be related to the fact we have a central location for adding stories instead of adding each at a time on their own file. See config.js file below for the exact code. Is this maybe not supported by StorySource?

Please specify which version of Storybook and optionally any affected addons that you're running

  • @storybook/addon-actions: "^5.0.1",
  • @storybook/addon-knobs: "^5.0.1",
  • @storybook/addon-storysource: "^5.0.1",
  • @storybook/react: "^5.0.1",

Affected platforms

Issue happens in both Firefox/Chrome in macOS. Don't think it's browser or even platform related. More like configuration.

Code Snippets

config.js

import "./styles.css";
import React from "react";
import path from "path";
import { configure } from "@storybook/react";
import { getStorybook, storiesOf } from "@storybook/react";
import { withKnobs } from "@storybook/addon-knobs";

let getComponentName = filePath =>
  path
    .dirname(filePath)
    .split(path.sep)
    .reverse()[0];

let getPackageName = filePath =>
  path
    .dirname(filePath)
    .split(path.sep)
    .reverse()[1];

configure(() => {
  // Automatically import all examples
  const req = require.context(
    "../packages",
    true,
    /^((?!node_modules).)*\.example\.js$/
  );

  req.keys().forEach(pathToExample => {
    const { name, Example } = req(pathToExample);
    const componentName = `${getPackageName(pathToExample)}.${getComponentName(
      pathToExample
    )}`;
    storiesOf(componentName, module)
      .addDecorator(withKnobs)
      .add(name, () => <Example />);
  });
}, module);

export { getStorybook };

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.example.js?$/,
        loaders: [require.resolve("@storybook/addon-storysource/loader")],
        enforce: "pre"
      }
    ]
  }
};

Individual story file button.example.js

import React from "react";
import { Button } from ".";
import { action } from "@storybook/addon-actions";

export let name = "Default";

export let Example = () => {
  return (
    <div>
            <Button onClick={action("clicked")} size={Button.SIZE.SMALL}>
              Default
            </Button>
    </div>
  );
};
@shilman
Copy link
Member

shilman commented Mar 16, 2019

Good golly!! I just released https://github.com/storybooks/storybook/releases/tag/v5.1.0-alpha.7 containing PR #6104 that references this issue. Upgrade today to try it out!

Because it's a pre-release you can find it on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Mar 16, 2019
@raulfdm
Copy link

raulfdm commented Mar 17, 2019

@shilman Is it'll be fixed for v5.0.x?

I'm having the same issue even after update to v5.0.2 🤔

@raulfdm
Copy link

raulfdm commented Mar 17, 2019

nvm, my config was wrong.

module.exports = function({ config }) {
  config.module.rules.push({
-  test: /\.stories.jsx?$/,
+  test: /\.story.jsx?$/,
    loaders: [require.resolve('@storybook/addon-storysource/loader')],
    enforce: 'pre',
  });

  return config;
};

@balovbohdan
Copy link

I faced the same issue with storybook 6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants