Repository navigation
fix(optimize-imports): support @heroui/react in Server Components #4099
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dea1e55
fix(optimize-imports): optimize @heroui/react barrel imports by default
james-elicx 06edc50
feat(optimize-imports): follow react-aria-components subpath imports …
james-elicx 2999215
fix(optimize-imports): only follow the server-safe Toast queue subpat…
james-elicx cff6c2c
fix(optimize-imports): follow all react-aria-components subpath expor…
james-elicx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
This broad match also rewrites direct user imports such as
import { Collection } from "react-aria-components/Collection"in a Server Component. The publishedCollection.mjsentry intentionally imports"client-only"(its comment says this should cause a build-time error from an RSC), but this transform follows the re-export toreact-aria/Collectionand drops that guard. That changes Next.js-compatible behavior for every RAC subpath in order to fix one server-safe Toast queue export. Please scope this path to the known HeroUI/ToastQueue case (for example by importer and exported name), so arbitrary RAC client entries retain theirclient-onlyerror.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.
Fixed in 2999215: the RSC subpath rewrite now only applies to
UNSTABLE_ToastQueuefromreact-aria-components/Toast(the server-safe react-stately class heroui's toast queue imports). Any other export, namespace import or RAC subpath is left unchanged, so itsclient-onlyguard still fails a Server Component import. Added a test forUNSTABLE_Toast, a mixed import, a namespace import andreact-aria-components/Collection.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.
Went back to following all
react-aria-componentssubpath exports in cff6c2c, after checking real Next.js. Next's default Turbopack build follows re-exports out of these side-effect-free entries and drops theirclient-onlyimport too:UNSTABLE_ToastQueuerenders, andCollectionfails withcreateContext is not a function, not theclient-onlyerror. Webpack keeps the guard, but it also fails the #4007 repro itself, even withoptimizePackageImports. The export allowlist was stricter than Next's default build.Each cell is dev / build for a page whose only import is the one in the row (Next.js 16.2.7, @heroui/react 3.2.1, react-aria-components 1.18.0). "client-only" is the
'client-only' cannot be importederror; "createContext" iscreateContext is not a function.optimizePackageImports: ["@heroui/react"]{ UNSTABLE_ToastQueue }fromreact-aria-components/Toast{ Collection }fromreact-aria-components/Collection{ Toast }from@heroui/react, rendering<Toast.Provider />(#4007){ Skeleton }from@heroui/react