Skip to content

[FEATURE] relative paths break when embedding the SVG #546

@LukeLR

Description

@LukeLR

Describe the bug
When the SVG image is in-line embedded in the homeassistant dashboard, relative links inside the SVG image will break, as the browser will try to fetch the resource relatively to the dashboard URL, not the SVG image URL. This affects for example raster images, which are not embedded in the SVG file.

For example, the floor plans of our rooms and lamp icons are available as PNG images, so my SVG image includes a PNG (example.png) which is in the same folder as the SVG image. When loading the SVG image directly in the browser using its URL http://<ha-ip>:8123/local/floorplan/floorplan.svg, the browser fetches the PNG from http://<ha-ip>:8123/local/floorplan/example.png. However, inside the floorplan card, the URL is interpreted relatively to the dashboard URL: http://<ha-ip>:8123/dashboard-test/example.png which doesn't work.

Embedding all the images in the SVG and using object clones in Inkscape is a workaround, but due to the base64 encoding of the embedded images, the SVG filesize blows up and slows down dashboard display. Using absolute links to the PNG on the HomeAssistant server inside the SVG is not really feasible for inkscape editing. As another workaround, I tried to rewrite the relative paths inside my SVG using JavaScript, but I can't find a way to execute JavaScript once after loading the document.

It would be great if relative links would work as expected inside the SVG image.

To Reproduce
Steps to reproduce the behavior:

  1. Create an SVG in Inkscape
  2. Drag an external image into the Inkscape window
  3. Choose "Link"
  4. Upload that SVG to your HomeAssistant www directory
  5. Load the SVG directly in the browser
  6. Use the SVG in a floorplan card

Expected behavior
The external image linked inside the SVG will display in the floorplan card. However, it will only be displayed when loading the SVG directly in the browser, not from inside the floorplan card.

Desktop (please complete the following information):

  • OS: Arch Linux
  • Browser: Firefox
  • Version: 137

Smartphone (please complete the following information):

  • Device: Fairphone 5
  • OS: /e/-OS
  • Browser: HomeAssistant app from f-droid
  • Version: -

Share configuration
Please share:

  • YAML:
type: custom:floorplan-card
full_height: true
config:
  image: /local/floorplan/IMG_20250402_194639.svg
  stylesheet: /local/floorplan/IMG_20250402_194639.css
  rules: []
  • CSS: none
  • SVG-file (IMPORTANT!) (Use gofile.io, or something simular)

Image
Image

If you create a issue without a SVG example, including the required YAML and CSS to reproduce the issue, it's likely what your issue will be closed, or marked as unresolvable, as it's lacking the proper amount of details. Thank you for understanding the situation.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions