Skip to content
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

Next.js compatibility feedback collection #43510

Open
zombieJ opened this issue Jul 12, 2023 · 26 comments
Open

Next.js compatibility feedback collection #43510

zombieJ opened this issue Jul 12, 2023 · 26 comments

Comments

@zombieJ
Copy link
Member

zombieJ commented Jul 12, 2023

English Description

Before All

If you meet the problem, please make sure:

  1. Upgrade antd & next to latest version
  2. For compile issue, please try next canary version. Some problem may be fixed but not released yet.

What to leave message in this issue?

  1. leave Codesandbox url or Github repo for minimal reproduction.
    a. minimal reproduction is very important to us for fast dig problem
  2. Tell what reproduce step to do (e.g. npm run build)
  3. Tell what behavior is wrong (e.g. Button style missing on the page. Please check /xxx/xxx page)

中文描述

在开始前

如果你遇到任何问题,请优先:

  1. 升级 antdnext 的版本。
  2. 对于编译问题,可以尝试使用 nextcanary 版本。一些编译问题已经解决但是尚未发布。

这个 issue 下我该做什么?

  1. 留下 Codesandbox 或 Github repo 的 最小重现 地址
    a. 最小重现 非常重要,复杂的代码会难以找出问题所在
  2. 告知重现步骤 (例如:执行 npm run build)
  3. 告知非预期的表现 (例如:在 /xxx/xxx 页面中,Button 的样式丢失了)
@Veri5ied
Copy link

Screenshot 2023-07-19 at 12 38 33 PM This is the issue I am encountering on next ts now using antd. Form throws this warning and I can't tell what is wrong for real

@zombieJ
Copy link
Member Author

zombieJ commented Jul 20, 2023

This is the issue I am encountering on next ts now using antd. Form throws this warning and I can't tell what is wrong for real

Check your node_modules. antd do not have Form folder but form folder: https://unpkg.com/browse/antd@5.7.2/es/

@sahaja56
Copy link

sahaja56 commented Jul 22, 2023

ss

I face this issue currently on next ts using antd. This error only shown after saving changes (Fast Refresh). But if I hard reload the page, it become normal again. And this keeps happening as long as I save every changes which trigger next's fast refresh. I'm not sure what is wrong with this. This fast refresh just act normal when I'm not use antd, so i guess nothing is wrong with next ts.

Edited:
I just noticed that this happened because of @ant-design/cssinjs. I follow docs:
https://ant.design/docs/react/use-with-next#using-nextjs-app-router
If I disable this cssinjs feature, everything works fine, but on every first load, page will shift from no-CSS page to antd style.

@headironc
Copy link

@sahaja56 I also met this problem. Have you solved this problem yet?

@headironc
Copy link

@sahaja56 I found this solution, it seems nice for this problem

@zombieJ
Copy link
Member Author

zombieJ commented Jul 26, 2023

TypeError: Cannot read properties of null (reading '1')

Let me check this. Seem HMR destroy the cache instance but not rebuild it

@thisisandreww
Copy link

@sahaja56 I found this solution, it seems nice for this problem

Thanks, your reference to the solution fixed the issue for me.

In case anyone is searching the same error message, the message is "Cannot read properties of null (reading '1')"

@mihir-karbelkar-wiz
Copy link

mihir-karbelkar-wiz commented Aug 18, 2023

https://github.com/ant-design/ant-design-examples/blob/main/examples/with-nextjs-app-router-inline-style/src/app/with-sub-components/page.tsx

Any plans to move away from sub components?

Since most usecases will require layout and form (atleast for me), it would mean I have to make every page use client otherwise I get the below error.

Error: Unsupported Server Component type: undefined

The way I can go around this, is by passing components as props in a client component

"use client";

import { Layout } from "antd";
import React, { PropsWithChildren } from "react";

const { Header, Content } = Layout;

export default function SiteLayout({
  header,
  children: content,
}: PropsWithChildren<{
  header: React.ReactNode;
}>) {
  return (
    <Layout>
      <Header style={{ display: "flex", alignItems: "center", gap: "4" }}>
        {header}
      </Header>
      <Content>{content}</Content>
    </Layout>
  );
}

But this doesnt seem feasible for any layout or nested layouts across an entire application.

Would love any inputs on this.

@sahaja56
Copy link

@headironc @thisisandreww I tried to update to the latest antd version and it fixes the problem now.

@WankkoRee
Copy link

#43510 (comment)


Same problem with sub-components. Any progress or plans for Antd or Next.js now?

I don't know how to make server-side data fetch and sub-components work together. If I use sub-components, it must need to use client component, but after that I cannot fetch data at server-side any more.


在子组件上遇到了同样的问题。Antd或者Next.js在这方面有任何进展或者计划吗?

