Repository navigation
[RFC] OXC fast path for CSF indexing #36467
Replies: 1 comment 6 replies
|
Great idea, @EastonShin! I believe replacing Babel is the long-term goal though I'm not sure what all the technical constraints are for this to happen. I believe we'll have very little appetite for owning two indexers instead of one, though. As you pointed out, we'd need to ensure API equivalence. As CSF 4 becomes default in Storybook 11, it's quite possible we'll get PRs on the code that extracts static properties for the index, so the risk is real. This means we'd need to add CI test paths for both implementations. That's also a good reason to prefer replacements over duplications of internal APIs. My personal opinion is that "Replacing Babel in CsfFile entirely" would be a great goal for this RFC. It's definitely a bigger piece of work but it's also a bigger net benefit and it avoids having to still preserve Babel! @JReinhold, @huang-julien, @shilman FYI :) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Storybook already ships and uses OXC for server-side module graph work (#34625). This RFC explores reusing that existing parser infrastructure for CSF indexing, without introducing a new dependency. Statically analyzable story files are indexed with
oxc-parser; everything else falls back to the existing Babel/CsfFilepath. In a proof of concept, 96.3% of this repository's 706 story files take the fast path with zero output mismatches, andstorybook indexon Storybook's internal UI drops from ~7.97s to ~5.95s.Problem Statement
storybook dev,storybook buildandstorybook indexrun parses every story file with Babel to build the story index.Non-goals
CsfFile. It is still used for everything that transforms or writes CSF (vitest transform, save-story, docs enrichment), and for every shape the fast path doesn't support.Implementation
indexCsfWithOxc(code, fileName, options)returnsIndexInput[]ornull("unsupported shape").csfIndexertries the fast path first and falls back toloadCsf(...).parse().indexInputsonnull. The experimental flag is off by default.CsfFileimplementation remains the reference path during the experimental phase. Unsupported or uncertain shapes fall back to it.Template.bind({}), legacy story annotations (Story.storyName = ...,Story.play = ...), staticincludeStories/excludeStories, and CSF4preview.meta()/meta.story()/meta.extend()whenpreviewis imported from.storybook/preview.export { x as y }specifiers,export *,__namedExportsOrder, factory meta defined outside the file, story-level.extend(), and parse errors (e.g. Flow).Correctness
index.jsonis byte-identical with and without the fast pathPerformance (macOS, Node 22)
storybook indexon Storybook's internal UI: ~7.97s → ~5.95s (~25% reduction), averaged over 6 alternating runsCompatibility
Proof of concept: https://github.com/EastonShin/storybook/tree/feat/native-csf-indexer-poc
Prior Art
storybook/internal/oxc-parserwrapper and parse worker pool. This proposal reuses that existing direction for CSF indexing rather than introducing a new parser dependency.Deliverables
storybook/internal/oxc-parserwith typed OXC AST nodes, behind an experimental feature flag (e.g.features.experimentalOxcIndexer).Risks
CsfFilesemantics that the fast path doesn't mirror could produce different index output. Mitigation: the fast path only handles shapes it can prove, and the CI parity gate catches drift on the repository's story files.CsfFilechanges. feat(csf-tools): implement factory meta resolution and enhance story import handling #36272 (cross-file factory meta resolution) is compatible by design: when OXC can't resolve factory meta locally, it returnsnulland Babel handles the file. The correctness risk is low. The cost is lower fast-path coverage for those files. Core: Recognise .extend() calls as CSF factory stories in enrichCsfStory #35339 (.extend()as factory stories) and Core: Parse modern Flow syntax in CSF files with hermes-parser #35848 (Flow via hermes-parser) likewise only affect files that already fall back.Unresolved Questions
CsfFileas the fallback/reference path and add a CI parity gate over the repository's story corpus.CsfFilechanges such as feat(csf-tools): implement factory meta resolution and enhance story import handling #36272?features.experimentalOxcIndexerthe right flag shape?storybook/internal/oxc-parserworker pool, or stay synchronous like the current indexer?Alternatives considered / Abandoned Ideas
CsfFileentirely.CsfFilealso backs transforms and CSF writing, so swapping its AST would be a far larger and riskier change. A read-only fast path with fallback keeps the blast radius small.Disclosure: I used Claude (Claude Code) to help build the proof of concept, run the benchmarks and draft this RFC. I reviewed the results and the text myself.
All reactions