Skip to content

Commit

Permalink
remove extra code, fix #406 slow perf on localeCompare
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Sep 25, 2024
1 parent cf0ebbf commit 83b7093
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-apples-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/router": patch
---

remove extra code, fix #406 slow perf on localeCompare
14 changes: 1 addition & 13 deletions src/routers/createRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ function intercept<T>(
return [get ? () => get(value()) : value, set ? (v: T) => setValue(set(v)) : setValue];
}

function querySelector<T extends Element>(selector: string) {
if (selector === "#") {
return null;
}
// Guard against selector being an invalid CSS selector
try {
return document.querySelector<T>(selector);
} catch (e) {
return null;
}
}

export function createRouter(config: {
get: () => string | LocationChange,
set: (next: LocationChange) => void,
Expand Down Expand Up @@ -65,7 +53,7 @@ export function bindEvent(target: EventTarget, type: string, handler: EventListe
}

export function scrollToHash(hash: string, fallbackTop?: boolean) {
const el = querySelector(`#${hash}`) ?? document.getElementById(hash);
const el = hash && document.getElementById(hash);
if (el) {
el.scrollIntoView();
} else if (fallbackTop) {
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ export function createMatcher<S extends string>(

for (let i = 0; i < len; i++) {
const segment = segments[i];
const locSegment = locSegments[i];
const dynamic = segment[0] === ":";
const key = dynamic ? segment.slice(1) : segment;
const locSegment = dynamic ? locSegments[i] : locSegments[i].toLowerCase();
const key = dynamic ? segment.slice(1) : segment.toLowerCase();

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

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

if (filter === undefined) {
return true;
Expand Down

0 comments on commit 83b7093

Please sign in to comment.