-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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: NextJS and svg-core cause server and client hydration errors #19348
Comments
I had the same error, and what I did is to change the import to require js, like this:
|
Sorry, I do not know NextJS. As far as I can tell, it is a framework based on React If this is the case, then the react-fontawesome component component is required to make font awesome work So I'm asking if there is there, by any chance, an answer to this issue on the react-fontawesome repository at https://github.com/FortAwesome/react-fontawesome/ or if this issue belongs to there |
Same problem here. The |
Any chance to have a test case with the minimum amount of code and dependencies to reproduce this issue hosted on a publicly accessible GitHub repo? edit: ok sorry it's in the first post |
@robmadole could you please take a look or reassign to the most suitable person? |
Ok. I think this is related to FortAwesome/react-fontawesome#525. My guess is that the Library singleton is not working correctly with SSR. We'd need to involve the Next.js folks in order to figure this out probably. I'd recommend the workaround of avoiding the import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faBars } from '@fortawesome/free-solid-svg-icons';
export default function Home() {
return <>
<FontAwesomeIcon icon={faBars} fixedWidth color="black" />
</>;
} |
@robmadole yeah that's just a lot of work for an already existing codebase! I'm going to try the require way a bit later and report back if it works Thank you for your input! Much appreciated |
@tm1000 yeah that |
The latest version of NextJS ( |
I was having this same issue when upgrading to |
I'm still experiencing this issue in NextJS |
Agreed same issue. Next 13.03. require fixed but seems hacky |
Also experienced the same issue using Next 13 and FA 6.2.0. Require seems to do the trick although not ideal. |
Any update on this? |
I had to use this solution to get it working. |
Nuxt.js 3 got the same issue Got error:
|
Using NextJS 13.4.8 and FontAwesome 6.4.2 and the "require" workaround is not working for me. Any other ideas? |
try using the solution above from @robmadole, worked for me
|
Thanks @dan2kx, unfortunately that's how I have it configured. I might have some complicating factors such as lazy loading components that could be affecting this. I was able to avoid the error by using |
any update? |
Facing this same issue—also using the App Router from Next.js. |
You may try this approach if you have the topic issue App.jsx
import { library } from '@fortawesome/fontawesome-svg-core';
import { fas } from '@fortawesome/free-solid-svg-icons';
import { far } from '@fortawesome/free-regular-svg-icons';
library.add(far, fas);
Icon.jsx
import { findIconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
const faIconPrefix = {
regular: 'far',
solid: 'fas',
};
const Icon = ({ name, type = 'regular' }) => {
const iconLookup = { prefix: faIconPrefix[type], iconName: name };
const iconDefinition = findIconDefinition(iconLookup);
return (
<FontAwesomeIcon icon={iconDefinition} />
);
};
export default Icon;
Usage:
<Icon name="shopping-bag" />
**NOTE**
By this approach you will import all of the icons and they will be included in the initial bundle.
In my case i have CMS and i need them at app boot, but you may just simply need to import each icon separately and use it as follows :
import { faHouse } from '@fortawesome/free-solid-svg-icons';
<FontAwesomeIcon icon={faHouse} /> |
Any fix for this with Next 14? |
Facing the same issue when using vike + Vue:
Currently solved by importing icons directly: |
Bug description
This is actually similar to #19193 and it might entirely be the same issue (or related). After following https://fontawesome.com/v6/docs/web/dig-deeper/svg-core and https://fontawesome.com/v6/docs/web/use-with/react/use-with I continue to get hydration errors since upgrading to react 18. I've narrowed this down to svg-core not working properly in SSR mode and I've attached a repo that is easy to download and install and demonstrates the error at hand.
Reproducible test case
https://github.com/tm1000/fontawesome-bug
Screenshots
Font Awesome version
v6.2.0
Serving
Self-hosted
Implementation
SVG+JS
Browser and Operating System
Web bug report checklist
The text was updated successfully, but these errors were encountered: