Skip to content

Commit 66442ad

Browse files
authored
fix(dia.LinkView): fix missing arrowheads in Safari (#2677)
1 parent d985a7e commit 66442ad

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/joint-core/src/dia/LinkView.mjs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { addClassNamePrefix, merge, assign, isObject, isFunction, clone, isPerce
55
import { Point, Line, Path, normalizeAngle, Rect, Polyline } from '../g/index.mjs';
66
import * as routers from '../routers/index.mjs';
77
import * as connectors from '../connectors/index.mjs';
8-
8+
import { env } from '../env/index.mjs';
99

1010
const Flags = {
1111
TOOLS: CellView.Flags.TOOLS,
@@ -99,6 +99,11 @@ export const LinkView = CellView.extend({
9999
this.updateHighlighters(true);
100100
this.updateTools(opt);
101101
flags = this.removeFlag(flags, [Flags.RENDER, Flags.UPDATE, Flags.LABELS, Flags.TOOLS, Flags.CONNECTOR]);
102+
103+
if (env.test('isSafari')) {
104+
this.__fixSafariBug268376();
105+
}
106+
102107
return flags;
103108
}
104109

@@ -151,6 +156,19 @@ export const LinkView = CellView.extend({
151156
return flags;
152157
},
153158

159+
__fixSafariBug268376: function() {
160+
// Safari has a bug where any change after the first render is not reflected in the DOM.
161+
// https://bugs.webkit.org/show_bug.cgi?id=268376
162+
const { el } = this;
163+
const childNodes = Array.from(el.childNodes);
164+
const fragment = document.createDocumentFragment();
165+
for (let i = 0, n = childNodes.length; i < n; i++) {
166+
el.removeChild(childNodes[i]);
167+
fragment.appendChild(childNodes[i]);
168+
}
169+
el.appendChild(fragment);
170+
},
171+
154172
requestConnectionUpdate: function(opt) {
155173
this.requestUpdate(this.getFlag(Flags.UPDATE), opt);
156174
},

packages/joint-core/src/env/index.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export const env = {
77
svgforeignobject: function() {
88
return !!document.createElementNS &&
99
/SVGForeignObject/.test(({}).toString.call(document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject')));
10+
},
11+
12+
// works for iOS browsers too
13+
isSafari: function() {
14+
return /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);
1015
}
1116
},
1217

0 commit comments

Comments
 (0)