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

Edge 18 & IE 11 server mismatch with SVG icons #15187

Open
oliviertassinari opened this issue Mar 21, 2019 · 20 comments
Open

Edge 18 & IE 11 server mismatch with SVG icons #15187

oliviertassinari opened this issue Mar 21, 2019 · 20 comments

Comments

@oliviertassinari
Copy link
Contributor

Do you want to request a feature or report a bug?

bug

What is the current behavior?

React raises a warning:

Capture d’écran 2019-03-22 à 00 40 00

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

@gaearon
Copy link
Collaborator

gaearon commented Mar 22, 2019

Wanna send a fix?

@oliviertassinari
Copy link
Contributor Author

oliviertassinari commented Mar 22, 2019

@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.

@StarpTech
Copy link

StarpTech commented Sep 9, 2019

@gaearon IE, Edge do svg paths normalization. It's similiar to

// IE 11 parses & normalizes the style attribute as opposed to other
// browsers. It adds spaces and sorts the properties in some
// non-alphabetical order. Handling that would require sorting CSS
// properties in the client & server versions or applying
// `expectedStyle` to a temporary DOM node to read its `style` attribute
// normalized. Since it only affects IE, we're skipping style warnings
// in that browser completely in favor of doing all that work.
// See https://github.com/facebook/react/issues/11807
canDiffStyleForHydrationWarning = canUseDOM && !document.documentMode;

and can be archived in the same way. Any objections?

@stale
Copy link

stale bot commented Jan 10, 2020

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.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@stale
Copy link

stale bot commented Jan 17, 2020

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!

@stale stale bot closed this as completed Jan 17, 2020
@gaearon gaearon reopened this Apr 1, 2020
@stale stale bot removed the Resolution: Stale Automatically closed due to inactivity label Apr 1, 2020
@licg9999
Copy link

image
Hi? Is this issue resolved? I can still replay this problem on react 16.12.0 😳

@CrossTheDev
Copy link

I am on react@16.13.1 and it's still a problem.

@joshuambg
Copy link

Still a problem.
Windows 10
IE 11
"react": "^16.11.0"

@deadcoder0904
Copy link

deadcoder0904 commented Jun 15, 2021

I am trying to use it in my DarkMode.tsx with Next.js & I face the same error:

react_devtools_backend.js:2560 Warning: Prop d did not match. Server: "M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" Client: "M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"
at path
at svg
at MoonIcon
at button
at div
at DarkMode

DarkMode.tsx

import { 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 observer so that solved it :)

@Nzent
Copy link

Nzent commented Aug 25, 2021

image

Still getting this error on Next.js + Tailwind dark mode 😟

@mustafamoe
Copy link

me too :/

Screenshot from 2021-09-15 03-48-59

@ivosabev
Copy link

+1 with SVG icon exported from React component and rendered in NextJS

@slbls
Copy link

slbls commented Nov 19, 2021

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>
	);
};

@EbrahimHeydari
Copy link

In react v18.2.0, This problem still exists 😕

@omer-os
Copy link

omer-os commented Feb 9, 2023

same issue with nextjs 13 and lastest version of reactjs

@faeb187
Copy link

faeb187 commented Feb 24, 2023

Same experience: react-icons, MUI, SSR in pages/ dir with NextJS 13.2.1 & React 18.2.0

@xjahic
Copy link

xjahic commented Mar 12, 2023

I had this problem and upgrading mui to v5 fixed the problem.

  "@emotion/core": "^11.0.0",
  "@emotion/react": "^11.10.6",
  "@emotion/server": "^11.10.0",
  "@emotion/styled": "^11.10.6",
  "@mui/icons-material": "^5.11.11",
  "@mui/material": "^5.11.11",
  "@mui/styles": "^5.11.11",
"next": "12.3.1",
"react": "18.2.0",

@hson194
Copy link

hson194 commented Oct 20, 2023

Same issue to me

    "@types/react": "18.2.0",
    "@types/react-dom": "18.2.1",
    "@vercel/analytics": "^1.0.0",
    "autoprefixer": "10.4.14",
    "contentlayer": "^0.3.2",
    "eslint": "8.39.0",
    "eslint-config-next": "13.3.1",
    "next": "13.4.1",

@dbonates
Copy link

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>
  )
}

@isaacdarcilla
Copy link

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!

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

No branches or pull requests