Skip to content

Commit

Permalink
Merge branch 'next' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniebigodes authored Dec 14, 2023
2 parents d3b01f3 + 43af8b7 commit 523d280
Show file tree
Hide file tree
Showing 48 changed files with 937 additions and 436 deletions.
36 changes: 35 additions & 1 deletion code/renderers/react/src/docs/jsxDecorator.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
import type { FC, PropsWithChildren } from 'react';
import React, { createElement, Profiler } from 'react';
import React, { StrictMode, createElement, Profiler } from 'react';
import PropTypes from 'prop-types';
import { addons, useEffect } from '@storybook/preview-api';
import { SNIPPET_RENDERED } from '@storybook/docs-tools';
Expand Down Expand Up @@ -155,6 +155,40 @@ describe('renderJsx', () => {
`);
});

it('StrictMode', () => {
function StrictModeComponent(props: any) {
return (
<StrictMode>
<div>{props.children}</div>
</StrictMode>
);
}

expect(renderJsx(createElement(StrictModeComponent, {}, 'I am StrictMode'), {}))
.toMatchInlineSnapshot(`
<StrictModeComponent>
I am StrictMode
</StrictModeComponent>
`);
});

it('Suspense', () => {
function SuspenseComponent(props: any) {
return (
<React.Suspense fallback={null}>
<div>{props.children}</div>
</React.Suspense>
);
}

expect(renderJsx(createElement(SuspenseComponent, {}, 'I am Suspense'), {}))
.toMatchInlineSnapshot(`
<SuspenseComponent>
I am Suspense
</SuspenseComponent>
`);
});

it('should not add default props to string if the prop value has not changed', () => {
const Container = ({ className, children }: { className: string; children: string }) => {
return <div className={className}>{children}</div>;
Expand Down
38 changes: 20 additions & 18 deletions code/renderers/react/src/docs/jsxDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { logger } from '@storybook/client-logger';

import type { ReactRenderer } from '../types';

import { isMemo, isForwardRef } from './lib';

// Recursively remove "_owner" property from elements to avoid crash on docs page when passing components as an array prop (#17482)
// Note: It may be better to use this function only in development environment.
function simplifyNodeForStringify(node: ReactNode): ReactNode {
Expand Down Expand Up @@ -56,7 +54,7 @@ export const renderJsx = (code: React.ReactElement, options: JSXOptions) => {
const Type = renderedJSX.type;

// @ts-expect-error (Converted from ts-ignore)
for (let i = 0; i < options.skip; i += 1) {
for (let i = 0; i < options?.skip; i += 1) {
if (typeof renderedJSX === 'undefined') {
logger.warn('Cannot skip undefined element');
return null;
Expand All @@ -80,21 +78,25 @@ export const renderJsx = (code: React.ReactElement, options: JSXOptions) => {
}
}

const displayNameDefaults =
typeof options.displayName === 'string'
? { showFunctions: true, displayName: () => options.displayName }
: {
// To get exotic component names resolving properly
displayName: (el: any): string =>
el.type.displayName ||
(el.type === Symbol.for('react.profiler') ? 'Profiler' : null) ||
getDocgenSection(el.type, 'displayName') ||
(el.type.name !== '_default' ? el.type.name : null) ||
(typeof el.type === 'function' ? 'No Display Name' : null) ||
(isForwardRef(el.type) ? el.type.render.name : null) ||
(isMemo(el.type) ? el.type.type.name : null) ||
el.type,
};
let displayNameDefaults;

if (typeof options?.displayName === 'string') {
displayNameDefaults = { showFunctions: true, displayName: () => options.displayName };
/**
* add `renderedJSX?.type`to handle this case:
*
* https://github.com/zhyd1997/storybook/blob/20863a75ba4026d7eba6b288991a2cf091d4dfff/code/renderers/react/template/stories/errors.stories.tsx#L14
*
* or it show the error message when run `yarn build-storybook --quiet`:
*
* Cannot read properties of undefined (reading '__docgenInfo').
*/
} else if (renderedJSX?.type && getDocgenSection(renderedJSX.type, 'displayName')) {
displayNameDefaults = {
// To get exotic component names resolving properly
displayName: (el: any): string => getDocgenSection(el.type, 'displayName'),
};
}

const filterDefaults = {
filterProps: (value: any, key: string): boolean => value !== undefined,
Expand Down
102 changes: 100 additions & 2 deletions docs/configure/frameworks-feature-support.md

Large diffs are not rendered by default.

68 changes: 0 additions & 68 deletions docs/essentials/auto-generated-controls/angular.mdx

This file was deleted.

29 changes: 0 additions & 29 deletions docs/essentials/auto-generated-controls/ember.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/essentials/auto-generated-controls/fallback.mdx

This file was deleted.

14 changes: 0 additions & 14 deletions docs/essentials/auto-generated-controls/react.mdx

This file was deleted.

11 changes: 0 additions & 11 deletions docs/essentials/auto-generated-controls/vue.mdx

This file was deleted.

20 changes: 0 additions & 20 deletions docs/essentials/auto-generated-controls/web-components.mdx

This file was deleted.

Loading

0 comments on commit 523d280

Please sign in to comment.