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

Safari + foreignobject render issue [SOLVED] #284

Open
ankero opened this issue Mar 8, 2020 · 5 comments
Open

Safari + foreignobject render issue [SOLVED] #284

ankero opened this issue Mar 8, 2020 · 5 comments
Labels

Comments

@ankero
Copy link

ankero commented Mar 8, 2020

This is not an issue, but something that could be added to the README. I'll add it here so if someone faces a similar issue, a solution can be found in this repo.

When developing with this libary and if you use foreignobject to render a node, check how it is displayed in Safari (Mac + iOS). We faced an issue, where the node content was rendered to coordinates 0,0 (top-left corner) of the parent SVG. This is due to a bug in Safari, which affects foreignobjects to calculate the rendering position based on the top SVG and not the foreignobject itself. You could see this effect very clearly by inspecting the node and seeing that the node, based on the browser, is where it should be, but it was rendered in the wrong place.

So what's the solution if you see this issue?
As far as I saw, if you use any of the following CSS options, the dom element will render in the wrong place. So fix is not to use these. For us, we needed to check if the browser is Safari and then remove some functionalities that required one or more of these styles:

So do not use the following styles in Safari + foreignobjects:

  • position (You can use position:fixed but that will introduce an overflow issue)
  • webkit-transform-style
  • webkit-backface-visibility
  • transition
  • transform

How to detect Safari?
We use this snippet:
export const IS_SAFARI = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);

@edo
Copy link

edo commented Mar 14, 2020

Thanks for posting this @ankero. Was struggling with this same issue and couln't find it.

@bkrem
Copy link
Owner

bkrem commented Mar 15, 2020

Thanks so much for explaining this issue for everyone @ankero 🙏 I'm going to pin this great explanation and add a link to the issue in the readme.

Sorry for the delay on any action here, I'm only now coming back to the library to keep working on v2 and recent issues/critical v1 patches after a lengthy stint of being unwell (fortunately unrelated to current events) and some high prio offline concerns.

I believe we had another issue going discussing this bug, which I'll close and forward to this one now. If you have questions and/or suggestions around this bug, please post them here rather than opening a new issue.

@hiep294
Copy link

hiep294 commented Oct 16, 2022

In safari, I found opacity also causes bugs.
<foreignObject
y="calc(100% - 49px)"

calc may not work as expected

@Damon99999
Copy link

This is not an issue, but something that could be added to the README. I'll add it here so if someone faces a similar issue, a solution can be found in this repo.

When developing with this libary and if you use foreignobject to render a node, check how it is displayed in Safari (Mac + iOS). We faced an issue, where the node content was rendered to coordinates 0,0 (top-left corner) of the parent SVG. This is due to a bug in Safari, which affects foreignobjects to calculate the rendering position based on the top SVG and not the foreignobject itself. You could see this effect very clearly by inspecting the node and seeing that the node, based on the browser, is where it should be, but it was rendered in the wrong place.

So what's the solution if you see this issue? As far as I saw, if you use any of the following CSS options, the dom element will render in the wrong place. So fix is not to use these. For us, we needed to check if the browser is Safari and then remove some functionalities that required one or more of these styles:

So do not use the following styles in Safari + foreignobjects:

  • position (You can use position:fixed but that will introduce an overflow issue)
  • webkit-transform-style
  • webkit-backface-visibility
  • transition
  • transform

How to detect Safari? We use this snippet: export const IS_SAFARI = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);

thx, In my project, the node position was wrong and the size was scaled down

@remon25
Copy link

remon25 commented Nov 26, 2023

Thanks so much

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

No branches or pull requests

6 participants