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

Add Official Support for Storybook 7.0 #192

Merged
merged 33 commits into from
Jul 6, 2023
Merged

Add Official Support for Storybook 7.0 #192

merged 33 commits into from
Jul 6, 2023

Conversation

thafryer
Copy link
Collaborator

@thafryer thafryer commented May 2, 2023

This PR adds official support for Storybook 7.0.

  1. All packages are updated to 7.0 versions
  2. Updated to use @storybook/preview-api and @storybook/manager-api

@socket-security
Copy link

socket-security bot commented May 2, 2023

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Issue Package Version Note Source
Bin script confusion @storybook/cli 7.0.24
  • Bin Script: sb
Shell access @storybook/cli 7.0.24
Bin script confusion storybook 7.0.24
  • Bin Script: sb
Install scripts esbuild 0.17.19
Shell access esbuild 0.17.19
New author supports-hyperlinks 2.3.0
New author @babel/plugin-syntax-import-meta 7.10.4
New author puppeteer-core 2.1.1
Shell access puppeteer-core 2.1.1
Uses eval puppeteer-core 2.1.1
New author html-minifier-terser 6.1.0
New author for-each 0.3.3
New author fb-watchman 2.0.2
New author defaults 1.0.4
New author anymatch 3.1.3
New author convert-source-map 2.0.0
New author assert 2.0.0
New author fd-slicer 1.1.0
New author signale 1.4.0
New author write-file-atomic 2.4.3
New author cosmiconfig 7.1.0
Shell access @auto-it/core 10.46.0
Shell access @auto-it/npm 10.46.0
Shell access @aw-web-design/x-default-browser 1.4.88
Shell access bottleneck 2.19.5
Uses eval bottleneck 2.19.5
Shell access envinfo 7.10.0
Uses eval envinfo 7.10.0
Shell access gitlog 4.0.8
Shell access jake 10.8.7
Shell access jscodeshift 0.14.0
Shell access requireg 0.2.2
Shell access shelljs 0.8.5
Shell access ts-node 10.9.1
Shell access update-browserslist-db 1.0.11
Uses eval @sinclair/typebox 0.25.24
Uses eval @storybook/manager 7.0.24
Uses eval @storybook/preview 7.0.24
Uses eval ajv 8.12.0
Uses eval ejs 3.1.9
Uses eval esbuild-register 3.4.2
Uses eval is-generator-function 1.0.10
  • Eval Type: Function
  • Location: index.js
Uses eval prettier 2.8.8
  • Eval Type: Function
  • Location: cli.js
Uses eval telejson 7.1.0
Uses eval uglify-js 3.17.4
Uses eval uvu 0.5.6
Uses eval @storybook/blocks 7.0.24
Uses eval await-to-js 3.0.0

Next steps

What is bin script confusion?

This package has multiple bin scripts with the same name. This can cause non-deterministic behavior when installing or could be a sign of a supply chain attack

Consider removing one of the conflicting packages. Packages should only export bin scripts with their name

What is shell access?

This module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.

Packages should avoid accessing the shell which can reduce portability, and make it easier for malicious shell access to be introduced.

What is an install script?

Install scripts are run when the package is installed. The majority of

@thafryer thafryer requested review from pocka, yannbf and shilman May 2, 2023 17:02
packages/storybook-addon-designs/package.json Outdated Show resolved Hide resolved
packages/examples/.storybook/main.js Outdated Show resolved Hide resolved
yannbf
yannbf previously requested changes May 10, 2023
Copy link
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I added a few comments

