Fix the @storybook/nextjs image loader #20615
Merged
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: #20611
This fixes the corrupted images when importing images with the @storybook/nextjs framework. Looking at the file history, it probabily broke with commit 44129a4.
What I did
I compared the webpack loader that exists in Next.js with the webpack loader in Storybook, and saw that the definition of 'raw' was different.
When I changed it so it was the same as the Next.js version, the images were not corrupted after a production build anymore.
That however introduced TS errors, so I reverted the export change made in commit 44129a4 to archive the same.
File in Next.js: https://github.com/vercel/next.js/blob/98df70e233e536188a303eacdf27ca2d1f4cfb19/packages/next/src/build/webpack/loaders/next-image-loader.ts
How to test
If your answer is yes to any of these, please make sure to include it in your PR.
I am not familiar with the Storybook codebase, and because the images are currently broken I assume that there is no test for this yet. I think it is wise to create an E2E test that checks full Next.js compatibility, but I think that is out of scope of this issue.