Git Product home page Git Product logo

Comments (8)

cyberalien avatar cyberalien commented on May 31, 2024

Thanks for reporting!

Fixed in version 2.0.0-rc.6

from iconify.

marklawlor avatar marklawlor commented on May 31, 2024

@cyberalien I'm still seeing the same SSR warning on 2.0.0-rc.6

Here is a link to a minimal reproduction

Code for the Icon is here

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.

marklawlor avatar marklawlor commented on May 31, 2024

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.

cyberalien avatar cyberalien commented on May 31, 2024

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.

marklawlor avatar marklawlor commented on May 31, 2024

You can just call the prop id as the term id in html already means "unique for this document".

from iconify.

cyberalien avatar cyberalien commented on May 31, 2024

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.

marklawlor avatar marklawlor commented on May 31, 2024

Seems to work well 👍

from iconify.

cyberalien avatar cyberalien commented on May 31, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.