-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Docs tab shows 'no code available' when using CSF format #8104
Comments
Can you share your preset and config files? |
|
I have very similar situation but with typescript configuration. Everything is working fine except code part. I'm not using presets. My stories are placed in My webpack.config.js:
|
facing the same issue |
I do have the same issue using typescript preset, ended up in moving to write in MDX |
I've found bug in my config. I changed
EDIT: source-loader shouldn't be set for something else than stories. In my case regexp wasn't matching stories files. |
@mattwaler sorry for the slow reply. this line from your preset is disabling the source loader, so there's no code to show:
|
@goszczynskip i don't think so. source-loader is about loading the source for stories only. if you set it to load the source for your components it will slow down your builds etc. i suspect there's some other problem with your setup. |
@shilman You are right. There was other problem. I've just used regexp with starting dot but my stories are like: My working configuration with Typescript, MDX and sources. Maybe someone wants to copy it.
|
thx. this works for me. |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Same problem here. We use a custom Webpack config for TypeScript support in stories.
|
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Still got no code available while using CSF format (Docs mode). But, when I switched to Canvas mode, the story source existed. webpack.config.js // Core(s)
const path = require('path');
const createMDXCompiler = require('@storybook/addon-docs/mdx-compiler-plugin');
// Summary
module.exports = async ({ config }) => {
config.module.rules.push(
{
test: /\.stories\.mdx$/,
use: [
{
loader: 'babel-loader',
// May or may not need this line depending on your app's setup
options: {
plugins: ['@babel/plugin-transform-react-jsx']
}
},
{
loader: '@mdx-js/loader',
options: {
compilers: [createMDXCompiler({})]
}
}
]
},
{
test: /\.stories\.tsx?$/,
use: [
{
loader: require.resolve('@storybook/source-loader'),
options: {
parser: 'typescript',
prettierConfig: {
arrowParens: 'avoid',
printWidth: 80,
tabWidth: 2,
bracketSpacing: true,
trailingComma: 'none',
singleQuote: true,
semi: true,
jsxBracketSameLine: false
}
}
}
],
enforce: 'pre',
include: path.resolve(__dirname, '../src')
},
{
test: /\.tsx?$/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: [
[
require.resolve('babel-preset-react-app'),
{ flow: false, typescript: true }
]
]
}
},
require.resolve('react-docgen-typescript-loader')
]
},
{
test: /\.s[ac]ss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../')
}
);
config.resolve.extensions.push('.ts', '.tsx');
return config;
}; button.tsx import React, { ReactNode, FunctionComponentElement } from 'react';
export type Props = {
/**
* Children
*/
children?: ReactNode;
};
export function Button({ children }: Props): FunctionComponentElement<Props> {
return <button type="button">{children}</button>;
}
export default Button; button.stories.tsx import React, { FunctionComponent } from 'react';
import { text } from '@storybook/addon-knobs';
import { Button } from './button';
export default { title: 'Genesis|Button', component: Button };
export const withText: FunctionComponent = () => <Button>Hello Button</Button>;
export const withEmoji: FunctionComponent = () => (
<Button>
<span role="img" aria-label="so cool">
😀 😎 👍 💯
</span>
</Button>
);
export const withKnobs: FunctionComponent = () => (
<Button>{text('children', 'Test Children')}</Button>
); 🙇♂️ |
@jeffryang24 your webpack config adds source-loader, but addon-docs also adds source-loader. I'd suggest removing yours, or disabling the one in addon-docs per https://github.com/storybookjs/storybook/blob/next/addons/docs/README.md#preset-options |
I see... Will try to disable one of them. Will report the result back, probably this night (GMT+7)... 🙇♂️ |
I have a running storybook installation as per instructions here: https://gist.github.com/shilman/bc9cbedb2a7efb5ec6710337cbd20c0c Currently I also see no code preview in the stories when using CSF - it only works properly when using MDX instead. |
@patrick-radulian I have updated the gist, specifically this part, to reflect recent changes in {
name: "@storybook/addon-docs/preset",
options: {
configureJSX: true,
}
} I also tested it with a clean setup & verified that it's working |
Hmm... Actually, I don't use the default preset, |
Here's my full config: https://gist.github.com/jeffryang24/2147d8dbed6189ba6cc9a022ec79ac11 🙇♂️. Still got no luck... Oh, yes. My project is a monorepo and has only one tsconfig.json in the root dir.... Does it cause this issue? |
cc: @shilman |
Renaming the story files is necessary to conform with internal regex for selecting files from which the story is extracted[1][2]. [1]: storybookjs/storybook#8104 (comment) [2]: https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/docspage.md#story-file-names Overwriting `extractComponentDescription` seems to be the only way to add back a description into the stories file itself that does not live in the component. Change-Id: Ia50d560ad5215e089db938dcfc060f740419118a
In my project I am overriding the default storybook webpack config with my own custom webpack config. This meant that any of the default module.rules from storybook webpack config were not being applied. Due to this the source-loader rule was also not being applied, and DocsPage was showing 'No code available' . I re-added the source-loader rule and it works fine. |
ran into the same issue like @Vanuan on v6.0.21. It works if the storyname includes the name of the component. However, our folder structure is like this:
I am no webpack expert, could someone point me into a direction how to fix this without changing folder structure? 😃 EDIT: config.module.rules.push({
test: /(.*\.)?stories\.js$/,
loaders: [ '@storybook/source-loader' ],
}); |
@andre-brdoch Maybe try changing Or, if you're willing to contribute, change this line:
To the following:
|
but that would match, for example, Assuming this tests a path and not a filename alone:
|
Add the following to // /.storybook/webpack.config.js
module.exports = ({ config }) => {
config.module.rules.push({
test: /(\/|\.)(stories|story)\.[tj]sx?$/,
use: '@storybook/source-loader',
})
return config
} |
@pwfisher Good catch! |
I'm finding that if I have a story as follows: export const Start: Story = () => (
<Button start>
Save and continue
</Button>
); Then I get "No code available". But if I add an unused export const Start: Story = (args) => (
<Button start>
Save and continue
</Button>
); Then "Show code" is displayed. Not sure if this is a bug or a feature @shilman ? 😀 |
@penx it's a feature. you can read more about it here: https://storybook.js.org/docs/react/writing-docs/doc-blocks#docspage-1 dynamic snippet rendering was introduced at the last minute in storybook 6.0 to fix a broken user experience for args stories, which were introduced in 6.0. however, because the feature was immature, i didn't want to break the experience for existing 5.x users writing no-args stories. now that dynamic snippets are fairly stable, we can probably make them the default and users can opt-in to source snippets when they need them. i'll consider this seriously as part of the 7.0 release. |
* chore: add some storybook https://redwoodjs.com/docs/tutorial/chapter5/first-story * fix: enable show code button storybookjs/storybook#8104 (comment) * fix: better layout * chore: make boilerplate stories TODO have framework generate these * fix: account for missing id on netlify > Error: Variable "$id" of required type "Int!" was not provided. * chore: fixup some tests https://redwoodjs.com/docs/tutorial/chapter5/first-test * chore: add `Comment` yarn rw g component Comment https://redwoodjs.com/docs/tutorial/chapter6/the-redwood-way * chore: add some boilerplate * chore(Comment): improve and wire up some mock data https://redwoodjs.com/docs/tutorial/chapter6/the-redwood-way#storybook * chore: add styling * chore: add CommentsCell https://redwoodjs.com/docs/tutorial/chapter6/multiple-comments * chore: add some boilerplate * chore: add better mocks * chore: update CommentsCell * chore: add a bit more styling * chore: add comments TODO figure out loading part of this * chore: fix * chore: add Comments to the schema https://redwoodjs.com/docs/tutorial/chapter6/comments-schema * chore(prisma): generate Comment table migration * chore(prisma): generate Comment table migration * chore(ide): add recommended extension * chore: remove unused routes in main app * Revert "chore: remove unused routes in main app" This reverts commit 53637f8. * chore: disable contact/login forms not used * chore: remove unused import * test(unit): add example async test * test(unit): default summary to true * chore: update empty comments cell https://redwoodjs.com/docs/tutorial/chapter6/comments-schema * chore(comments): allow/create https://redwoodjs.com/docs/tutorial/chapter6/comments-schema * chore(commentForm): run generator `yarn rw g component CommentForm` https://redwoodjs.com/docs/tutorial/chapter6/comment-form * chore(commentForm): add some boilerplate * chore(commentForm): simple form * chore(commentForm): add submit * chore(storybook): wire up mockGraphQLMutation * chore(storybook): add interaction test https://stackoverflow.com/a/63745654 * chore: fixup style * test(unit): better test * test: add loading snapshot * chore(commentForm): use form https://redwoodjs.com/docs/tutorial/chapter6/comment-form#adding-the-form-to-the-blog-post * chore(commentForm): wire up correctly in Article * chore(contactForm): refetch comments after create https://redwoodjs.com/docs/tutorial/chapter6/comment-form#graphql-query-caching * chore: add toast feedback for form https://redwoodjs.com/docs/tutorial/chapter6/comment-form#graphql-query-caching * chore: wire up comments to posts correctly * chore: fixup prod/dev routes * chore: get comment by post * chore(rbac): add roles to user https://redwoodjs.com/docs/tutorial/chapter7/rbac * chore(rbac): gate admin page * chore(rbac): add seed script * chore: add default route for /admin * chore(rbac): add delete button also wire up test/story https://redwoodjs.com/docs/tutorial/chapter7/rbac#mocking-currentuser-for-jest * chore: gate delete call * chore: allow admin to delete as well * chore(rbac): wire up delete gating * test(unit): simplify * fix(storybook): add explicit imports for Netlify * build(🧶): add reslutions for `@storybook/*` transitive dependencies of redwood
@shilman I found another scenario where it does not show code. When using a custom DocsContainer: import { DocsContainer } from '@storybook/addon-docs';
export const parameters = {
docs: {
container: (props) => <DocsContainer {...props} />,
},
}; Seems like a bug? |
* fix(storybook): add `args` to auto generate docs see: - storybookjs/storybook#8104 (comment) - https://storybook.js.org/docs/react/writing-docs/doc-block-source * test(unit): update snapshots ```sh yarn workspace @redwoodjs/cli run test -u ``` see: #5979 (comment)
* fix(storybook): add `args` to auto generate docs see: - storybookjs/storybook#8104 (comment) - https://storybook.js.org/docs/react/writing-docs/doc-block-source * test(unit): update snapshots ```sh yarn workspace @redwoodjs/cli run test -u ``` see: redwoodjs/redwood#5979 (comment)
Is there a solution to this, I'm facing this same senerio |
Describe the bug
When composing a story using new CSF format, all stories show
no code available
.To Reproduce
Steps to reproduce the behavior:
Expected behavior
Like in the screenshots and docs, code previews should be available to view and copy.
Screenshots
System:
The text was updated successfully, but these errors were encountered: