Migration Guide
Ant Design released a new major version as a v5. This document will help you upgrade from antd 4.x version to antd 5.x version.
Ant Design removed less
and adopt CSS-in-JS
, for better support of dynamic themes. The bottom layer uses @ant-design/cssinjs
as a solution.
Some components are removed or renamed, and some APIs are changed.
Some of the changes are:
<PageHeader>
component moved into@ant-design/pro-components
. refine is using<PageHeader>
in<List>
,<Create>
,<Edit>
,<Show>
components and added as a dependency. You don't need to install@ant-design/pro-components
package manually.<Comment>
component moved into@ant-design/compatible
.moment.js
is replaced withday.js
.less
is removed fromantd
package.
Please refer to Ant Design Migration Guide for detailed information.
refine package | Ant Design version |
---|---|
@pankod/refine-antd@3.x.x | antd@4.x.x |
@pankod/refine-antd@4.x.x | antd@5.x.x |
Updating the packagesβ
@pankod/refine-antd
must be updated to 4.x.x
- refine CLI
- Manual
npm i @pankod/refine-antd@latest
πͺ Migrating your project automatically with Codemod β¨ (recommended)β
@pankod/refine-codemod
package handles the breaking changes for your project automatically, without any manual steps. It migrates your @pankod/refine-antd
version from 3.x.x to 4.x.x.
Just cd
into root folder of your project (where package.json
is contained) and run this command:
npx @pankod/refine-codemod antd4-to-antd5
And it's done. Now your project uses @pankod/refine-antd@4.x.x
.
π¨ Customized or swizzled components and .less files cannot be migrated automatically. You need to migrate them manually.
Migrating your project manuallyβ
Updating Importsβ
- CSS files are no longer included in package. Since CSS-in-JS supports importing on demand, the original
styles/antd.less
has also been abandoned. If you need to reset some basic styles, please import@pankod/refine-antd/dist/reset.css
- import "@pankod/refine-antd/dist/styles.min.css";
+ import "@pankod/refine-antd/dist/reset.css";
Updating Propsβ
actionButtons
and pageHeaderProps
props was deprecated on @pankod/refine-antd@3.x.x
and removed on @pankod/refine-antd@4.x.x
from <List>
, <Create>
, <Edit>
, <Show>
component due to incosistency with all UI packages. Use headerButtons
and headerProps
props instead.
- <List actionButtons={actionButtons} pageHeaderProps={pageHeaderProps}>
+ <List headerButtons={actionButtons} headerProps={pageHeaderProps}>
- <Create actionButtons={actionButtons} pageHeaderProps={pageHeaderProps}>
+ <Create headerButtons={actionButtons} headerProps={pageHeaderProps}>
- <Show actionButtons={actionButtons} pageHeaderProps={pageHeaderProps}>
+ <Show headerButtons={actionButtons} headerProps={pageHeaderProps}>
- <Edit actionButtons={actionButtons} pageHeaderProps={pageHeaderProps}>
+ <Edit headerButtons={actionButtons} headerProps={pageHeaderProps}>
Customized <Sider>
β
If you have customized or swizzled
the <Sider>
component, there may be a color mismatch issue.
You can give theme dark to the <Menu>
component in the <Sider>
component.
<AntdLayout.Sider
collapsible
collapsed={collapsed}
onCollapse={(collapsed: boolean): void => setCollapsed(collapsed)}
collapsedWidth={isMobile ? 0 : 80}
breakpoint='lg'
style={isMobile ? antLayoutSiderMobile : antLayoutSider}>
<RenderToTitle collapsed={collapsed} />
<Menu
+ theme='dark'
selectedKeys={[selectedKey]}
defaultOpenKeys={defaultOpenKeys}
mode='inline'
onClick={() => {
if (!breakpoint.lg) {
setCollapsed(true)
}
}}>
{renderSider()}
</Menu>
</AntdLayout.Sider>
Customized <Header>
β
If you have customized or swizzled
the <Header>
component, there may be a color mismatch issue.
You can remove constant background color in <Header>
component.
<AntdLayout.Header
style={{
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'center',
padding: '0px 24px',
height: '64px',
- backgroundColor: '#FFF',
}}>
LESS Usersβ
Ant Design removed less
, uses and recommends CSS-in-JS
instead. You need to manually migrate your .less
files to CSS-in-JS
. Ant Design's documentation for less migration.
Known Issuesβ
Compile errorsβ
Some users repored (issue#1, issue#2) compile errors after upgrading from @pankod/refine-antd@3.x.x
to @pankod/refine-antd@4.x.x
. They also provided solutions.
Solution 1β
- remove
node_modules
folder - remove
package-lock.json
file npm install
Solution 2β
npm install react@latest react-dom@latest