@@ -39,6 +39,7 @@ import {
3939} from "../router/utils" ;
4040import { getDocumentHeadersImpl } from "../server-runtime/headers" ;
4141import { SINGLE_FETCH_REDIRECT_STATUS } from "../dom/ssr/single-fetch" ;
42+ import { URL_LIMIT , getPathsWithAncestors } from "../dom/ssr/fog-of-war" ;
4243import { throwIfPotentialCSRFAttack } from "../actions" ;
4344import invariant from "../server-runtime/invariant" ;
4445
@@ -532,6 +533,14 @@ async function generateManifestResponse(
532533 temporaryReferences : unknown ,
533534 routeDiscovery : RouteDiscovery | undefined ,
534535) {
536+ let url = new URL ( request . url ) ;
537+ if ( url . toString ( ) . length > URL_LIMIT ) {
538+ return new Response ( null , {
539+ statusText : "Bad Request" ,
540+ status : 400 ,
541+ } ) ;
542+ }
543+
535544 if ( routeDiscovery ?. mode === "initial" ) {
536545 let payload : RSCManifestPayload = {
537546 type : "manifest" ,
@@ -550,7 +559,6 @@ async function generateManifestResponse(
550559 ) ;
551560 }
552561
553- let url = new URL ( request . url ) ;
554562 let pathParam = url . searchParams . get ( "paths" ) ;
555563 let pathnames = pathParam
556564 ? pathParam . split ( "," ) . filter ( Boolean )
@@ -1193,7 +1201,7 @@ async function getRenderPayload(
11931201 ) ,
11941202 )
11951203 : getAdditionalRoutePatches (
1196- [ staticContext . location . pathname ] ,
1204+ getPathsWithAncestors ( [ staticContext . location . pathname ] ) ,
11971205 routes ,
11981206 basename ,
11991207 staticContext . matches . map ( ( m ) => m . route . id ) ,
@@ -1428,33 +1436,18 @@ async function getAdditionalRoutePatches(
14281436 let matchedPaths = new Set < string > ( ) ;
14291437
14301438 for ( const pathname of pathnames ) {
1431- let segments = pathname . split ( "/" ) . filter ( Boolean ) ;
1432- let paths : string [ ] = [ "/" ] ;
1433-
1434- // We've already matched to the last segment
1435- segments . pop ( ) ;
1436-
1437- // Traverse each path for our parents and match in case they have pathless/index
1438- // children we need to include in the initial manifest
1439- while ( segments . length > 0 ) {
1440- paths . push ( `/${ segments . join ( "/" ) } ` ) ;
1441- segments . pop ( ) ;
1439+ if ( matchedPaths . has ( pathname ) ) {
1440+ continue ;
14421441 }
1443-
1444- paths . forEach ( ( path ) => {
1445- if ( matchedPaths . has ( path ) ) {
1442+ matchedPaths . add ( pathname ) ;
1443+ let matches = matchRoutes ( routes , pathname , basename ) || [ ] ;
1444+ matches . forEach ( ( m , i ) => {
1445+ if ( patchRouteMatches . get ( m . route . id ) ) {
14461446 return ;
14471447 }
1448- matchedPaths . add ( path ) ;
1449- let matches = matchRoutes ( routes , path , basename ) || [ ] ;
1450- matches . forEach ( ( m , i ) => {
1451- if ( patchRouteMatches . get ( m . route . id ) ) {
1452- return ;
1453- }
1454- patchRouteMatches . set ( m . route . id , {
1455- ...m . route ,
1456- parentId : matches [ i - 1 ] ?. route . id ,
1457- } ) ;
1448+ patchRouteMatches . set ( m . route . id , {
1449+ ...m . route ,
1450+ parentId : matches [ i - 1 ] ?. route . id ,
14581451 } ) ;
14591452 } ) ;
14601453 }
0 commit comments