Comments (8)
Thanks for reporting!
Fixed in version 2.0.0-rc.6
from iconify.
@cyberalien I'm still seeing the same SSR warning on 2.0.0-rc.6
Here is a link to a minimal reproduction
You can start the server with npm run dev
When visiting localhost:3000
you will see the warning
react-dom.development.js?61bb:67 Warning: Prop `dangerouslySetInnerHTML` did not match. Server: "<defs><linearGradient x1=\"50%\" y1=\"0%\" x2=\"50%\" y2=\"100%\" id=\"iconify-react-id-6\"><stop stop-color=\"#FFF\" offset=\"0%\"></stop><stop stop-color=\"#FFF\" stop-opacity=\"0\" offset=\"100%\"></stop></linearGradient><path d=\"M180.828 252.605a15.872 15.872 0 0 0 12.65-.486l52.501-25.262a15.94 15.94 0 0 0 9.025-14.364V41.197a15.939 15.939 0 0 0-9.025-14.363l-52.5-25.263a15.877 15.877 0 0 0-18.115 3.084L74.857 96.35l-43.78-33.232a10.614 10.614 0 0 0-13.56.603L3.476 76.494c-4.63 4.211-4.635 11.495-.012 15.713l37.967 34.638l-37.967 34.637c-4.623 4.219-4.618 11.502.012 15.714l14.041 12.772a10.614 10.614 0 0 0 13.56.604l43.78-33.233l100.507 91.695a15.853 15.853 0 0 0 5.464 3.571zm10.464-183.649l-76.262 57.889l76.262 57.888V68.956z\" id=\"iconify-react-id-7\"></path></defs><mask id=\"iconify-react-id-8\" fill=\"#fff\"><use xlink:href=\"#iconify-react-id-7\"></use></mask><path d=\"M246.135 26.873L193.593 1.575a15.885 15.885 0 0 0-18.123 3.08L3.466 161.482c-4.626 4.219-4.62 11.502.012 15.714l14.05 12.772a10.625 10.625 0 0 0 13.569.604L238.229 33.436c6.949-5.271 16.93-.315 16.93 8.407v-.61a15.938 15.938 0 0 0-9.024-14.36z\" fill=\"#0065A9\" mask=\"url(#iconify-react-id-8)\"></path><path d=\"M246.135 226.816l-52.542 25.298a15.887 15.887 0 0 1-18.123-3.08L3.466 92.207c-4.626-4.218-4.62-11.502.012-15.713l14.05-12.773a10.625 10.625 0 0 1 13.569-.603l207.132 157.135c6.949 5.271 16.93.315 16.93-8.408v.611a15.939 15.939 0 0 1-9.024 14.36z\" fill=\"#007ACC\" mask=\"url(#iconify-react-id-8)\"></path><path d=\"M193.428 252.134a15.892 15.892 0 0 1-18.125-3.083c5.881 5.88 15.938 1.715 15.938-6.603V11.273c0-8.318-10.057-12.483-15.938-6.602a15.892 15.892 0 0 1 18.125-3.084l52.533 25.263a15.937 15.937 0 0 1 9.03 14.363V212.51c0 6.125-3.51 11.709-9.03 14.363l-52.533 25.262z\" fill=\"#1F9CF0\" mask=\"url(#iconify-react-id-8)\"></path><path d=\"M180.828 252.605a15.874 15.874 0 0 0 12.65-.486l52.5-25.263a15.938 15.938 0 0 0 9.026-14.363V41.197a15.939 15.939 0 0 0-9.025-14.363L193.477 1.57a15.877 15.877 0 0 0-18.114 3.084L74.857 96.35l-43.78-33.232a10.614 10.614 0 0 0-13.56.603L3.476 76.494c-4.63 4.211-4.635 11.495-.012 15.713l37.967 34.638l-37.967 34.637c-4.623 4.219-4.618 11.502.012 15.714l14.041 12.772a10.614 10.614 0 0 0 13.56.604l43.78-33.233l100.506 91.695a15.857 15.857 0 0 0 5.465 3.571zm10.464-183.65l-76.262 57.89l76.262 57.888V68.956z\" fill-opacity=\".25\" fill=\"url(#iconify-react-id-6)\" mask=\"url(#iconify-react-id-8)\"></path>" Client: "<defs><linearGradient x1=\"50%\" y1=\"0%\" x2=\"50%\" y2=\"100%\" id=\"iconify-react-id-0\"><stop stop-color=\"#FFF\" offset=\"0%\"></stop><stop stop-color=\"#FFF\" stop-opacity=\"0\" offset=\"100%\"></stop></linearGradient><path d=\"M180.828 252.605a15.872 15.872 0 0 0 12.65-.486l52.501-25.262a15.94 15.94 0 0 0 9.025-14.364V41.197a15.939 15.939 0 0 0-9.025-14.363l-52.5-25.263a15.877 15.877 0 0 0-18.115 3.084L74.857 96.35l-43.78-33.232a10.614 10.614 0 0 0-13.56.603L3.476 76.494c-4.63 4.211-4.635 11.495-.012 15.713l37.967 34.638l-37.967 34.637c-4.623 4.219-4.618 11.502.012 15.714l14.041 12.772a10.614 10.614 0 0 0 13.56.604l43.78-33.233l100.507 91.695a15.853 15.853 0 0 0 5.464 3.571zm10.464-183.649l-76.262 57.889l76.262 57.888V68.956z\" id=\"iconify-react-id-1\"></path></defs><mask id=\"iconify-react-id-2\" fill=\"#fff\"><use xlink:href=\"#iconify-react-id-1\"></use></mask><path d=\"M246.135 26.873L193.593 1.575a15.885 15.885 0 0 0-18.123 3.08L3.466 161.482c-4.626 4.219-4.62 11.502.012 15.714l14.05 12.772a10.625 10.625 0 0 0 13.569.604L238.229 33.436c6.949-5.271 16.93-.315 16.93 8.407v-.61a15.938 15.938 0 0 0-9.024-14.36z\" fill=\"#0065A9\" mask=\"url(#iconify-react-id-2)\"></path><path d=\"M246.135 226.816l-52.542 25.298a15.887 15.887 0 0 1-18.123-3.08L3.466 92.207c-4.626-4.218-4.62-11.502.012-15.713l14.05-12.773a10.625 10.625 0 0 1 13.569-.603l207.132 157.135c6.949 5.271 16.93.315 16.93-8.408v.611a15.939 15.939 0 0 1-9.024 14.36z\" fill=\"#007ACC\" mask=\"url(#iconify-react-id-2)\"></path><path d=\"M193.428 252.134a15.892 15.892 0 0 1-18.125-3.083c5.881 5.88 15.938 1.715 15.938-6.603V11.273c0-8.318-10.057-12.483-15.938-6.602a15.892 15.892 0 0 1 18.125-3.084l52.533 25.263a15.937 15.937 0 0 1 9.03 14.363V212.51c0 6.125-3.51 11.709-9.03 14.363l-52.533 25.262z\" fill=\"#1F9CF0\" mask=\"url(#iconify-react-id-2)\"></path><path d=\"M180.828 252.605a15.874 15.874 0 0 0 12.65-.486l52.5-25.263a15.938 15.938 0 0 0 9.026-14.363V41.197a15.939 15.939 0 0 0-9.025-14.363L193.477 1.57a15.877 15.877 0 0 0-18.114 3.084L74.857 96.35l-43.78-33.232a10.614 10.614 0 0 0-13.56.603L3.476 76.494c-4.63 4.211-4.635 11.495-.012 15.713l37.967 34.638l-37.967 34.637c-4.623 4.219-4.618 11.502.012 15.714l14.041 12.772a10.614 10.614 0 0 0 13.56.604l43.78-33.233l100.506 91.695a15.857 15.857 0 0 0 5.465 3.571zm10.464-183.65l-76.262 57.89l76.262 57.888V68.956z\" fill-opacity=\".25\" fill=\"url(#iconify-react-id-0)\" mask=\"url(#iconify-react-id-2)\"></path>"
at svg
at eval (webpack-internal:///./node_modules/@iconify/react/dist/icon.esm.js:741:99)
at main
at div
at Home
at MyApp (webpack-internal:///./pages/_app.js:18:24)
at ErrorBoundary (webpack-internal:///./node_modules/@next/react-dev-overlay/lib/internal/ErrorBoundary.js:23:47)
at ReactDevOverlay (webpack-internal:///./node_modules/@next/react-dev-overlay/lib/internal/ReactDevOverlay.js:73:23)
at Container (webpack-internal:///./node_modules/next/dist/client/index.js:149:5)
at AppContainer (webpack-internal:///./node_modules/next/dist/client/index.js:637:24)
at Root (webpack-internal:///./node_modules/next/dist/client/index.js:768:24)
from iconify.
Looking at the changes, the issue is with the global counter variable. This issue may help explain why you cannot a global counter variable when generating ids for SSR.
I think most users who are doing SSR will already have a solution to generate unique ids (as they are needed for aria, labels, etc). It might be easier to just allow the user to provide an id override.
from iconify.
That reproduction repo does help a lot. Thanks!
I think this problem cannot be solved in component. There is no way to reset variable on each page render. On first page render ids match, but then it all goes wrong.
Idea about optional property for unique ids is good. What if I add an optional property uuid
, which is a function that returns unique id?
from iconify.
You can just call the prop id
as the term id
in html already means "unique for this document".
from iconify.
Added property id
, which is a string. That id will be used for SVG element and used as base for ids for shapes inside it, starting counter with 0 on each render, so it is reliable.
Tested with your repo by adding id to icon: <Icon icon={visualStudioCode} width={50} id="vscode" />
. It reliably renders same ids on server and on client.
Please test 2.0.0-rc.7
. I think it solves issue.
from iconify.
Seems to work well 👍
from iconify.
Adding ids to all icons could be not simple if icons are used inside component that can be displayed multiple times on page, so I came up with a better solution.
In version 3.0.0-dev
(had to rewrite whole component because passing references was impossible with old code), component loads icon data only when it is mounted, so initially component renders empty placeholder (or children nodes if you set any).
This solves problem of conflicting ids because there are no ids generated on server.
from iconify.
Related Issues (20)
- ESM import issues HOT 6
- please add information about attribute `observer` and `noobserver` in the offcial site document HOT 1
- How do you guarantee icons don't change HOT 3
- Iconify - Definitely the easiest! Why not the fastest? HOT 6
- Feature Request: A SDK to pick icons
- Show API link for icons HOT 2
- Tailwind plugin: allow non-square icons HOT 1
- [@iconify-icon/react] Not show in next-app-dir HOT 1
- When I want to achieve offline on-demand loading need to use the icon, when packaged online, there will be some icons appear, some icons do not appear HOT 3
- Add "Atlas Icons" set HOT 6
- Consider supporting root attributes for icons in JSON format HOT 1
- Nuxt Error while using @iconify-json/fluent-emoji HOT 2
- Add "Iconsax" set HOT 1
- error import cheerio HOT 3
- once the animation done it doesnt restart HOT 5
- Imports with "assert" keyword are not supported anymore HOT 5
- Solid start error HOT 1
- [BUG?] @iconify/utils `getIconCss` does not respect transformations HOT 1
- Vite build warning with `@iconify/tailwind` package HOT 2
- Add doodle icons
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iconify.