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
[DRAFT] Add Storybook (Vite) framework package #10064
base: main
Are you sure you want to change the base?
[DRAFT] Add Storybook (Vite) framework package #10064
Conversation
…add-storybook-framework-package
…rposes — doesn't seem like previewAnnotations are working at all (global decorators + loaders)
import type { StorybookYargsOptions } from '../types' | ||
|
||
/* | ||
readFile and writeFile are somewhat duplicated from @redwoodjs/cli; I could not for the life of me get the package |
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.
@redwoodjs/cli
is a bit strange. It's not ment to be imported from. Stuff that should be shared goes in cli-helpers
. So maybe readFile
and writeFile
should live there. But since you modified writeFile
anyways they might as well both live here, at least for now 🙂
import { useLocation, ParamsContext, parseSearch } from '@redwoodjs/router' | ||
|
||
interface Props { | ||
path?: string |
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.
Did you intend for this to be allParams
to match ParamsProvider
in @redwoodjs/router
?
Or could we maybe just get rid of it since it's not used in the Mock version?
|
||
import { MockParamsProvider } from './MockParamsProvider' | ||
|
||
// Import the user's Router from `./web/src/Router.{tsx,jsx}`, |
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.
// Import the user's Router from `./web/src/Router.{tsx,jsx}`, | |
// Import the user's Routes from `./web/src/Routes.{tsx,jsx}`, |
import { MockParamsProvider } from './MockParamsProvider' | ||
|
||
// Import the user's Router from `./web/src/Router.{tsx,jsx}`, | ||
// we pass the `children` from the user's Router to `./MockRouter.Router` |
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.
// we pass the `children` from the user's Router to `./MockRouter.Router` | |
// we pass the `children` from the user's Routes to `./MockRouter.Router` |
// we pass the `children` from the user's Router to `./MockRouter.Router` | ||
// so that we can populate the `routes object` in Storybook and tests. | ||
// // @ts-expect-error - this comes from a Vite alias in main.ts | ||
let UserRouterWithRoutes: React.FC |
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.
let UserRouterWithRoutes: React.FC | |
let UserRoutes: React.FC |
export const routes: { [routeName: string]: () => string } = {} | ||
|
||
/** | ||
* We overwrite the default `Router` export (see jest-preset). So every import |
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.
is jest-preset still the thing to look at?
import { reactDocgen } from './plugins/react-docgen' | ||
import type { StorybookConfig } from './types' | ||
|
||
const getAbsolutePath = <I extends string>(input: I): I => |
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.
Can you explain what's going on with the types here? I tried it without the narrowing to I
and it seems to still work as expected. What am I missing?
const { | ||
default: UserRouterWithRoutes, | ||
} = require('~__REDWOOD__USER_ROUTES_FOR_MOCK') | ||
let UserRouterWithRoutes: React.FC |
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.
Same naming questions here as above
Overview
This PR is the first step to migrating our Storybook integration from relying on Webpack to relying on Vite. Specifically, this PR:
react-vite
framework package.storybook-vite
CLI package, which is based on the existingstorybook
CLI package. The CLI package does two important things before running the Storybook command:Importantly, the architecture of this (including duplicating files, etc.) is based on the eventual goal of removing the older Storybook integration files.
Proof
This screen recording shows that the following works:
Details
This framework package is based on the proof of concept of getting Storybook working on RedwoodJS with Vite, which is documented here.
Please see that and official Storybook framework package documentation to understand implementation details.
Outstanding
yarn redwood storybook
, and make the new oneyarn redwood storybook-vite
.yarn redwood storybook-webpack
.Trying it out
First step is, of course, pulling down this branch.
I've been testing this with the generated test project. If you want to do that, from the framework repo, first run:
yarn run build:test-project ../for-testing-storybook-vite
Then, over in your project, run
yarn rwfw project:tarsync
so that the module resolutions point to the ones in this branch.Then, I think because it hasn't yet been published anywhere, you'll need to manually add the new CLI package (yarn complains about not being able to find the packument when I try to get the CLI package to autoinstall):
Then, run:
Your browser should then open to Storybook!