Skip to content

Commit

Permalink
[nextjs] Move the import startsWith next check at end
Browse files Browse the repository at this point in the history
* This fixes the resolve error happening in nextjs for it's path based module imports.
* Also adds check for `next/link`
* Ignore null value during css object processing
  • Loading branch information
Brijesh Bittu committed Sep 11, 2024
1 parent 445c9ce commit 689a35d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 7 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') {
return require.resolve('../next-image');
}
if (what.startsWith('next/font')) {
Expand All @@ -76,6 +70,12 @@ 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.startsWith('@babel') || what.startsWith('react') || what.startsWith('next')) {
return require.resolve(what);
}
if (asyncResolve) {
return asyncResolve(what, importer, stack);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/pigment-css-react/src/utils/cssFnValueToVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ function iterateAndReplaceFunctions(
const css = styleObj as StyleObj;
Object.keys(css).forEach((key) => {
const value = css[key];
if (!value) {
// ignore null value
return;
}

if (typeof value === 'object') {
if (!Array.isArray(value)) {
Expand Down

0 comments on commit 689a35d

Please sign in to comment.