Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to load SVG from CDN #489

Open
MwareSolutons opened this issue Jan 20, 2025 · 14 comments
Open

Trying to load SVG from CDN #489

MwareSolutons opened this issue Jan 20, 2025 · 14 comments

Comments

@MwareSolutons
Copy link

MwareSolutons commented Jan 20, 2025

Trying to load and SVG icon from CDN by setting the src on a view

<View autosize={true} style={styles} src={icon}></View>

https://cloudtv.akamaized.net/donotremove/tvms/icons/light/shield.svg

While the response is 200 from the CDN it still give an error in LNG and it wont show the icon

The error:

Image
@philippe-wm
Copy link

Does the SVG refer to external files, like images? If it's on another domain than your app it won't work

@MwareSolutons
Copy link
Author

Yes it is on another domain why would that not work PNG images from the same domain have no issues ?

@philippe-wm
Copy link

philippe-wm commented Jan 21, 2025

No I mean from inside the SVG, does it for instance incorporates images?

SVG generally is notorious to cause security issues on older devices, due to its ability to render foreign resources. We even have very old devices which refuse to render any remote SVG to canvas.

@MwareSolutons
Copy link
Author

No that seems not to be the case, if we load from local asset folder we should be ok? even on these older devices ?

@philippe-wm
Copy link

I'd say, do a few tests...
On the oldest we use canvg to render the SVG using JS 😬

@philippe-wm
Copy link

philippe-wm commented Jan 21, 2025

OT: you have a log Computations created outside a createRoot... that you should look into.
That's a SolidJS memory leak because you must be creating Solid reactive primitives outside of a component context.

@MwareSolutons
Copy link
Author

I am not sure I understand what you are saying where should I check to fix this memory leak?

@philippe-wm
Copy link

@chiefcll
Copy link
Contributor

Hey @philippe-wm - I know where this is happening - wondering how you handle it. But we create "global signals" that exist for the entire app - I'm not concerned about cleanup due to I want them to exist until the app is closed (which then the browser will clean them up) - Just want to get your thoughts - do you prefer just using Context or just createRoot to wrap global signals to ignore the warning?

@philippe-wm
Copy link

philippe-wm commented Jan 21, 2025

@chiefcll I think generally Solid won't show the warning if you create global signals before the app is rendered (we have a number of global signals as well), but after that point you should use createRoot for reactive set ups that you manage outside of the components lifecycle

(we're getting a bit OT though)

@MwareSolutons
Copy link
Author

the SVG's icons are working perfectly from local assets

@elsassph
Copy link
Contributor

Here's relevant reading:

L3 renderer doesn't set crossOrigin="anonymous" when loading SVG for rendering to canvas so maybe that's the issue:

As a side note, normal image loading uses either an Image with crossorigin="Anonymous" (maybe casing is important) or fetch.

@wouterlucas
Copy link
Contributor

wouterlucas commented Jan 21, 2025

L3 renderer doesn't set crossOrigin="anonymous" when loading SVG for rendering to canvas so maybe that's the issue:

* https://github.com/lightning-js/renderer/blob/main/src/core/lib/textureSvg.ts

Indeed, fairly simple change if that is desired. Do we know if setting that fixes the issue?

@MwareSolutons can you check if this resolves it on your device:

      const img = new Image();
      img.crossOrigin = "anonymous";

      img.onload = () => {
        console.log("Image loaded successfully. Attempting to draw on canvas...");

        const canvas = document.createElement("canvas");
        const ctx = canvas.getContext("2d");

        canvas.width = img.width;
        canvas.height = img.height;

        ctx.drawImage(img, 0, 0);

        try {
          // Attempt to read pixel data from the canvas
          const imageData = ctx.getImageData(0, 0, 1, 1);
          console.log("Pixel data read successfully:", imageData.data);
        } catch (error) {
          console.error(
            "Failed to read pixel data. This is likely due to a CORS issue:",
            error
          );
        }
      };

      img.onerror = () => {
        console.error("Image failed to load. Ensure the URL is valid and supports CORS.");
      };

      img.src = '<SVG URL goes here>';
    }

by running that somewhere in a JS file for me?

As a side note, normal image loading uses either an Image with crossorigin="Anonymous" (maybe casing is important) or fetch.

!! that's a good spot - we should align that to be anonymous

@wouterlucas
Copy link
Contributor

Any update @MwareSolutons ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants