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

[Bug]: Next.js - Prop className did not match. #817

Closed
bombillazo opened this issue Sep 21, 2023 · 7 comments
Closed

[Bug]: Next.js - Prop className did not match. #817

bombillazo opened this issue Sep 21, 2023 · 7 comments
Labels

Comments

@bombillazo
Copy link
Contributor

Describe the bug

When using this lbrary and adding a class name to icons using the IconContext.Provider:

 <IconContext.Provider value={{ className: 'anticon' }}>

We get the following error on page load:

Warning: Prop `className` did not match. Server: "ant-menu-item-icon" Client: "anticon ant-menu-item-icon"

Expected behavior

No error is given.

Minimal sample repository URL

N/A

Steps To Reproduce

  1. Pass a custom className to the IconContest.
  2. Load a page.

Package version

v4.11.0

Relevant log output

Warning: Prop `className` did not match. Server: "ant-menu-item-icon" Client: "anticon ant-menu-item-icon"

Additional context

No response

@bombillazo bombillazo added the Bug label Sep 21, 2023
@bombillazo bombillazo changed the title [Bug]: Next.js [Bug]: Next.js - Prop className did not match. Sep 24, 2023
@ianujvarshney
Copy link

Dear ,

I'm Anuj Varshney, experienced in resolving such issues efficiently. Kindly assign it to me. I'll work diligently and keep you updated. Excited to contribute.

@Hachikoi-the-creator
Copy link

found a work around for this, in typescript it wont even allow the provider to exist, so just added a span whit the classes I need

<span className="text-red-500 text-9xl">
    <FaHotTub />
</span>

@bombillazo
Copy link
Contributor Author

found a work around for this, in typescript it wont even allow the provider to exist, so just added a span whit the classes I need

<span className="text-red-500 text-9xl">
    <FaHotTub />
</span>

Yeah.... Adding this to every instance of an icon component is not practical and pretty much defeats the purpose of the className prop and icon context 😔

@Hachikoi-the-creator
Copy link

@bombillazo I know, was pretty confused when I couldn't even use the IconContext, hope this helps someone tho
since this lib doesn´t seem to update anymore :c

@bombillazo
Copy link
Contributor Author

bombillazo commented Oct 20, 2023

@Hachikoi-the-creator I have a solution for this, though 😄

@kamijin-fanta Remember my PR #720 ? This issue is solved by allowing users to wrap icons with custom elements (like span in this case) to solve the issue caused by Next.js + React Icons. So it seems we have another use case for the PR.

@loczek
Copy link

loczek commented Oct 27, 2023

Adding react-icons to transpile packages inside next.config.js seems to fix the issue.

const nextConfig = {
  transpilePackages: ["react-icons"]
};

@bombillazo
Copy link
Contributor Author

Thanks @loczek , that worked!

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

No branches or pull requests

5 participants