Skip to content

Commit 83b7093

Browse files
committed
remove extra code, fix #406 slow perf on localeCompare
1 parent cf0ebbf commit 83b7093

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

.changeset/little-apples-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/router": patch
3+
---
4+
5+
remove extra code, fix #406 slow perf on localeCompare

src/routers/createRouter.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ function intercept<T>(
1010
return [get ? () => get(value()) : value, set ? (v: T) => setValue(set(v)) : setValue];
1111
}
1212

13-
function querySelector<T extends Element>(selector: string) {
14-
if (selector === "#") {
15-
return null;
16-
}
17-
// Guard against selector being an invalid CSS selector
18-
try {
19-
return document.querySelector<T>(selector);
20-
} catch (e) {
21-
return null;
22-
}
23-
}
24-
2513
export function createRouter(config: {
2614
get: () => string | LocationChange,
2715
set: (next: LocationChange) => void,
@@ -65,7 +53,7 @@ export function bindEvent(target: EventTarget, type: string, handler: EventListe
6553
}
6654

6755
export function scrollToHash(hash: string, fallbackTop?: boolean) {
68-
const el = querySelector(`#${hash}`) ?? document.getElementById(hash);
56+
const el = hash && document.getElementById(hash);
6957
if (el) {
7058
el.scrollIntoView();
7159
} else if (fallbackTop) {

src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ export function createMatcher<S extends string>(
7272

7373
for (let i = 0; i < len; i++) {
7474
const segment = segments[i];
75-
const locSegment = locSegments[i];
7675
const dynamic = segment[0] === ":";
77-
const key = dynamic ? segment.slice(1) : segment;
76+
const locSegment = dynamic ? locSegments[i] : locSegments[i].toLowerCase();
77+
const key = dynamic ? segment.slice(1) : segment.toLowerCase();
7878

7979
if (dynamic && matchSegment(locSegment, matchFilter(key))) {
8080
match.params[key] = locSegment;
81-
} else if (dynamic || !matchSegment(locSegment, segment)) {
81+
} else if (dynamic || !matchSegment(locSegment, key)) {
8282
return null;
8383
}
8484
match.path += `/${locSegment}`;
@@ -98,7 +98,7 @@ export function createMatcher<S extends string>(
9898
}
9999

100100
function matchSegment(input: string, filter?: string | MatchFilter): boolean {
101-
const isEqual = (s: string) => s.localeCompare(input, undefined, { sensitivity: "base" }) === 0;
101+
const isEqual = (s: string) => s === input;
102102

103103
if (filter === undefined) {
104104
return true;

0 commit comments

Comments
 (0)