packages/storybook-addon-designs/package.json Outdated Show resolved Hide resolved
packages/storybook-addon-designs/package.json Outdated Show resolved Hide resolved
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/webpack-env": "^1.13.9",
"figma-js": "^1.13.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^4.7.3"
},
"peerDependencies": {
"@storybook/addon-docs": "^6.4.0 || ^7.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pocka is addon-docs as peerdep a requirement because of the docs block? could it be added as optional in peerDepspendenciesMeta?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { DocsContext } from "@storybook/addon-docs";
is the only line importing addon-docs so yes, it could be marked as optional (docs update is also needed probably)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 85 % sure that DocsContext can safely be imported from @storybook/blocks, making it possible to remove the dependency on @storybook/addon-docs completely.

Either way, I'm writing up a review here now that should make the usage of DocsContext entirely unneeded.

packages/storybook-addon-designs/package.json Outdated Show resolved Hide resolved
packages/examples/stories/docs/0.quickStart.mdx Outdated Show resolved Hide resolved
packages/examples/stories/docs/0.quickStart.mdx Outdated Show resolved Hide resolved
packages/examples/stories/docs/figspec/README.mdx Outdated Show resolved Hide resolved
@JReinhold
Copy link
Contributor

Storybook 7.0 introduces a slightly different API for using and building Doc Blocks, that I'd recommend you adopt here as well. Instead of taking in a storyId prop in the block, you would take in a reference to a story. The benefit of doing this, is that it would make it inline with the built-in doc blocks' API, and more crucially users don't have to manually keep their storyId props up to date when they change story names/titles or structures:

import * as ButtonStories from './Button.stories';
import { Design } from 'storybook-addon-designs/blocks';

<Design of={ButtonStories.Primary} />

This is the relevant code:

export interface DesignProps {
/**
* An ID of the story that has `design` parameter to use for rendering.
*/
storyId: string;
}
export const Design: FC<DesignProps & Omit<BlocksCommonProps, "showLink">> = ({
storyId,
placeholder,
...rest
}) => {
// Storybook ~v6.3 / v6.4~ is incompatible due to differences of this context value shape.
// Because of this, this addon needs Storybook v6.4 at minimum.
const { storyById } = useContext(DocsContext);
const story = storyById(storyId);
return (
<DocBlockBase placeholder={placeholder ?? "Design"} {...rest}>
<AbsoluteLocater>
<WrapperInternal config={story.parameters[ParameterName]} />
</AbsoluteLocater>
</DocBlockBase>
);
};

I would change it to something like this (haven't tested it, GitHub comments is my IDE 😎):

import { useOf, Of } from '@storybook/blocks';

...

export interface DesignProps {
  /**
   * Specify which story to get the Figma spec from.
   * If not specified, the primary story will be used in attached docs
   */
  of?: Of;
}

export const Design: FC<DesignProps & Omit<BlocksCommonProps, "showLink">> = (props) => {
  const {
    of,
    placeholder,
    ...rest
  } = props;

  const { story } = useOf(of || 'story', ['story']);

  if ('of' in props && of === undefined) {
    // MDX isn't always type-safe, it's often that users mistype their imports
    throw new Error('Unexpected `of={undefined}`, did you mistype a CSF file reference?');
  }
  
  return (
    <DocBlockBase placeholder={placeholder ?? "Design"} {...rest}>
      <AbsoluteLocater>
        <WrapperInternal config={story.parameters[ParameterName]} />
      </AbsoluteLocater>
    </DocBlockBase>
  );
};

My suggestion here would be a breaking change, but it should also be doable to do in a non-breaking way, deprecating but still supporting storyId. Let me know if you want to pair on any of this @thafryer .

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for updating this @thafryer !! 🙏

Lots of minor comments, but the important ones are from @yannbf @JReinhold

packages/examples/package.json Outdated Show resolved Hide resolved
packages/examples/stories/docs/0.quickStart.mdx Outdated Show resolved Hide resolved
packages/examples/stories/docs/0.quickStart.mdx Outdated Show resolved Hide resolved
packages/examples/stories/docs/0.quickStart.mdx Outdated Show resolved Hide resolved
packages/examples/stories/docs/0.quickStart.mdx Outdated Show resolved Hide resolved
packages/examples/stories/docs/0.quickStart.mdx Outdated Show resolved Hide resolved
packages/examples/stories/docs/0.quickStart.mdx Outdated Show resolved Hide resolved
packages/examples/stories/docs/0.quickStart.mdx Outdated Show resolved Hide resolved
packages/examples/stories/docs/advanced/docs.mdx Outdated Show resolved Hide resolved
packages/storybook-addon-designs/src/index.ts Outdated Show resolved Hide resolved
@socket-security
Copy link

socket-security bot commented Jun 30, 2023

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
storybook 7.0.24 None +311 84.9 MB shilman
@storybook/addon-mdx-gfm 7.0.26 eval, filesystem +68 2.66 MB shilman
@storybook/blocks 7.0.24 eval, shell +72 32.8 MB shilman
@storybook/react-webpack5 7.0.24 None +167 107 MB shilman
@storybook/mdx1-csf 1.0.0 shell +38 15.3 MB shilman
auto 10.46.0 eval +128 88.5 MB alisowski
typescript 4.7.3...4.9.5 None +0/-0 66.8 MB typescript-bot
@storybook/addon-docs 6.5.9...7.0.24 None +252/-912 101 MB shilman
@storybook/addons 6.5.9...7.0.24 None +36/-52 23.8 MB shilman
@figspec/react 1.0.1...1.0.3 None +6/-6 3.06 MB pocka
@babel/preset-typescript 7.17.12...7.22.5 None +44/-41 10.5 MB nicolo-ribaudo
@babel/preset-react 7.17.12...7.22.5 None +40/-40 10.1 MB nicolo-ribaudo
@storybook/react 6.5.9...7.0.24 None +72/-642 31.2 MB shilman
@babel/core 7.18.5...7.22.5 None +32/-32 9.97 MB nicolo-ribaudo
@babel/preset-env 7.18.2...7.22.5 None +116/-112 14.1 MB nicolo-ribaudo
@storybook/addon-actions 6.5.9...7.0.24 None +22/-35 12.6 MB shilman
figma-js 1.15.0...1.16.0 None +1/-1 150 kB chrisdrackett
@storybook/addon-storysource 6.5.9...7.0.24 None +23/-33 25.6 MB shilman
prettier 2.7.0...2.8.8 eval +0/-0 11.2 MB prettier-bot
@storybook/addon-links 6.5.9...7.0.24 None +18/-27 11.9 MB shilman

🚮 Removed packages: @storybook/api@6.5.9, @storybook/client-api@6.5.9, @storybook/components@6.5.9, @storybook/core-events@6.5.9, @storybook/theming@6.5.9, examples@0.1.0, react@16.14.0, react-dom@16.14.0, storybook-addon-designs@6.3.1

@ShaunEvening ShaunEvening marked this pull request as ready for review June 30, 2023 16:17
Copy link
Collaborator

@pocka pocka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment about a legacy(?) API. Other than that, LGTM.

packages/examples/.storybook/preview.js Outdated Show resolved Hide resolved
@thafryer thafryer dismissed yannbf’s stale review July 6, 2023 16:32

Comments are resolved and we are ready to merge.

@thafryer thafryer merged commit 8b31b4f into master Jul 6, 2023
2 of 3 checks passed
@thafryer thafryer deleted the support-7.0 branch July 6, 2023 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants