-
Notifications
You must be signed in to change notification settings - Fork 61
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
extraction-plugin: support for appDir in NextJS 13 #266
Comments
@layershifter, Thank you! |
Linking this discussion here, since I think it may be related 🤔 microsoft/fluentui#25384 |
@Dwlad90 it seems that I traced the problem, looks that it's happening in webpack loader from Looks like Next.js (or its Webpack part) does not like how we emit imports there: griffel/packages/webpack-extraction-plugin/src/webpackLoader.ts Lines 107 to 114 in ebd004e
If imports for CSS are not there - then it works 😳 I did following change and then build is passing: const request = `import ${JSON.stringify(this.utils.contextify(this.context || this.rootContext, `griffel.css!=!${virtualLoaderPath}!${resourcePath}?style=${toURIComponent(result.cssRules.join('\n'))}`))};`;
- this.callback(null, `${result.code}\n\n${request};`, result.sourceMap);
+ this.callback(null, `${result.code}`, result.sourceMap);
return; I will look more to understand why it happens and how to fix it later this/next week. |
No, it's not related to that. This issue is purely related to CSS extraction. |
Thanks for the answer! Good to know. |
* my face when I found the reason *
@Dwlad90 For older version you just need a following patch in if (result) {
- if (result.cssRules) {
+ if (result.cssRules.length > 0) { For newer, I have a fix already in #289. |
@layershifter, Thanks for the solution of the problem. But I noticed that when I add the condition to process styles on the client assembly only, then Webpack successfully compiled and extract the styles. However on the page the CSS file wasn't loaded and, accordingly, there are no styles on the page. To reproduce these errors go to the Sandbox and run the command: npm install && npx next build && npm next start Also I found another issue, when using the RendererProvider in the info - Collecting page data .TypeError: React__namespace.createContext is not a function
at 4947 (file:///home/projects/nextjs-ikosio/.next/server/chunks/854.js:6871:60)
at __webpack_require__ (file:///home/projects/nextjs-ikosio/.next/server/webpack-runtime.js:25:43)
at 2562 (file:///home/projects/nextjs-ikosio/.next/server/chunks/854.js:7197:23)
at __webpack_require__ (file:///home/projects/nextjs-ikosio/.next/server/webpack-runtime.js:25:43)
at 3294 (file:///home/projects/nextjs-ikosio/.next/server/chunks/854.js:7089:18)
at __webpack_require__ (file:///home/projects/nextjs-ikosio/.next/server/webpack-runtime.js:25:43)
at 8748 (file:///home/projects/nextjs-ikosio/.next/server/app/page.js:140:72)
at Function.__webpack_require__ (file:///home/projects/nextjs-ikosio/.next/server/webpack-runtime.js:25:43)
at async collectGenerateParams (file:///home/projects/nextjs-ikosio/node_modules/next/dist/build/utils.js:713:17)
at async eval (file:///home/projects/nextjs-ikosio/node_modules/next/dist/build/utils.js:853:36) To reproduce these errors go to the Sandbox and run following command: npm install && npx next build Maybe it happens because of the limitations of the Server Components, currently the use of CSS-in-JS If you uncomment the line 'use client' in the |
Yeah, it's the same problem that I faced. Will look into it more.
Out of curiosity, why do you need it with CSS extraction? It's not used when CSS extraction is in place.
It's a thing that I don't really like. Components that use |
I cloned the code and checked it out a bit, but I have never used nx, etc. and it seemed to take me a while to understand it, so I will share about the next-extraction-plugin here. The first thing I did was to tell getGlobalCssLoader that it is app-dir.
const isAppDir = nextConfig.experimental?.appDir === true;
const appDirOptions = isAppDir
? {
hasAppDir: true,
experimental: { appDir: true },
}
: {};
cssRules.unshift({
test: /griffel\.css$/i,
sideEffects: true,
use: getGlobalCssLoader(
{
assetPrefix: config.assetPrefix,
isClient: !isServer,
isServer,
isDevelopment: dev,
future: nextConfig.future || {},
experimental: nextConfig.experimental || {},
...appDirOptions,
} as ConfigurationContext,
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev), undefined),
[],
),
}); For the react server components, since hooks are not available You will need to rethink your design in order to get it to work. |
Hi @layershifter, |
@Dwlad90 yes, this looks relevant and explains what current thing does work. I will look into it in upcoming weeks, but feel free to do the same if you are interested 😉 |
FYI, I have described the Next.js issue here: SukkaW/style9-webpack#1 (comment), and I quote:
And you can find my workaround here: SukkaW/style9-webpack@f468bf8...696f4e0 In short, you can't use resource match query ( import 'noop.css?{ filename, source }' Then you will need to create a loader to extract |
@Dwlad90 can you please re-test with the latest Next.js? I was able to compile your example without any issues: |
@layershifter, Thank you. |
@Dwlad90 thanks for confirmation, closing. |
Hi,
I was trying to use NextJS v13 appDir mode with
@griffel
and I get the following errors:and
TypeError: core.createDOMRenderer is not a function at 4415 (/home/projects/nextjs-ltekvi/.next/server/chunks/792.js:3446:88) at __webpack_require__ (/home/projects/nextjs-ltekvi/.next/server/webpack-runtime.js:25:43) at 5933 (/home/projects/nextjs-ltekvi/.next/server/chunks/792.js:3829:23) at __webpack_require__ (/home/projects/nextjs-ltekvi/.next/server/webpack-runtime.js:25:43) at 9692 (/home/projects/nextjs-ltekvi/.next/server/chunks/792.js:3710:18) at __webpack_require__ (/home/projects/nextjs-ltekvi/.next/server/webpack-runtime.js:25:43) at 4312 (/home/projects/nextjs-ltekvi/.next/server/app/page.js:99:72) at __webpack_require__ (/home/projects/nextjs-ltekvi/.next/server/webpack-runtime.js:25:43) at eval (/home/projects/nextjs-ltekvi/node_modules/next/dist/compiled/react-server-dom-webpack/client.js:918:337)
There are errors only when using the '@griffel/next-extraction-plugin' package.
To reproduce these errors g to the Sandbox and run the command:
npm install && npx next build
The text was updated successfully, but these errors were encountered: