software-mansion / react-native-svg

SVG library for React Native, React Native Web, and plain React web projects.
MIT License
7.42k stars 1.12k forks source link

`source` is undefined when SvgXml calls the parse function within xml.tsx #2066

Closed manan19 closed 1 week ago

manan19 commented 1 year ago

source is undefined when SvgXml calls the parse function within xml.tsx

Bug

ERROR [TypeError: Cannot read property 'length' of undefined]

Unexpected behavior

source shouldn't be undefined or parse function should handle source optionally

Environment info

Using Expo Go with Expo SDK 48

React native info output:

System:
    OS: macOS 13.4
    CPU: (10) arm64 Apple M2 Pro
    Memory: 840.52 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.0.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.6.4 - /opt/homebrew/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: Not Found
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 14.3/14E222b - /usr/bin/xcodebuild
  Languages:
    Java: Not Found
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.8 => 0.71.8 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

This is the code I'm using to load an Svg

                    <SvgUri uri={uri}
                        width={size}
                        height={size}
                        preserveAspectRatio="xMidYMid meet"
                        style={[styles.avatarImage, sizeStyle]}
                    />

This is the URI I'm trying to load https://res.cloudinary.com/merkle-manufactory/image/fetch/c_fill,f_png,w_256/https://openseauserdata.com/files/d5d652ed260e8c7891f731cad05805d4.svg

Short, Self Contained, Correct (Compilable), Example

abraham-serafino commented 12 months ago

I am experiencing the same issue.

mitchelljustin commented 8 months ago

I'm having the same issue with a URI as well. The problem is that both the OP's URI and mine end with .svg but actually return .pngs when requested. When fetchText() tries to load that URI's SVG XML and instead receives a binary blob, it just returns undefined for the text (something that shouldn't technically be possible according to the types).

decpk commented 6 months ago

Facing same issue with url and it is breaking with error Cannot read property "length" of undefined

bohdanprog commented 1 month ago

Hello @decpk @mitchelljustin @abraham-serafino @manan19,

I have reviewed your issue and I believe it has been resolved.

Here is a branch with a test case.

Perhaps I overlooked something. Please feel free to check and let me know if everything is working as expected.

Thank you!