我不知道怎么在使用子组件的同时在服务端完成数据获取。如果我使用了子组件,就必须要将页面转为客户端组件,此时我无法再实现服务端的数据获取。

这违背了使用Next.js实现SSR的初衷,如果数据都需要在客户端获取,使用Next.js将没有任何意义。

@zombieJ
Copy link
Member Author

zombieJ commented Sep 1, 2023

@WankkoRee,
You can mix client component with RSC. It's only required a component to be server component or client component. Not limit sub node must follow parent. For the component need interactive, use client. Instead use server.

你是可以混合使用 RSC 和 CC 的。它只是限制一个组件要么是客户端渲染要么是服务端渲染,并没有限制组件的子节点要去跟随父节点。对于需要前端交互的就 use client,反之 RSC 即可。

@AsuraKev
Copy link

Antd styles are overriding my tailwind css classes

@ChristianRaoulis
Copy link

Antd styles are overriding my tailwind css classes

You can use !<tailwind class> to prevent that

@raaaaayn
Copy link

raaaaayn commented Oct 5, 2023

next build fails

next@13.5.4
antd@5.9.4

I am currently using the form component in one of my client rendered files by importing it like so:

import { Form } from "antd";
Collecting page data  .../home/hay/projects/japangrabtech/jobbox/node_modules/antd/es/form/Form.js:11
import classNames from 'classnames';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:74:18)
    at wrapSafe (node:internal/modules/cjs/loader:1141:20)
    at Module._compile (node:internal/modules/cjs/loader:1182:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at mod.require (/home/hay/projects/japangrabtech/jobbox/node_modules/next/dist/server/require-hook.js:64:28)
    at require (node:internal/modules/cjs/helpers:103:18)
    at 8351 (/home/hay/projects/japangrabtech/jobbox/.next/server/pages/index.js:1:35256)

> Build error occurred
Error: Failed to collect page data for /
    at /home/hay/projects/japangrabtech/jobbox/node_modules/next/dist/build/utils.js:1178:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error'
}

This error occurs and build fails.

I have tried:

const PhoneNumberSubmit = dynamic(import("../PhoneNumberSubmit"), {
ssr: false,
}); // does not work
  • removing "use client";

@raaaaayn
Copy link

raaaaayn commented Oct 5, 2023

next build fails

next@13.5.4 antd@5.9.4

I am currently using the form component in one of my client rendered files by importing it like so:

import { Form } from "antd";
Collecting page data  .../home/hay/projects/japangrabtech/jobbox/node_modules/antd/es/form/Form.js:11
import classNames from 'classnames';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:74:18)
    at wrapSafe (node:internal/modules/cjs/loader:1141:20)
    at Module._compile (node:internal/modules/cjs/loader:1182:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at mod.require (/home/hay/projects/japangrabtech/jobbox/node_modules/next/dist/server/require-hook.js:64:28)
    at require (node:internal/modules/cjs/helpers:103:18)
    at 8351 (/home/hay/projects/japangrabtech/jobbox/.next/server/pages/index.js:1:35256)

> Build error occurred
Error: Failed to collect page data for /
    at /home/hay/projects/japangrabtech/jobbox/node_modules/next/dist/build/utils.js:1178:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error'
}

This error occurs and build fails.

I have tried:

* using [next canary](https://vercel.com/blog/next-canary)

* using dynamic import
const PhoneNumberSubmit = dynamic(import("../PhoneNumberSubmit"), {
ssr: false,
}); // does not work
* removing "use client";

Nvm found the issue:

if you are using useForm and importing it like this:

import { useForm } from "antd/es/form/Form";


const [form] = useForm();

Do not, this is what causes it, use the useForm method of the Form component instead

const [form] = Form.useForm();

@zombieJ
Copy link
Member Author

zombieJ commented Oct 11, 2023

Do not, this is what causes it, use the useForm method of the Form component instead

You should not import from the package path since Next do some magic for the path resolution to speed up build perf.

@infodusha
Copy link

Let me introduce two bugs that i've faced when using streaming:
#45955

@bombillazo
Copy link
Contributor

bombillazo commented Nov 22, 2023

We have tried using the "whole export" process to get styles in SSR, but it never worked correctly. The layouts would get all distorted. I have added hasSider to all layout components and no effect. We are currently using inline styles as specified in the guides to get the styles to work.

However, this is not working all as expected either. We get this error when using the ConfigProvider in our app.

Warning: Prop `className` did not match. Server: "ant-layout-content css-dev-only-do-not-override-1g853jt" Client: "ant-layout-content css-dev-only-do-not-override-lzn4fh"
main

Also, the app does not get styled correctly in the first render; only once the context of the theme changes are the style changes applied.

Our current solution is using the NoSSR component to wrap the children of the ConfigProvider, effectively negating the use of SSR. This has been one of our biggest upsets about AntD when using it with Next.Js. 😞

@zcx992132258
Copy link

import React from 'react'
import { Inter } from 'next/font/google'
import { AntdRegistry } from '@ant-design/nextjs-registry'
import '@/assets/styles/index.scss'

const inter = Inter({ subsets: ['latin'] })

export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (


{children}


)
}

