Skip to content

Commit

Permalink
Fix (probably) the issue with Next.js 13.0.1 css loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre de la Martiniere committed Nov 1, 2022
1 parent 04e3a3d commit 70caf1b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/__packages__/shared-ui/components/Input.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styles from './Input.module.scss';

function Input() {
return <input type='text' className={styles.input} />;
return <input type='text' className={styles.input} defaultValue='' />;
}

export default Input;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './Textarea.css';

function Textarea(props) {
return (
<textarea type='text' className='textarea'>
<textarea type='text' className='textarea' defaultValue=''>
{props.children}
</textarea>
);
Expand Down
43 changes: 11 additions & 32 deletions src/next-transpile-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
*
* THIS PLUGIN IS A BIG HACK.
*
* don't even try to reason about the quality of the following lines of code.
* Don't even try to reason about the quality of the following lines of code.
*
* ---
*
* We intentionally do not use experimental.transpilePackages (yet) as its API
* may change and we want to avoid breaking changes while the Next.js figures
* this all out.
*/

const path = require('path');
Expand All @@ -12,10 +18,10 @@ const process = require('process');
const enhancedResolve = require('enhanced-resolve');

// Use me when needed
// const util = require('util');
// const inspect = (object) => {
// console.log(util.inspect(object, { showHidden: false, depth: null }));
// };
const util = require('util');
// const inspect = (object) => {
// console.log(util.inspect(object, { showHidden: false, depth: null }));
// };

const CWD = process.cwd();

Expand Down Expand Up @@ -191,33 +197,6 @@ const withTmInitializer = (modules = [], options = {}) => {
// TODO ask Next.js maintainer to expose the css-loader via defaultLoaders
const nextCssLoaders = config.module.rules.find((rule) => typeof rule.oneOf === 'object');

// .module.css
if (nextCssLoaders) {
const nextCssLoader = nextCssLoaders.oneOf.find(
(rule) => rule.sideEffects === false && regexEqual(rule.test, /\.module\.css$/)
);

const nextSassLoader = nextCssLoaders.oneOf.find(
(rule) => rule.sideEffects === false && regexEqual(rule.test, /\.module\.(scss|sass)$/)
);

if (nextCssLoader) {
nextCssLoader.issuer.or = nextCssLoader.issuer.and ? nextCssLoader.issuer.and.concat(matcher) : matcher;
delete nextCssLoader.issuer.not;
delete nextCssLoader.issuer.and;
} else {
console.warn('next-transpile-modules - could not find default CSS rule, CSS imports may not work');
}

if (nextSassLoader) {
nextSassLoader.issuer.or = nextSassLoader.issuer.and ? nextSassLoader.issuer.and.concat(matcher) : matcher;
delete nextSassLoader.issuer.not;
delete nextSassLoader.issuer.and;
} else {
console.warn('next-transpile-modules - could not find default SASS rule, SASS imports may not work');
}
}

// Add support for Global CSS imports in transpiled modules
if (nextCssLoaders) {
const nextGlobalCssLoader = nextCssLoaders.oneOf.find(
Expand Down

0 comments on commit 70caf1b

Please sign in to comment.