-
-
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
Add default export as function annotation from core addons #30376
Add default export as function annotation from core addons #30376
Conversation
View your CI Pipeline Execution ↗ for commit 5b68c6a.
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
31 file(s) reviewed, 11 comment(s)
Edit PR Review Bot Settings | Greptile
|
||
import * as addonAnnotations from './preview'; | ||
|
||
export default () => definePreview(addonAnnotations); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider adding a type annotation for the return value to ensure type safety
export { PARAM_KEY } from './constants'; | ||
|
||
export default () => definePreview({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: empty object passed to definePreview() suggests this addon has no preview annotations, which seems incorrect for a controls addon that likely needs to register parameters or decorators
@@ -1 +1,5 @@ | |||
import { definePreview } from 'storybook/internal/preview-api'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: consider using the full path '@storybook/internal/preview-api' instead of 'storybook/internal/preview-api' for consistency with other imports in the codebase
// perhaps csf types need to be updated? StepRunner expects Promise<void> and not Promise<void> | void | ||
).step as StepRunner; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The type assertion may hide a real type mismatch between StepRunner and the instrumented step function. Consider fixing the underlying type definitions instead of using a type assertion.
import { PARAM_KEY } from './constants'; | ||
import { withMeasure } from './withMeasure'; | ||
|
||
export const decorators: Addon_DecoratorFunction[] = [withMeasure]; | ||
export const decorators = [withMeasure]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Removing the explicit Addon_DecoratorFunction type could make it harder to catch type errors if withMeasure's type signature changes in the future
export * from './defaults'; | ||
export type * from './types'; | ||
|
||
export default () => definePreview(addonAnnotations); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider adding a return type annotation to the default export function for better type safety
if (!data.isCoreAddon) { | ||
data.importPath = `@storybook/${addon}/preview`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Non-core addon path assumes @storybook namespace which may not always be true. Consider using the original addon string instead of hardcoding the namespace.
(getAddonAnnotations as Mock).mockImplementation(() => { | ||
return { | ||
importName: 'addonA11yAnnotations', | ||
importPath: '@storybook/addon-a11y', | ||
isCoreAddon: true, | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: the mock implementation returns a different importPath compared to the first test case ('@storybook/addon-a11y' vs '@storybook/addon-a11y/preview'). Consider adding a test case that verifies the behavior when both paths are used in the same preview config
|
||
import { PARAM_KEY } from './constants'; | ||
import { addOutlineStyles, clearStyles } from './helpers'; | ||
import outlineCSS from './outlineCSS'; | ||
|
||
export const withOutline = (StoryFn: StoryFunction<Renderer>, context: StoryContext<Renderer>) => { | ||
export const withOutline: DecoratorFunction = (StoryFn, context) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The DecoratorFunction
type should be properly constrained with a Renderer type parameter to maintain type safety
|
||
import { PARAM_KEY } from './constants'; | ||
import { addOutlineStyles, clearStyles } from './helpers'; | ||
import outlineCSS from './outlineCSS'; | ||
|
||
export const withOutline = (StoryFn: StoryFunction<Renderer>, context: StoryContext<Renderer>) => { | ||
export const withOutline: DecoratorFunction = (StoryFn, context) => { | ||
const { globals } = context; | ||
const isActive = [true, 'true'].includes(globals[PARAM_KEY]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using Boolean()
instead of array includes for cleaner type coercion
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
Before | After | Difference | |
---|---|---|---|
Dependency count | 59 | 59 | 0 |
Self size | 228 KB | 234 KB | 🚨 +6 KB 🚨 |
Dependency size | 13.46 MB | 13.45 MB | 🎉 -11 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/addon-backgrounds
Before | After | Difference | |
---|---|---|---|
Dependency count | 4 | 4 | 0 |
Self size | 27 KB | 44 KB | 🚨 +17 KB 🚨 |
Dependency size | 99 KB | 99 KB | 0 B |
Bundle Size Analyzer | Link | Link |
@storybook/addon-docs
Before | After | Difference | |
---|---|---|---|
Dependency count | 17 | 17 | 0 |
Self size | 2.20 MB | 2.20 MB | 🚨 +2 KB 🚨 |
Dependency size | 7.91 MB | 7.90 MB | 🎉 -13 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/addon-essentials
Before | After | Difference | |
---|---|---|---|
Dependency count | 36 | 36 | 0 |
Self size | 15 KB | 18 KB | 🚨 +3 KB 🚨 |
Dependency size | 13.87 MB | 13.93 MB | 🚨 +60 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/addon-highlight
Before | After | Difference | |
---|---|---|---|
Dependency count | 1 | 1 | 0 |
Self size | 9 KB | 12 KB | 🚨 +2 KB 🚨 |
Dependency size | 5 KB | 5 KB | 0 B |
Bundle Size Analyzer | Link | Link |
@storybook/addon-interactions
Before | After | Difference | |
---|---|---|---|
Dependency count | 56 | 56 | 0 |
Self size | 128 KB | 129 KB | 🚨 +1 KB 🚨 |
Dependency size | 12.73 MB | 12.72 MB | 🎉 -14 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/addon-links
Before | After | Difference | |
---|---|---|---|
Dependency count | 4 | 4 | 0 |
Self size | 19 KB | 20 KB | 🚨 +1 KB 🚨 |
Dependency size | 284 KB | 272 KB | 🎉 -13 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/addon-measure
Before | After | Difference | |
---|---|---|---|
Dependency count | 2 | 2 | 0 |
Self size | 32 KB | 60 KB | 🚨 +28 KB 🚨 |
Dependency size | 20 KB | 20 KB | 0 B |
Bundle Size Analyzer | Link | Link |
@storybook/addon-outline
Before | After | Difference | |
---|---|---|---|
Dependency count | 2 | 2 | 0 |
Self size | 23 KB | 41 KB | 🚨 +19 KB 🚨 |
Dependency size | 32 KB | 32 KB | 0 B |
Bundle Size Analyzer | Link | Link |
@storybook/addon-storysource
Before | After | Difference | |
---|---|---|---|
Dependency count | 7 | 7 | 0 |
Self size | 1.89 MB | 1.89 MB | 0 B |
Dependency size | 10.74 MB | 10.73 MB | 🎉 -13 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/experimental-addon-test
Before | After | Difference | |
---|---|---|---|
Dependency count | 60 | 60 | 0 |
Self size | 832 KB | 834 KB | 🚨 +2 KB 🚨 |
Dependency size | 14.19 MB | 14.17 MB | 🎉 -14 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/core
Before | After | Difference | |
---|---|---|---|
Dependency count | 54 | 54 | 0 |
Self size | 19.11 MB | 19.11 MB | 🚨 +955 B 🚨 |
Dependency size | 14.44 MB | 14.43 MB | 🎉 -13 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/experimental-nextjs-vite
Before | After | Difference | |
---|---|---|---|
Dependency count | 153 | 153 | 0 |
Self size | 234 KB | 234 KB | 0 B |
Dependency size | 45.54 MB | 45.52 MB | 🎉 -14 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/nextjs
Before | After | Difference | |
---|---|---|---|
Dependency count | 592 | 592 | 0 |
Self size | 474 KB | 474 KB | 0 B |
Dependency size | 84.23 MB | 84.22 MB | 🎉 -14 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/server-webpack5
Before | After | Difference | |
---|---|---|---|
Dependency count | 255 | 255 | 0 |
Self size | 15 KB | 15 KB | 0 B |
Dependency size | 32.67 MB | 32.66 MB | 🎉 -13 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/blocks
Before | After | Difference | |
---|---|---|---|
Dependency count | 4 | 4 | 0 |
Self size | 604 KB | 604 KB | 🚨 +18 B 🚨 |
Dependency size | 1.53 MB | 1.52 MB | 🎉 -13 KB 🎉 |
Bundle Size Analyzer | Link | Link |
storybook
Before | After | Difference | |
---|---|---|---|
Dependency count | 55 | 55 | 0 |
Self size | 22 KB | 22 KB | 0 B |
Dependency size | 33.55 MB | 33.54 MB | 🎉 -12 KB 🎉 |
Bundle Size Analyzer | Link | Link |
sb
Before | After | Difference | |
---|---|---|---|
Dependency count | 56 | 56 | 0 |
Self size | 1 KB | 1 KB | 0 B |
Dependency size | 33.57 MB | 33.56 MB | 🎉 -12 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/cli
Before | After | Difference | |
---|---|---|---|
Dependency count | 390 | 390 | 0 |
Self size | 530 KB | 529 KB | 🎉 -468 B 🎉 |
Dependency size | 75.35 MB | 75.34 MB | 🎉 -12 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/codemod
Before | After | Difference | |
---|---|---|---|
Dependency count | 277 | 277 | 0 |
Self size | 612 KB | 612 KB | 🚨 +18 B 🚨 |
Dependency size | 65.42 MB | 65.41 MB | 🎉 -12 KB 🎉 |
Bundle Size Analyzer | Link | Link |
create-storybook
Before | After | Difference | |
---|---|---|---|
Dependency count | 113 | 113 | 0 |
Self size | 1.11 MB | 1.11 MB | 0 B |
Dependency size | 42.68 MB | 42.67 MB | 🎉 -12 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/source-loader
Before | After | Difference | |
---|---|---|---|
Dependency count | 5 | 5 | 0 |
Self size | 41 KB | 41 KB | 🚨 +18 B 🚨 |
Dependency size | 10.68 MB | 10.67 MB | 🎉 -13 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/test
Before | After | Difference | |
---|---|---|---|
Dependency count | 53 | 53 | 0 |
Self size | 1.82 MB | 1.82 MB | 🚨 +18 B 🚨 |
Dependency size | 8.09 MB | 8.08 MB | 🎉 -14 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/preset-server-webpack
Before | After | Difference | |
---|---|---|---|
Dependency count | 18 | 18 | 0 |
Self size | 10 KB | 10 KB | 0 B |
Dependency size | 1.48 MB | 1.47 MB | 🎉 -13 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/server
Before | After | Difference | |
---|---|---|---|
Dependency count | 9 | 9 | 0 |
Self size | 13 KB | 13 KB | 🚨 +18 B 🚨 |
Dependency size | 974 KB | 961 KB | 🎉 -13 KB 🎉 |
Bundle Size Analyzer | Link | Link |
Tnx broo |
…ons' into yann/addon-annotations-as-functions
Closes #30242
What I did
This PR introduces the concept of
definePreview
in preview-api, to be used by addon authors. It also uses that concept as part of the core addons. It updates the syncing logic to take into account so that core addons will be added like this in csf factories:Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>
Greptile Summary
Based on the provided information, I'll create a summary of the key changes in this PR:
Introduces
definePreview
function for standardizing addon configuration in Storybook, with significant changes to core addons and their integration patterns.definePreview
function incode/core/src/preview-api/modules/addons/definePreview.ts
for type-safe addon configurationsync-main-preview-addons.ts
to handle different import patterns for core vs non-core addonsDecoratorFunction
type instead of explicitRenderer
andStoryContext
typesThe changes improve type safety and standardize how addons are registered and configured in Storybook, particularly focusing on core addons that will now be added using function calls rather than direct imports.