Skip to content
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

[nextjs] Move the import startsWith next check at end #228

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/pigment-css-nextjs-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ export function withPigment(nextConfig: NextConfig, pigmentConfig?: PigmentOptio
if (what.startsWith('__barrel_optimize__')) {
return require.resolve('../next-font');
}
// Need to point to the react from node_modules during eval time.
// Otherwise, next makes it point to its own version of react that
// has a lot of RSC specific logic which is not actually needed.
if (what.startsWith('@babel') || what.startsWith('react') || what.startsWith('next')) {
return require.resolve(what);
}
if (what === 'next/image') {
if (what === 'next/image' || what === 'next/link') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If what==='next/link' we still import next-image? @brijeshb42

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both just point to a dummy module for wyw evaluation to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next/link just provides a default export which is already there in the next-image file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK 👌

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit confusing 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just rename the next-image file to next-module-stub or similar to remove the confusion.
It's on our side and not user facing.

return require.resolve('../next-image');
}
if (what.startsWith('next/font')) {
Expand All @@ -76,6 +70,17 @@ export function withPigment(nextConfig: NextConfig, pigmentConfig?: PigmentOptio
if (what.startsWith('@emotion/styled') || what.startsWith('styled-components')) {
return require.resolve('../third-party-styled');
}
// Need to point to the react from node_modules during eval time.
// Otherwise, next makes it point to its own version of react that
// has a lot of RSC specific logic which is not actually needed.
if (
what === 'react' ||
what.startsWith('react-dom/') ||
what.startsWith('@babel/') ||
what.startsWith('next/')
) {
return require.resolve(what);
}
if (asyncResolve) {
return asyncResolve(what, importer, stack);
}
Expand Down
Loading