Skip to content

Commit 345e904

Browse files
authored
Merge pull request #75 from AegisJSProject/bug/unset-signal
Do not add listener on missing signal
2 parents 5b12108 + 45ddf45 commit 345e904

6 files changed

Lines changed: 38 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [v1.1.11] - 2025-04-25
11+
12+
### Fixed
13+
- Check for `passedSignal` being given before adding listener
14+
- Do not handle link clicks with modifier keys (eg to open in new tab)
15+
1016
## [v1.1.10] - 2025-04-24
1117

1218
### Fixed

http.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
import { readFile } from 'node:fs/promises';
2+
const home = await readFile('./test/index.html');
3+
const getHome = () => new Response(home, { headers: { 'Content-Type': 'text/html' }});
14
const cache = new Map();
25

36
export default {
47
open: true,
58
pathname: '/test/',
9+
routes: {
10+
'/favicon.svg': () => new Response(`<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 10 10">
11+
<rect x="0" y="0" rx="10" ry="10" width="10" height="10" fill="#${crypto.getRandomValues(new Uint8Array(3)).toHex()}"></rect>
12+
</svg>`, { headers: { 'Content-Type': 'image/svg+xml' }}),
13+
'/product/:productId': getHome,
14+
'/page/markdown': getHome,
15+
'/test/': getHome,
16+
'/search?q=:query': getHome,
17+
'/img/:fill([A-Fa-f\\d]{3,6})?/:size(\\d+)?/:radius(\\d+)?': getHome,
18+
'/page/bacon/:lines(\\d+)': getHome,
19+
'/github/:username(\\w+)': getHome,
20+
},
621
requestPreprocessors: [
722
req => {
823
if (cache.has(req.url)) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aegisjsproject/router",
3-
"version": "1.1.10",
3+
"version": "1.1.11",
44
"description": "A simple but powerful router module",
55
"keywords": [
66
"router",

router.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,11 @@ function _loadLink(href, {
234234
const controller = new AbortController();
235235
const signal = passedSignal instanceof AbortSignal ? AbortSignal.any([controller.signal, passedSignal]) : controller.signal;
236236

237-
passedSignal.addEventListener('abort', ({ target }) => {
238-
reject(target.reason);
239-
}, { signal: controller.signal });
237+
if (passedSignal instanceof AbortSignal) {
238+
passedSignal.addEventListener('abort', ({ target }) => {
239+
reject(target.reason);
240+
}, { signal: controller.signal, once: true });
241+
}
240242

241243
link.referrerPolicy = referrerPolicy;
242244

@@ -307,7 +309,11 @@ function _getLinkStateData(a) {
307309
function _interceptLinkClick(event) {
308310
if (event.target.classList.contains('no-router') || event.target.hasAttribute(onClick)) {
309311
event.target.removeEventListener(_interceptLinkClick);
310-
} else if (event.isTrusted && event.currentTarget.href.startsWith(location.origin)) {
312+
} else if (
313+
event.isTrusted
314+
&& event.currentTarget.href.startsWith(location.origin)
315+
&& ! (event.metaKey || event.ctrlKey || event.shiftKey)
316+
) {
311317
event.preventDefault();
312318
const state = _getLinkStateData(event.currentTarget);
313319
navigate(event.currentTarget.href, state, {
@@ -316,7 +322,7 @@ function _interceptLinkClick(event) {
316322
referrerPolicy: event.currentTarget.dataset.referrerPolicy,
317323
});
318324
}
319-
};
325+
}
320326

321327
async function _interceptFormSubmit(event) {
322328
if (event.target.classList.contains('no-router') || event.target.hasAttribute(onSubmit)) {

test/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en" dir="ltr" class="preload-x">
2+
<html lang="en" dir="ltr" class="preload">
33
<head>
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width" />
@@ -26,8 +26,9 @@
2626
}
2727
</script>
2828
<!-- <script type="application/javascript" defer="" referrerpolicy="no-referrer" fetchpriority="auto" crossorigin="anonymous" integrity="sha384-uaVA9Le/fIJMMUrQHZyGJ+aAH3EdIhOLxPl+cuBCvvZBltVoc+Kemy4t8KLX3/aF" src="https://unpkg.com/@shgysk8zer0/polyfills@0.4.2/all.min.js"></script> -->
29-
<script type="application/javascript" defer="" referrerpolicy="no-referrer" fetchpriority="auto" crossorigin="anonymous" integrity="sha384-1saT/U4nXVBbxQeMGiDxcWp3S9u8rT3rkBuRH7vV0DsGqV6jqGPp6ZNEEvsIWpWQ" src="https://unpkg.com/@shgysk8zer0/polyfills@0.4.5/all.min.js"></script>
29+
<script type="application/javascript" defer="" referrerpolicy="no-referrer" fetchpriority="high" crossorigin="anonymous" integrity="sha384-X8d55dt38lBIY87GNkg6Upb9pjtwYlhEoKtw9Sfsbj/XCDV4W+g0kdx4X1Bo/EaO" src="https://unpkg.com/@shgysk8zer0/polyfills@0.4.11/browser.min.js"></script>
3030
<script type="module" src="./index.js"></script>
31+
<link rel="icon" href="/favicon.svg" sizes="any" type="image/svg+xml" />
3132
<!-- <script src="./index.min.js" defer=""></script> -->
3233
<!-- <script type="application/json" id="routes">
3334
{

0 commit comments

Comments
 (0)