-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Taking care of next/babel preset #21104
Merged
valentinpalkovic
merged 2 commits into
next
from
valentin/fix-proptypes-for-nextjs-in-production
Feb 27, 2023
Merged
Taking care of next/babel preset #21104
valentinpalkovic
merged 2 commits into
next
from
valentin/fix-proptypes-for-nextjs-in-production
Feb 27, 2023
Conversation
This file contains 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
fc47549
to
66bbc44
Compare
66bbc44
to
3f14c24
Compare
kasperpeulen
approved these changes
Feb 23, 2023
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.
Great!
c00e1dc
to
66cdcd7
Compare
66cdcd7
to
3cc2d7f
Compare
3cc2d7f
to
84b8f68
Compare
This was referenced Feb 27, 2023
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.
Resolves #20087
Resolves #21027
What I did:
Moved next/babel preset into codebase to be able to make changes, because it seems that
next/babel
will not be maintained anymore in favour of swc/Turbopack. Also:@babel/typescript-preset
package from next and use the latest one.Background:
The Next.js babel plugin
next/babel
behaves differently indevelopment
andproduction
modes. It removes React propTypes in production, which is bad because Storybook relies on them to correctly infer the right argTypes. I opened a discussion here at@vercel/nextjs
to be able to conditionally still output the proptypes even for a production build. For almost two months nobody replied to this. I assume, that they will not work on any babel-related stuff, because the future at Next.js is Turbopack.Essentially the
plugin-transform-react-remove-prop-types
plugin applied here should not be applied on production.I tried different approaches:
My first approach was flattening all plugins in
next/babel
preset and removing the superfluousplugin-transform-react-remove-prop-types
plugin if it is present. The issue is that as soon as I want to look up the babel configuration, I cannot identify a plugin by a specific ID or name, because of how the plugins are set up innext/babel
(direct require call).The final approach I have decided on, and which was discussed with @shilman, was to actually copy
next/babel
and all of its dependencies to modify that one line and reference the modifiednext/babel
preset instead. I really don't like this approach, but I can't think of another solution.Therefore actually, only the changes in
code/frameworks/nextjs/src/preset.ts
matter. The other files are more or less copied over with some slight type adjustments.How to test
The chromatic changes introduced here
https://www.chromatic.com/build?appId=634ff0454a50407deedde524&number=205
should be reverted by
https://www.chromatic.com/build?appId=634ff0d0ec053b270775979d&number=2459
Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:merged
orci:daily
GH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]