Git Product home page Git Product logo

Comments (24)

astandrik avatar astandrik commented on September 28, 2024 3

Now everything works great. Thanks for your efforts!

from react-svg.

viniychuk avatar viniychuk commented on September 28, 2024 1

@tanem Thanks so much, it works like a charm now!

from react-svg.

nikoskleidis avatar nikoskleidis commented on September 28, 2024

Probably implementing shouldComponentUpdate would prevent this from happening. In my case I wrapped the component with another component that ensures the component is only updated when its props change.

from react-svg.

tanem avatar tanem commented on September 28, 2024

@mikeriley131 see if the latest version (> 2.02) solves your issue? (Commit e946dc2).

from react-svg.

Marc90521 avatar Marc90521 commented on September 28, 2024

Still an issue here on 2.1.1 Updates of the path based on props causes this issue.
return <ReactSVG path={this.props.path} className={'example'} />

from react-svg.

tanem avatar tanem commented on September 28, 2024

Thanks for that extra info @Montaldo. I've got an idea of what changes I need to make, so once they're done I'll let you know.

from react-svg.

tanem avatar tanem commented on September 28, 2024

@mikeriley131 @nikoskleidis @Montaldo

Just published 2.1.2 to address this issue... let me know how you get on with it?

from react-svg.

viniychuk avatar viniychuk commented on September 28, 2024

Hi @tanem, thanks a lot for creating and supporting your nifty package!

I use it for toolbar icons and want icon to change color when it's "active". I can set fill="currentColor" in SVG file and then use style property to set the color from the outside. It almost worked in 2.1.1, but I was getting pretty much the same error as @mikeriley131 . With the latest update it throws an error when I use style property to change color (I checked v2.1.2 - v2.1.6).

I use react and react-dom v15.4.1

Simple test to run:

              <div onClick={() => this.setState({active: !this.state.active})}>
                    <ReactSVG path={alignmentLeftIcon} style={{color: this.state.active ? "#a33" : "#000"}}/>
                </div>

Error:

ReactDOMComponentTree.js:106 Uncaught TypeError: Cannot read property '__reactInternalInstance$5fa40ba6ejyiw56gatgkhgp66r' of null
    at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:106)
    at findParent (ReactEventListener.js:38)
    at handleTopLevelImpl (ReactEventListener.js:67)
    at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:140)
    at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
    at Object.batchedUpdates (ReactUpdates.js:97)
    at dispatchEvent (ReactEventListener.js:147)

from react-svg.

tanem avatar tanem commented on September 28, 2024

Thanks @viniychuk. Think I can fix this by moving more of the DOM manipulation away from React. Will repost when I've got something working ⌛️

from react-svg.

tanem avatar tanem commented on September 28, 2024

@viniychuk just released 2.1.10 - want to see if that fixes your issue?

from react-svg.

duro avatar duro commented on September 28, 2024

@tanem I'm still getting this error in 2.1.10

Here is what my component definition looks like:

<ReactSVG
  key={0}
  path="/static/media/refesh-icon.2b18acf8.svg"
  evalScripts="never"
  className="Button__icon"
/>

from react-svg.

duro avatar duro commented on September 28, 2024

Actually, maybe mine is a little different. The call stack is different, but similar:

Uncaught TypeError: Cannot read property 'replaceChild' of null
    at Array.eval (svg-injector.js:377)
    at eval (svg-injector.js:81)
(anonymous) @ svg-injector.js:377
(anonymous) @ svg-injector.js:81

from react-svg.

duro avatar duro commented on September 28, 2024

If it helps, the SVG does render to the DOM, I just get that error as well.

from react-svg.

tanem avatar tanem commented on September 28, 2024

Thanks @duro, will get back to ya once I've had the chance to look properly 👍

from react-svg.

tanem avatar tanem commented on September 28, 2024

@duro I haven't been able to recreate your issue using an isolated example, are you able to provide more context?

FWIW, it does look similar to the error output we saw many versions ago, so you might just want to make sure you are indeed pulling in the correct version of this library. Maybe something along the lines of:

$ rm -rf node_modules
$ npm cache clean
$ npm i -S react-svg@latest
$ npm i

Also, this may or not be useful to you, but there's a JSBin I sometimes play with that uses the UMD builds: http://jsbin.com/cicixuyofu/edit?html,js,output. Should probably link to it via the README at some point 😏

from react-svg.

astandrik avatar astandrik commented on September 28, 2024

Having this issue too. Occurs on first render. element seems to have no parentNode on the first injectElement call

from react-svg.

tanem avatar tanem commented on September 28, 2024

Thanks @astandrik. Published 2.1.14 but don't think that will help your situation (although more context would be nice 😉). Tempted to try using refs and one of the approaches using the ref callback mentioned in #13. Will let you know once I've done that.

from react-svg.

tanem avatar tanem commented on September 28, 2024

@duro @astandrik just published 2.1.15 which tweaks the lifecycle a bit, as mentioned above. Let me know how you get on? 🙏

from react-svg.

astandrik avatar astandrik commented on September 28, 2024

Can't say it helped a lot sorry. I'm doing the following:

function loadIcon(name, className, onClick) {
  const path =  require("./" + name +".svg"); 
  // here path becomes a string like path == './static.234wer23er32ellipsis.svg'
  return (
    <div onClick={onClick}>
      <ReactSVG
        path={path}
        className={className}
     />
   </div>
  )
}

const Icon = ({name, className, onClick}) => {
  return loadIcon(name, className, onClick);
}


......
render() {
   return (
    ....
    <Icon className="clickable-image ellipsis" onClick={openPopover} name="ellipsis" />
    ...
  )
}
.....

P.S. Icons work as expected but the error makes me feel a bit uncomfortable
error:

Uncaught TypeError: Cannot read property 'replaceChild' of null
    at Array.eval (svg-injector.js:377)
    at eval (svg-injector.js:81)

from react-svg.

tanem avatar tanem commented on September 28, 2024

Thanks @astandrik, think I managed to recreate your issue (or at least a very similar one 😅). Have released 2.1.17, can you let me know if that's any better now?

from react-svg.

neokat avatar neokat commented on September 28, 2024

I had a similar issue as @astandrik's earlier today, but downloaded 2.1.18 and am no longer receiving the type error. Thanks!

from react-svg.

tanem avatar tanem commented on September 28, 2024

Great, thanks for reporting back @kathrynreagan 💪

from react-svg.

Dlpan avatar Dlpan commented on September 28, 2024

@tanem Hello tanem, i have seen the discussion above, butI'm still getting this error in 7.0.1 "Cannot read property 'replaceChild' of null"

from react-svg.

tanem avatar tanem commented on September 28, 2024

Hey @Dlpan, thanks for the report. Since this issue you're commenting on is quite old now, I think it's worth creating a new issue? Any further information you can provide, such as code snippets, would be helpful too

from react-svg.

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.