Skip to content

Antd theme is not working with nextjs module federation 8.1.0 and nextjs 14.1.4 #2317

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

Closed
5 tasks done
prakashmallow opened this issue Apr 12, 2024 · 6 comments
Closed
5 tasks done

Comments

@prakashmallow
Copy link

prakashmallow commented Apr 12, 2024

Describe the bug

When using Next.js v14.1.4 along with @module-federation/nextjs-mf v8.1.0, I encountered an issue with the Ant Design (Antd) theme configuration. In this setup, the root Next.js app successfully provides the theme changes to child Next.js apps. However, while the root Next.js app consumes the theme changes, the child Next.js app only displays the default theme without incorporating the Antd theme changes.

Tried with the combination of Nextjs version 13.4.7 and @module-federation/nextjs-mf v8.1.0, Next.js v14.1.4 and @module-federation/nextjs-mf v7.0.8. But it's not working.

As a workaround, I downgraded to Next.js version 13.4.7 and @module-federation/nextjs-mf v7.0.8. With this configuration, the Antd theme changes are functioning correctly on both the root and child Next.js apps.

Note:
the below two @module-federation/nextjs-mf working fine with Nextjs all versions
@module-federation/nextjs-mf v7.0.8
@module-federation/nextjs-mf v8.1.0

Reproduction

Demo link
Root app repository
Child app 1 respository
Child app 2 respository

Used Package Manager

yarn

System Info

Environment Info
antd 5.15.4
nextjs 14.1.4
React 18
@module-federation/nextjs-mf 8.1.0
System Mac
Browser Chrome latest version

Validations

@ScriptedAlchemy
Copy link
Member

Is this an issue on next 14 specifically?
have you tried sharing and/ instead of antd?

@prakashmallow
Copy link
Author

@ScriptedAlchemy This issue is not limited to Next.js version 14; it also occurs in version 13.4.8 and later. The Antd theme does not function properly with module-federation/nextjs-mf.

@ScriptedAlchemy
Copy link
Member

This is caused by nexts own optimize package imports / modularizeImports
https://nextjs.org/docs/app/api-reference/next-config-js/optimizePackageImports

Its not added to share scope at all.

You can try doing this:
import * as _ from 'antd'
Which seems to make it opt into the bundle.
You can also try exposing antd to force webpack to bundle it.

Not much we can do on our end. Next is incompatible with module federation

@prakashmallow
Copy link
Author

prakashmallow commented Jul 29, 2024

@ScriptedAlchemy
It's still not working. I think using the @ant-design/cssinjs package inside the app is the reason why this issue occurs. What do you think about this?

@ScriptedAlchemy
Copy link
Member

Yes. Share it and it works again.

@ericloritefcm
Copy link

Hello @prakashmallow, did you get it to work in the end? If you did, do you have the working version of the code? Thank you.

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

No branches or pull requests

3 participants