react-svg icon indicating copy to clipboard operation
react-svg copied to clipboard

Add Error Handler to Limit Exception Bubbling

Open ProjectBarks opened this issue 2 years ago • 1 comments

The idea is to limit the scope in which exceptions in the injection code can break the react component. This reduces the risk of total app failure.

Added onError handler because passing new errors into afterInjection felt like I was overloading the function.

Example: Before this would break your application, after the error is routed into onError and then defaulted to the fallback.

 <ReactSVG
        beforeInjection={() => {
          throw new Error('test error')
        }}
        fallback={fallback}
        src={`http://localhost/${uuid}.svg`}
      />

ProjectBarks avatar Aug 31 '22 18:08 ProjectBarks

@tanem

ProjectBarks avatar Sep 02 '22 18:09 ProjectBarks

Thanks for this PR @ProjectBarks. Sorry for the long delay, things got away on me a bit late last year 😅

Will have a look through the changes and will get back to you. Will bring the branch up-to-date etc, so there'll be some forced pushes ⚠️

tanem avatar Jan 18 '23 20:01 tanem

Modified a few things and will merge now. Thanks for your contribution 🎉

tanem avatar Jan 23 '23 05:01 tanem

Released in v16.0.0.

tanem avatar Jan 23 '23 06:01 tanem