react: Edge 18 & IE 11 server mismatch with SVG icons
Do you want to request a feature or report a bug?
bug
What is the current behavior?
React raises a warning:

https://codesandbox.io/s/k91nr3xzy5
import React from "react";
export default () => (
<div>
2
<svg>
<path d="M0 0h24v24H0z" />
</svg>
</div>
);
What is the expected behavior?
No warning
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React: 16.8.4 Browser: Edge 18
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 27
- Comments: 20 (1 by maintainers)
In react v18.2.0, This problem still exists 😕
Same experience: react-icons, MUI, SSR in pages/ dir with NextJS 13.2.1 & React 18.2.0
I am on react@16.13.1 and it’s still a problem.
I was able to find a way to handle this:
code with context, if needed:
+1 with SVG icon exported from React component and rendered in NextJS
I am trying to use it in my
DarkMode.tsxwith Next.js & I face the same error:DarkMode.tsx
Edit: No worries. I wasn’t using
observerso that solved it 😃@gaearon It’s a shame I have only been contributing issues to the React project, in all these years. This issue is not very important. I doesn’t break the UI. It was more about moving an issue reported on Material-UI closer to its origin than anything else. Me working on #13838 could be more valuable for the community.
For anyone looking for a workaround for the time being, disabling hydration on inline SVG elements seems to do the trick. This obviously comes with downsides of its own, namely in that it’s only really applicable to static SVGs, but here’s the relevant TypeScript code for a component that disables hydration:
@gaearon IE, Edge do svg paths normalization. It’s similiar to
https://github.com/facebook/react/blob/b1a03dfdc8e42d075422556553ffe59868150e95/packages/react-dom/src/client/ReactDOMComponent.js#L141-L149
and can be archived in the same way. Any objections?