Comments (11)
This is driving me nuts, I've tried all the solutions mentioned above and still the antd styles are not pre-rendering.
I inspect the content created by return <style id="antd" dangerouslySetInnerHTML={{ __html: extractStyle(cache, true) }} />;
(as dictated in the docs) and I see that the result looks like this.
<style id="antd">.data-ant-cssinjs-cache-path{content:"";}</style>
It seems the extractStyle
function is not doing very much.
I have no idea what else to try.
My cssinjs version numbers match.
from cssinjs.
I meet the same problem too. The flicker css still happens when i use [email protected] but it works well after i downgrade to [email protected].
from cssinjs.
@Stuart88 Did you find a solution?
Nope, I chose to ignore it.
In my case, the app loads fast enough for the css loading flicker to not be too much of a problem.
from cssinjs.
I managed to reproduce here https://github.com/jknap/antd-demo/tree/main
npx create-next-app antd-demo
npm install antd --save
npm install @ant-design/cssinjs --save
(use App Router)- create
lib/AntdRegistry.tsx
- Use it in
app/layout.tsx
It works the first time.
Now if you delete the node_modules
and run npm install
again, then you can reproduce.
Downgrading to [email protected] does not solve the issue in this case.
It seems that the cache returned by createCache
is empty in this case.
I noticed that when the cache is not empty, this method is called multiple times, and it's never called when the issue is reproduced.
I am not sure what is triggering it so I could not dig more unfortunately, but the issue seems to come from there.
from cssinjs.
Ok I found the issue, it was due to a mismatch between the @ant-design/cssinjs version and the one that antd depends on.
This can be fixed by forcing the same @ant-design/cssinjs version in package.json.
This is mentioned in the doc => https://ant.design/docs/react/use-with-next#using-app-router
Fo reference => ant-design/ant-design#45567
from cssinjs.
Actually, the flicker still valid when streaming html
It seems you either have style duplication or streaming support
I kinda solved this with that trick:
'use client';
import { useRef, useState } from 'react';
import { useServerInsertedHTML } from 'next/navigation';
import { createCache, extractStyle, StyleProvider } from '@ant-design/cssinjs';
export function AntdRegistry({ children }: React.PropsWithChildren) {
const [cache] = useState(() => createCache());
const alreadyInserted = useRef(new Set<string>());
useServerInsertedHTML(() => {
if (cache.cache.size === 0) {
return;
}
for (const key of alreadyInserted.current.keys()) {
cache.cache.delete(key);
}
const html = extractStyle(cache, true);
for (const key of cache.cache.keys()) {
alreadyInserted.current.add(key);
}
cache.cache.clear();
return <style dangerouslySetInnerHTML={{ __html: html }} className='antd' />;
});
return (
<StyleProvider cache={cache} hashPriority='high'>
{children}
</StyleProvider>
);
}
But i am not aware if relying on cache keys is fine in all the edge cases
from cssinjs.
I also created a bug with reproduction in the antd repo, so let me link in here just in case:
ant-design/ant-design#45955
from cssinjs.
-- import { createCache, extractStyle } from '@ant-design/cssinjs';
++ import { createCache, extractStyle } from '@ant-design/cssinjs/lib';
This solved mine!
from cssinjs.
Same issue here, using:
"@ant-design/cssinjs": "^1.18.0-alpha.5",
"antd": "^5.11.4",
"next": "14.0.3",
"react": "^18",
"react-dom": "^18"
EDIT: I used "@ant-design/cssinjs": "1.17.5" and it worked.
from cssinjs.
Same issue here, using:
"@ant-design/cssinjs": "^1.18.0-alpha.5", "antd": "^5.11.4", "next": "14.0.3", "react": "^18", "react-dom": "^18"
EDIT: I used "@ant-design/cssinjs": "1.17.5" and it worked.
Yes you need to run npm ls @ant-design/cssinjs
and make sure that your @ant-design/cssinjs
version is the same as the one used by antd
itself.
This is explained in the Antd NextJS doc, although I missed it the first time. Might be worth fixing that as many of us are running into the issue.
from cssinjs.
@Stuart88 Did you find a solution?
from cssinjs.
Related Issues (20)
- Question - How to use this right? HOT 2
- useGlobalCache TypeError: Cannot read properties of null (reading '1') HOT 4
- useHMR throws in SSR when when dev-server hot reloading is enabled
- Content Security Policy - Nonce not set HOT 2
- 处理伪元素的content时,直接去除了content属性 HOT 1
- extractStyle(cache)返回是的content是"",cache打印有内容 HOT 6
- Uncaught RangeError: Invalid string length
- linters should be removed in production HOT 2
- Receiving error because code is running before head or body element are available
- 修改的样式无法热更新
- 🐞 Duplicate `!important` when enable legacyLogicalPropertiesTransformer for paddingInlineStart and marginBlockStart with !important
- Why is there no package-lock.json file? HOT 1
- antd ConfigProvider 设置 cssVar = true时,css variable中的px值不会被转换为rem HOT 1
- 如何调用默认样式
- bug: StyleProvider container config not work
- 【feature】能否支持兼容flex gap和margin-inline转margin-left,margin-right
- README 里缺少 extractStyle 的 API 描述
- useGlobalCache 会产生内存泄漏 HOT 1
- 在shadowRoot中使用时, 切换theme算法无效.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cssinjs.