Skip to content

Commit e14976f

Browse files
authored
fix(route-meta): deduplicate routing-meta imports by _importHash only (#4120)
1 parent 102191a commit e14976f

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

src/build/virtual/routing-meta.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ export default function routingMeta(nitro: Nitro) {
55
id: "#nitro/virtual/routing-meta",
66
template: () => {
77
const handlers = Object.values(nitro.routing.routes.routes).flatMap((h) => h.data);
8-
const routeHandlers = uniqueBy(
9-
handlers,
10-
(h) => `${h._importHash}_${h.method?.toLowerCase() || ""}_${h.route || ""}`
11-
);
8+
const routeHandlers = uniqueBy(handlers, "_importHash");
129

1310
return /* js */ `
1411
${routeHandlers
@@ -29,6 +26,6 @@ export const handlersMeta = [
2926
};
3027
}
3128

32-
function uniqueBy<T>(arr: T[], key: (item: T) => string): T[] {
33-
return [...new Map(arr.map((item) => [key(item), item])).values()];
29+
function uniqueBy<T>(arr: T[], key: keyof T): T[] {
30+
return [...new Map(arr.map((item) => [item[key], item])).values()];
3431
}

0 commit comments

Comments
 (0)