fix(contributors): defer .all-contributorsrc read to fix Storybook bundle#18106
Merged
Conversation
The module-level `readFileSync` call ran at import time, which broke Storybook (Chromatic) since `MdComponents` re-exports `Contributors`. Webpack stubs `fs` in the browser, so importing the module crashed with `(0 , fs_ignored_.readFileSync) is not a function` and Chromatic could not extract stories. Wrap the read in a memoized getter so importing the module is side-effect free; the read still happens once per SSG worker on first render.
✅ Deploy Preview for ethereumorg ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.

Summary
Fixes the Chromatic failure on the v11.6.0 release PR (#18104):
Root cause
src/components/Contributors/index.tsx(added in #18073) calledreadFileSync(".all-contributorsrc")at module top level.MdComponents/index.tsxbarrels inContributors, and theMdComponents.stories.tsxstory imports that barrel — so Storybook's webpack pullsContributorsinto the browser bundle.Storybook stubs
fs(fs_ignored_), so evaluating the module hit the stub and crashed. Theimport "server-only"directive only enforces against the Next.js client bundler, not Storybook.Fix
Wrap the read in a memoized getter (
getShuffledContributors()). Importing the module is now side-effect free; the read still happens once per SSG worker, on first render of<Contributors />.Test plan
pnpm build-storybooksucceedsreadFileSyncat top level (call is now inside the function:()=>{if(!shuffledContributors){const raw=(0,fs_ignored_.readFileSync)(...))npx tsc --noEmitpassesstaging, Chromatic on the release PR (Deploy v11.6.0 #18104) goes green