[next] fix re-mapping logic for index prefetches (#10750)

Follow-up to https://github.com/vercel/vercel/pull/10734 -- but considers that the static prefetch associated with `/` might be inside of a dir such as `index/index.prefetch.rsc`. 

To avoid any future matching conflicts, this PR updates to prefix all static prefetches
This commit is contained in:
Zack Tanner
2023-10-24 13:51:55 -07:00
committed by GitHub
parent 57541e230d
commit fc90a3dc0b
7 changed files with 148 additions and 17 deletions

View File

@@ -3120,3 +3120,16 @@ export async function getServerlessPages(params: {
return { pages, appPaths: normalizedAppPaths };
}
// to avoid any conflict with route matching/resolving, we prefix all prefetches (ie, __index.prefetch.rsc)
// this is to ensure that prefetches are never matched for things like a greedy match on `index.{ext}`
export function normalizePrefetches(prefetches: Record<string, FileFsRef>) {
const updatedPrefetches: Record<string, FileFsRef> = {};
for (const key in prefetches) {
const newKey = key.replace(/([^/]+\.prefetch\.rsc)$/, '__$1');
updatedPrefetches[newKey] = prefetches[key];
}
return updatedPrefetches;
}