Skip to content

Commit 4ca5be3

Browse files
authored
fix: static resource requests should not be valid loader requests (#7850)
1 parent 861393b commit 4ca5be3

File tree

1 file changed

+19
-0
lines changed
  • packages/cli/plugin-data-loader/src/runtime

1 file changed

+19
-0
lines changed

packages/cli/plugin-data-loader/src/runtime/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ function convertModernRedirectResponse(headers: Headers, basename: string) {
5252
});
5353
}
5454

55+
export function hasFileExtension(pathname: string): boolean {
56+
const lastSegment = pathname.split('/').pop() || '';
57+
const dotIndex = lastSegment.lastIndexOf('.');
58+
59+
if (dotIndex === -1) {
60+
return false;
61+
}
62+
63+
const extension = lastSegment.substring(dotIndex).toLowerCase();
64+
return extension !== '.html';
65+
}
66+
5567
export const handleRequest: ServerLoaderBundle['handleRequest'] = async ({
5668
request,
5769
serverRoutes,
@@ -61,6 +73,13 @@ export const handleRequest: ServerLoaderBundle['handleRequest'] = async ({
6173
}): Promise<Response | void> => {
6274
const url = new URL(request.url);
6375
const routeId = url.searchParams.get(LOADER_ID_PARAM) as string;
76+
77+
// Check if pathname has file extension (excluding .html)
78+
// Reject requests like /three/user/profile.js but allow /three/user/profile
79+
if (hasFileExtension(url.pathname)) {
80+
return;
81+
}
82+
6483
const entry = matchEntry(url.pathname, serverRoutes);
6584
// LOADER_ID_PARAM is the indicator for CSR data loader request.
6685
if (!routeId || !entry) {

0 commit comments

Comments
 (0)