-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Edge 18 & IE 11 server mismatch with SVG icons #15187
Comments
Wanna send a fix? |
@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. |
@gaearon IE, Edge do svg paths normalization. It's similiar to react/packages/react-dom/src/client/ReactDOMComponent.js Lines 141 to 149 in b1a03df
and can be archived in the same way. Any objections? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution. |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you! |
I am on react@16.13.1 and it's still a problem. |
Still a problem. |
I am trying to use it in my
DarkMode.tsximport { MoonIcon, SunIcon } from '@heroicons/react/solid'
import { useStore } from '@/store/index'
export const DarkMode = () => {
const { theme, setTheme } = useStore()
return (
<div className="cursor-pointer">
{theme === 'dark' && (
<button
className="focus:outline-none"
title="Activate light mode"
onClick={() => {
console.log(theme)
setTheme('light')
}}
>
<MoonIcon className="w-8 h-8" />
</button>
)}
{theme === 'light' && (
<button
className="focus:outline-none"
title="Activate dark mode"
onClick={() => {
setTheme('dark')
}}
>
<SunIcon className="w-8 h-8" />
</button>
)}
</div>
)
} Edit: No worries. I wasn't using |
+1 with SVG icon exported from React component and rendered in NextJS |
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: import {
FC,
HTMLProps,
ReactNode,
useEffect,
useLayoutEffect,
useReducer,
useRef
} from "react";
type NoHydrationProps = {
readonly children: ReactNode;
readonly parent?: keyof JSX.IntrinsicElements;
} & Omit<HTMLProps<HTMLElement>, "dangerouslySetInnerHTML">;
const reducer = () => true;
const isBrowser = typeof window !== "undefined";
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect;
export const NoHydration = ({
children,
parent = "div",
...props
}: NoHydrationProps) => {
const ref = useRef<HTMLElement>(null);
const [isHydrated, hydrate] = useReducer(reducer, !isBrowser);
useIsomorphicLayoutEffect(() => {
if (ref.current?.hasChildNodes()) {
return;
}
hydrate();
}, []);
const ParentElement = parent as unknown as FC<HTMLProps<HTMLElement>>;
if (!isHydrated) {
return (
<ParentElement
ref={ref}
suppressHydrationWarning
dangerouslySetInnerHTML={{ __html: "" }}
{...props}
/>
);
}
return (
<ParentElement
ref={ref}
// `display: contents` ensures the parent element does not produce
// a CSS box for itself, seeing as the parent is only needed for the
// purpose of preventing client-side hydration of the children.
style={{ display: "contents" }}
{...props}
>
{children}
</ParentElement>
);
}; |
In react v18.2.0, This problem still exists 😕 |
same issue with nextjs 13 and lastest version of reactjs |
Same experience: react-icons, MUI, SSR in pages/ dir with NextJS 13.2.1 & React 18.2.0 |
I had this problem and upgrading mui to v5 fixed the problem.
|
Same issue to me
|
I was able to find a way to handle this: <Button variant="ghost" size="sm" onClick={() => { setTheme(theme === "light" ? "dark" : "light") }}>
{loaded ?
(theme === "light" ? <MoonIcon /> : <SunIcon />)
: (<span className="animate-pulse">...</span>)
}
</Button> code with context, if needed: 'use client'
import React, { useEffect, useState } from 'react'
import { useTheme } from "next-themes"
import { Button } from "@/components/ui/button"
import { SunIcon, MoonIcon } from "@/components/ui/icons"
export default function NavBar() {
const { theme, setTheme } = useTheme()
const [loaded, setLoaded] = useState(false);
useEffect(() => {
setLoaded(true);
}, [setLoaded]);
return (
<div className='flex items-center fixed top-0 left-0 right-0'>
<div className='px-3'>Bonates.com</div>
<div className='flex-grow' />
<Button variant="ghost" size="sm" onClick={() => { setTheme(theme === "light" ? "dark" : "light") }}>
{loaded ?
(theme === "light" ? <MoonIcon /> : <SunIcon />)
: (<span className="animate-pulse">...</span>)
}
</Button>
</div>
)
} |
This works, thank you! |
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
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
The text was updated successfully, but these errors were encountered: