-
Notifications
You must be signed in to change notification settings - Fork 46k
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
hydrate SVG error: Expected server HTML to contain a matching <clipPath> in <svg> #17741
Comments
So this is a snippet of the svg that I'm trying to render.
it looks like the |
I'm seeing a similar issue, also with Next but it's probably a ReactDOM thing rather than Next. I believe React isn't properly diffing the path element in an SVG. Here's a minimum reproducible example: https://codesandbox.io/s/next-not-updaing-svg-path-xl1u4 In the above example, one would expect the red circle to be rendered on the server but then be updated to the blue square when it's rendered on the client, but that doesn't happen. Note, there is also a warning in the console: |
Yeah, I bet these are similar problems. I'm trying to pick through some of the code for |
actually @davidgolden I think the example you provided there is different. The error makes more sense in your example. You're trying to render something different during buildtime and runtime, in my case it should be rendering the same thing at both times. |
I may be mistaken but this line suggests that Btw, I do not have a repo for this but I just created a custom SSR app using webpack, babel, and SVGR loader. Everything seems to be working fine. I am going to try to use |
I have tested your code in the following scenarios:
It seems to be working in all the cases. I am not able to reproduce the bug that you have. Please provide an example where this bug can be reproduced. |
@benbot @GasimGasimzada I just cloned your repo and was also unable to reproduce following the steps you provided. However I also don't see a clipPath in your SVG, so maybe you changed something? You're right that we have different issues, sorry about that - I'll open separately. |
@davidgolden @GasimGasimzada Let me run through the steps again. Maybe i knocked something over when i made the branch, but before all i had to do was run Also it's not in the raw svg. The babel-inline-react-svg plugin does some modification and minification of the svg. |
I had the same issue and solved it with a {hasMounted && storedTheme === "dark" ? (
<Button onClick={handleTheme}>
<Sun />
</Button>
) : (
<Button onClick={handleTheme}>
<Moon />
</Button>
)} import {useEffect, useState} from "react"
const useHasMounted = () => {
const [hasMounted, setHasMounted] = useState(false)
useEffect(() => {
setHasMounted(true)
}, [])
return hasMounted
}
export default useHasMounted |
The original example is gone so I can't check it. #17741 (comment) is not a supported way to use React. It is not supported to have conditions like A possible way to fix it is to make server output identical but use CSS to hide/show appropriate icon. Then set the CSS class in an inline |
Thanks, man! You saved my a$$ |
This fixes it, but, the icon will show after the first render, which is not ideal |
good solution but the problem it's render the view after all thing are render which looks weired |
@masiucd good stuff! |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
It seems like
ReactDOM.hydrate
doesn't play nice with certain kinds of inline SVGs.Specifically ones that have
clipPath
sWhen nextjs tries calling hydrate on a page with one of these SVGs, the offending part of the svg flashes quickly then react throws this error to the console.
I have a very small example of this happening here https://github.com/Delray-Devs/site/tree/brokenSVG
The strange part is when next builds the site statically it all works.
I originally opened this issue on zeit/nextjs, but @timneutkens suggested I open the issue here.
See vercel/next.js#9871 for all the details.
What is the expected behavior?
The SVG containing the
clipPath
gets rendered correctly on the client side.Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React: 16.12, not sure about previous versions
Browser: Firefox and Chrome
OS: macOS
The text was updated successfully, but these errors were encountered: