feat: CSF Factories (CSF Next) support - #919
Open
kasperpeulen wants to merge 28 commits into
Open
Conversation
…andling Add storybook as devDependency to all workspace packages so pnpm hoists a single copy, fixing duplicate action events caused by two separate module instances each registering their own listener. Sanitize RN synthetic events in action payloads only on the WebSocket channel where async transport causes event pool recycling. Remove the unnecessary patch from the local sync channel. Remove early-return guards from addon panels so hooks are called unconditionally, fixing React rules-of-hooks violations.
- Changed annotations parameter type from any[] to ModuleExports[] in resolveAnnotations and getProjectAnnotations functions. - Introduced a PreviewObject interface and isPreviewObject type guard for better handling of preview objects. - Updated storyEntries type to use Record<string, unknown> instead of any for improved type clarity.
- Updated storyEntries and normalizedStories types to use unknown instead of Record<string, unknown> for improved type flexibility.
- Added '@storybook/react-native-theming' as a dependency for theming capabilities. - Updated ActionLogger to use styled components for count text based on the current theme. - Refactored Inspect component to utilize themed text styles for various data types, enhancing visual consistency and readability.
- Removed *.lerna_backup from .gitignore. - Improved clarity in CLAUDE.md by consolidating testing tool commands and adding a new section on sending events to the channel server. - Streamlined the agent-device section for better readability. - Removed redundant architecture overview section to focus on key concepts.
Resolves conflicts between the CSF factories work (#826) and six months of drift on next: - Start.tsx, preview.ts: take next's refactored versions (extracted getReactNativeProjectAnnotations, StoryEntry type, web workarounds); the factories logic lives in definePreview.tsx/entry-preview.ts - index.ts: keep the types/config.ts split and definePreview exports, with StorybookConfig updated to next's newer shape (deviceAddons, deprecated addons) - prepareStories.ts: next's TS6-friendly typing plus the factories-aware play detection (typeof story.play === 'function') - package.json: next's dependency versions plus type-fest (used by definePreview types); dropped the addons: Preset[] refinement in favor of next's deliberate Addon union + deviceAddons split - pnpm-lock.yaml: taken from next, to be regenerated by install
- pnpm-lock.yaml picks up the type-fest dependency - .rnstorybook-nofactories/main.ts migrates from the deprecated addons field to deviceAddons, matching the factories config - regenerate its storybook.requires.ts with the current generator template (was stale from before the merge)
🦋 Changeset detectedLatest commit: 8bd7fdc The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Member
|
👀 |
Member
|
I think theres still the question of what we should do for users that have |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: supersedes #826 (same branch content, brought up to date with
next)What I did
Fresh PR of @dannyhw's CSF Factories (CSF Next) work from #826, which had drifted ~6 months behind
next(74 commits) and accumulated merge conflicts. All 24 of Danny's original commits are preserved; on top of them sit one merge commit resolving the conflicts against currentnextand one follow-up chore commit.Danny's work (see #826 for the full description):
definePreview()wrappingstorybook/internal/csf, injecting the RN entry-preview annotations and render function, with compat shims soprepareStoriescan readmeta.title/includeStories/excludeStoriesand stories expose a lazyComponentand aplaythat staysundefinedwhen unsetdefineMain()exported from@storybook/react-native/node.factories.stories.tsxvariants of all example stories plus portable-story tests, and a.rnstorybook-nofactories/config so both CSF styles run side by sideMerge resolution highlights:
Start.tsx/preview.ts: tooknext's refactored versions (extractedgetReactNativeProjectAnnotations,StoryEntrytype, web workarounds); the factories logic lives indefinePreview.tsx/entry-preview.tsindex.ts: kept thetypes/config.tssplit anddefinePreviewexports, withStorybookConfigupdated tonext's newer shape (deviceAddons, deprecatedaddons) — this drops theaddons: Preset[]refinement from feat: CSF Factories (CSF Next) support #826 in favor ofnext's deliberateAddonunion +deviceAddonssplitprepareStories.ts:next's TS6-friendly typing plus the factories-aware story-name resolution andtypeof story.play === 'function'detection.rnstorybook-nofactories/main.ts: migrated from the deprecatedaddonsfield todeviceAddonsand regenerated its stalestorybook.requires.tsHow to test
Verified against the expo example running via
expo start(web target), with the factories config as the default.rnstorybook:.factoriesstories are indexed and render (Actions, Text Input, Deep Controls, Backgrounds, Notes, Hidden Controls, plus the Factories Edge Cases group)onPressfrom a factories storysb-rn-get-storiesgenerates correctly for both the factories and nofactories configsNot yet covered here: an on-device (simulator) run — the jest portable-story tests and the web target exercise the same composition path, but a native run is worth doing before merging. One observation, present for both classic and factories stories (so unrelated to this PR): the controls panel doesn't refresh when switching stories and only binds correctly after a reload.