chrvadala / react-svg-pan-zoom

:eyes: A React component that adds pan and zoom features to SVG
https://chrvadala.github.io/react-svg-pan-zoom/
MIT License
684 stars 126 forks source link

there is a warning at the start of rendering "Prop `id` did not match" #212

Open aseph8083 opened 2 years ago

aseph8083 commented 2 years ago

I'm using next js with typescript, when I start rendering a message appears

image

SmileHub commented 1 month ago

confirming, having the same warning when using with next.js:

Warning: Prop `id` did not match. Server: "react-svg-pan-zoom_miniature_mask_uid1" Client: "react-svg-pan-zoom_miniature_mask_uid2" Error Component Stack
    at mask (<anonymous>)
    at defs (<anonymous>)
    at g (<anonymous>)
    at MiniatureMask (miniature-mask.js:13:5)
    at RandomUID (RandomUID.js:16:7)
    at g (<anonymous>)
    at g (<anonymous>)
    at svg (<anonymous>)
    at div (<anonymous>)
    at Miniature (miniature.js:22:5)
    at div (<anonymous>)
    at ReactSVGPanZoom (viewer.js:57:14)
    at UncontrolledReactSVGPanZoom (uncontrolled-viewer.js:21:5)

a temporary work around on next.js is to avoid using SSR on this component till it's fixed. Since i'm having it wrapped with ReactSvgPanZoomLoader, so i'm just setting it up without SSR

import dynamic from 'next/dynamic';
const ReactSvgPanZoomLoader = dynamic(() => import('react-svg-pan-zoom-loader').then(mod => mod.ReactSvgPanZoomLoader), { ssr: false });

my code:

    <ReactSvgPanZoomLoader src="/map.svg" render={(content) => (
                <UncontrolledReactSVGPanZoom
                    ref={Viewer}
                    width={500}
                    height={500}
                    onZoom={e => console.log('zoom')}
                    onPan={e => console.log('pan')}
                    onClick={event => console.log('click', event.x, event.y, event.originalEvent)}
                    toolbarProps={toolbarProps}
                    miniatureProps={miniatureProps}
                >
                    <svg width={500} height={500}>
                        {content}
                    </svg>
                </UncontrolledReactSVGPanZoom>
        )} />
    </div>;