Skip to content

Commit

Permalink
Merge pull request #21722 from storybookjs/tom/21649-change-excludeDe…
Browse files Browse the repository at this point in the history
…corators-true
  • Loading branch information
tmeasday committed Mar 28, 2023
2 parents fe8e646 + dbbcafc commit d5c8238
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
6 changes: 6 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
- [Dropped addon-docs manual configuration](#dropped-addon-docs-manual-configuration)
- [Autoplay in docs](#autoplay-in-docs)
- [Removed STORYBOOK_REACT_CLASSES global](#removed-storybook_react_classes-global)
- [parameters.docs.source.excludeDecorators defaults to true](#parametersdocssourceexcludedecorators-defaults-to-true)
- [7.0 Deprecations and default changes](#70-deprecations-and-default-changes)
- [storyStoreV7 enabled by default](#storystorev7-enabled-by-default)
- [`Story` type deprecated](#story-type-deprecated)
Expand Down Expand Up @@ -1425,6 +1426,11 @@ If your story depends on a play function to render correctly, _and_ you are conf

This was a legacy global variable from the early days of react docgen. If you were using this variable, you can instead use docgen information which is added directly to components using `.__docgenInfo`.

#### parameters.docs.source.excludeDecorators defaults to true

By default we don't render decorators in the Source/Canvas blocks. If you want to render decorators, you can set the parameter to `false`.


### 7.0 Deprecations and default changes

#### storyStoreV7 enabled by default
Expand Down
3 changes: 3 additions & 0 deletions code/addons/docs/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ export const parameters: any = {
const { DocsRenderer } = (await import('./DocsRenderer')) as any;
return new DocsRenderer();
},
source: {
excludeDecorators: true,
},
},
};
13 changes: 7 additions & 6 deletions code/renderers/html/src/docs/sourceDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ function skipSourceRender(context: StoryContext) {
}

export function sourceDecorator(storyFn: PartialStoryFn<HtmlRenderer>, context: StoryContext) {
const story = context?.parameters.docs?.source?.excludeDecorators
const story = storyFn();
const renderedForSource = context?.parameters.docs?.source?.excludeDecorators
? (context.originalStoryFn as StoryFn)(context.args, context)
: storyFn();
: story;

let source: string | undefined;
if (!skipSourceRender(context)) {
if (typeof story === 'string') {
source = story;
} else if (story instanceof Element) {
source = story.outerHTML;
if (typeof renderedForSource === 'string') {
source = renderedForSource;
} else if (renderedForSource instanceof Element) {
source = renderedForSource.outerHTML;
}
}
useEffect(() => {
Expand Down
7 changes: 4 additions & 3 deletions code/renderers/web-components/src/docs/sourceDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export function sourceDecorator(
storyFn: PartialStoryFn<WebComponentsRenderer>,
context: StoryContext<WebComponentsRenderer>
): WebComponentsRenderer['storyResult'] {
const story = context?.parameters.docs?.source?.excludeDecorators
const story = storyFn();
const renderedForSource = context?.parameters.docs?.source?.excludeDecorators
? (context.originalStoryFn as ArgsStoryFn<WebComponentsRenderer>)(context.args, context)
: storyFn();
: story;

let source: string;

Expand All @@ -39,7 +40,7 @@ export function sourceDecorator(
});
if (!skipSourceRender(context)) {
const container = window.document.createElement('div');
render(story, container);
render(renderedForSource, container);
source = container.innerHTML.replace(LIT_EXPRESSION_COMMENTS, '');
}

Expand Down

0 comments on commit d5c8238

Please sign in to comment.