我是使用了antd的最新版本按照官网的写法来 但是还是出现了页面刷新抖动的现象 我还有什么需要注意的地方去避免这个抖动的发生吗
image

@annbeemsterboer
Copy link

i am encoutering the following error after upgrading next.js, antd and @ant-design/cssinjs

⨯ ./node_modules/antd/node_modules/classnames/index.js
Module parse failed: Cannot use 'import.meta' outside a module (93:16)
| // still a Refresh Boundary later.
| // @ts-ignore importMeta is replaced in the loader

            import.meta.webpackHot.accept();

| // This field is set when the previous version of this module was a
| // Refresh Boundary, letting us know we need to check for invalidation or

Import trace for requested module:
./node_modules/antd/node_modules/classnames/index.js
./node_modules/antd/es/date-picker/generatePicker/generateRangePicker.js
./node_modules/antd/es/date-picker/generatePicker/index.js
./node_modules/antd/es/date-picker/index.js
barrel_optimize?names=DatePicker!=!./node_modules/antd/es/index.js

package.json
"@ant-design/cssinjs": "1.18.4",
"antd": "5.14.1",
"next": "14.1.0",

next.config.js includes
transpilePackages: [ '@ant-design', 'rc-pagination', 'rc-picker', 'rc-util', 'antd', ],

what is causing this and does anyone have a solution?

@mxilievski
Copy link

mxilievski commented Feb 29, 2024

I'm trying to port my app to use the App Router, however the styles import order is wrong.

Reproduction code:

// layout.jsx

import { AntdRegistry } from '@ant-design/nextjs-registry';

export default function RootLayout({ children }) {
    return (
        <html lang="en">
        <body>
        <AntdRegistry>
            {children}
        </AntdRegistry>
        </body>
        </html>
    );
}
// page.jsx

import styles from './button.module.scss';

export default function AuditLog() {
    return <Button className={styles.button} type="primary">Primary Button</Button>;
};
// button.module.scss

.button {
  background: red;
}

The above code should make the button red, however AntdRegistry is appending the <style> tag at the end of <head> which is overriding the css code that I've provided in my component.
image

image

Versions used:
Antd 5.14.2
NextJS 14.1.0

@lapidus
Copy link

lapidus commented Mar 17, 2024

i am encoutering the following error after upgrading next.js, antd and @ant-design/cssinjs

⨯ ./node_modules/antd/node_modules/classnames/index.js Module parse failed: Cannot use 'import.meta' outside a module (93:16) | // still a Refresh Boundary later. | // @ts-ignore importMeta is replaced in the loader

Getting the same error. @annbeemsterboer did you find a fix? :)

@annbeemsterboer
Copy link

annbeemsterboer commented Mar 17, 2024

i am encoutering the following error after upgrading next.js, antd and @ant-design/cssinjs
⨯ ./node_modules/antd/node_modules/classnames/index.js Module parse failed: Cannot use 'import.meta' outside a module (93:16) | // still a Refresh Boundary later. | // @ts-ignore importMeta is replaced in the loader

Getting the same error. @annbeemsterboer did you find a fix? :)

to be honest i dont really know what did the trick, i started again from scratch and then it worked.

i have the suspicion it had to do with the next config for optimizePackageImports and transpilePackages, which i had adjusted in my earlier attempt.

for me it worked with this (partial) config:

// next.config.js
experimental: { optimizePackageImports: ['lodash', '@ant-design', 'antd'], }, transpilePackages: [ '@ant-design', 'antd', 'rc-pagination', 'rc-picker', 'rc-util', ],

i had to change imports for some of the types. i am using a custom setup with date-fns for the antd DatePicker. for example, in stead of importing from antd/es/date-picker/generatePicker, changed to antd/es/date-picker/generatePicker/interface.

not sure if any of this is helpful for you, this was for my setup :)

@lapidus
Copy link

lapidus commented Mar 17, 2024

not sure if any of this is helpful for you, this was for my setup :)

Thank you for taking the time to share @annbeemsterboer. Much appreciated. I’ll try it out :)

@phantomtet
Copy link

Re-exported Ant Design components don't have same style with the original components in Nextjs project
#47802

@mohammadgharouni
Copy link

not sure if any of this is helpful for you, this was for my setup :)

Thank you for taking the time to share @annbeemsterboer. Much appreciated. I’ll try it out :)

did u fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests