You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This makes it impossible for me to use Mantine properly anymore!
Adding the Mantine styles file:
import*asReactfrom'react';/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. *//* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */importconfigfrom'@payload-config';importtype{ServerFunctionClient}from'payload';import{RootLayout,handleServerFunctions}from'@payloadcms/next/layouts';import{importMap}from'@/app/(payload)/admin/importMap';import'@payloadcms/next/css';import'@mantine/core/styles.css';import'./custom.scss';typeArgs={children: React.ReactNode;};constserverFunction: ServerFunctionClient=asyncfunction(args){'use server';returnhandleServerFunctions({
...args,
config,
importMap,});};constLayout=({ children }: Args)=>{return(<RootLayoutconfig={config}importMap={importMap}serverFunction={serverFunction}htmlProps={{suppressHydrationWarning: true}}>{children}</RootLayout>);};exportdefaultLayout;
This increases the size of the bundle and makes the Payload dependent on Mantine, which is not right!
In the image above, mantine-scale has been added to the payload styles.
Such a problem would actually make it very difficult to integrate Payload with Mantine!
The reason var(--mantine-scale) is being injected into Payload's admin styles comes down to how postcss-preset-mantine works when autoRem: true is enabled:
Global PostCSS processing: In Next.js App Router, PostCSS operates globally across all imported stylesheets in the compilation pipeline—including @payloadcms/next/css.
auto-rem behavior: Enabling autoRem: true in postcss.config.mjs activates postcss-auto-rem. This plugin parses every declaration containing px and converts values like 16px into calc(0.0625rem * var(--mantine-scale)).
Missing variable in Payload's admin layout: Payload CMS admin routes run inside their own root layout (RootLayout from @payloadcms/next/layouts), which does not mount <MantineProvider> or declare Mantine's CSS variables. Under the W3C CSS Custom Properties specification, using an undefined variable without a fallback inside calc(...) causes the declaration to become invalid at computed-value time. As a result, Payload's paddings, heights, borders, and margins collapse.
Importing @mantine/core/styles.css into Payload's layout provided the missing --mantine-scale definition on :root, but as you noted, it bloats the admin bundle and risks CSS specificity conflicts.
Recommended Solutions
Solution 1: Turn off autoRem: true (Recommended Mantine v7 Pattern)
In Mantine v7+, autoRem: true is completely optional. Mantine's core components already ship pre-compiled into rem units; they do not rely on autoRem.
Turn off autoRem in postcss.config.mjs:
// postcss.config.mjsconstconfig={plugins: {'postcss-preset-mantine': {autoRem: false,// Disable global auto-conversion of px to rem},'postcss-simple-vars': {variables: {'mantine-breakpoint-xs': '320px','mantine-breakpoint-sm': '375px','mantine-breakpoint-md': '425px','mantine-breakpoint-lg': '768px','mantine-breakpoint-xl': '1024px',},},},};exportdefaultconfig;
For your own custom styles in *.module.css, use Mantine's built-in rem() and em() helper functions (which are enabled by default through remEmFunctions: true):
/* src/components/MyComponent.module.css */.card{/* Compiles to calc(1rem * var(--mantine-scale)) only in your own CSS */padding:rem(16px);border-radius:rem(8px);@media(min-width: $mantine-breakpoint-md){padding:rem(24px);}}
This keeps @payloadcms/next/css completely untouched while retaining full Mantine styling capabilities in your frontend components.
Solution 2: Scope PostCSS to Ignore @payloadcms and node_modules
If you strongly prefer writing raw px values in your own application and having them converted automatically, you can guard postcss-preset-mantine in postcss.config.mjs so it skips Payload and third-party vendor files:
// postcss.config.mjsimportpresetMantinefrom'postcss-preset-mantine';importsimpleVarsfrom'postcss-simple-vars';constmantinePlugin=presetMantine({autoRem: true});exportdefault{plugins: [{postcssPlugin: 'scoped-mantine-preset',Once(root,helpers){constfilePath=root.source?.input?.file||'';// Skip Payload CMS styles and external vendor stylesheetsif(filePath.includes('@payloadcms')||filePath.includes('node_modules')){return;}// Run the Mantine preset plugins only for your application codereturnmantinePlugin.plugins.reduce((promise,plugin)=>promise.then(()=>(plugin.Once ? plugin.Once(root,helpers) : undefined)),Promise.resolve());},},simpleVars({variables: {'mantine-breakpoint-xs': '320px','mantine-breakpoint-sm': '375px','mantine-breakpoint-md': '425px','mantine-breakpoint-lg': '768px','mantine-breakpoint-xl': '1024px',},}),],};
Solution 3: Provide the Missing Variable in custom.scss Without Mantine Styles
If you need a zero-config workaround without altering postcss.config.mjs, you do not need to import @mantine/core/styles.css. Simply define --mantine-scale: 1; inside the existing ./custom.scss that Payload's admin layout imports:
This satisfies the var(--mantine-scale) calculations generated by autoRem without downloading or executing Mantine's heavy CSS bundle inside the Payload admin UI.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
The payload cms styles are not applied correctly! This is probably because of postCSS.
I have found two non-standard solutions to this issue.
Such a problem would actually make it very difficult to integrate Payload with Mantine!
All reactions