Skip to content

Commit f35ddc7

Browse files
johanrdNullVoxPopuli
authored andcommitted
fix: [Bug] LinkTo inside inline SVG reloads application #19891
1 parent 59e54d5 commit f35ddc7

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

packages/@ember/-internals/glimmer/lib/components/link-to.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,13 @@ class _LinkTo extends InternalComponent {
368368
}
369369

370370
let element = event.currentTarget;
371-
assert('[BUG] must be an <a> element', element instanceof HTMLAnchorElement);
371+
assert(
372+
'[BUG] must be an <a> element',
373+
element instanceof HTMLAnchorElement || element instanceof SVGAElement
374+
);
372375

373-
let isSelf = element.target === '' || element.target === '_self';
376+
let target = element instanceof SVGAElement ? element.target.baseVal : element.target;
377+
let isSelf = target === '' || target === '_self';
374378

375379
if (isSelf) {
376380
this.preventDefault(event);

packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ApplicationTestCase,
33
ModuleBasedTestResolver,
44
moduleFor,
5+
runLoopSettled,
56
runTask,
67
} from 'internal-test-helpers';
78
import Controller, { inject as injectController } from '@ember/controller';
@@ -131,6 +132,34 @@ moduleFor(
131132
);
132133
}
133134

135+
async ['@test [GH#19891] it navigates into the named route when inside an inline SVG'](assert) {
136+
this.addTemplate(
137+
'index',
138+
`
139+
<h3 class="home">Home</h3>
140+
<svg xmlns="http://www.w3.org/2000/svg">
141+
<LinkTo @route='about' id='svg-about-link'>
142+
<rect x="0" y="0" width="200" height="100"></rect>
143+
</LinkTo>
144+
</svg>
145+
`
146+
);
147+
148+
await this.visit('/');
149+
150+
assert.equal(this.$('h3.home').length, 1, 'The home template was rendered');
151+
152+
// SVGAElement does not have a .click() method like HTMLElement,
153+
// so we dispatch a click event manually.
154+
let svgLink = document.querySelector('#svg-about-link');
155+
let clickEvent = document.createEvent('MouseEvents');
156+
clickEvent.initMouseEvent('click', true, true);
157+
svgLink.dispatchEvent(clickEvent);
158+
await runLoopSettled();
159+
160+
assert.equal(this.$('h3.about').length, 1, 'The about template was rendered');
161+
}
162+
134163
async [`@test it applies a 'disabled' class when disabled`](assert) {
135164
this.addTemplate(
136165
'index',

0 commit comments

Comments
 (0)