Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions packages/router-core/src/new-process-route-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1067,18 +1067,21 @@ function getNodeMatch<T extends RouteLike>(
rawParams,
parsedParams,
}
let indexValid = true
if (node.index.skipOnParamError) {
const result = validateMatchParams(path, parts, indexFrame)
if (!result) continue
if (!result) indexValid = false
}
// perfect match, no need to continue
// this is an optimization, algorithm should work correctly without this block
if (statics === partsLength && !dynamics && !optionals && !skipped) {
return indexFrame
}
if (isFrameMoreSpecific(bestMatch, indexFrame)) {
// index matches skip the stack because they cannot have children
bestMatch = indexFrame
if (indexValid) {
// perfect match, no need to continue
// this is an optimization, algorithm should work correctly without this block
if (statics === partsLength && !dynamics && !optionals && !skipped) {
return indexFrame
}
if (isFrameMoreSpecific(bestMatch, indexFrame)) {
// index matches skip the stack because they cannot have children
bestMatch = indexFrame
}
}
}

Expand Down
33 changes: 33 additions & 0 deletions packages/router-core/tests/skip-route-on-parse-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,39 @@ describe('skipRouteOnParseError', () => {
expect(otherResult?.route.id).toBe('/files')
expect(otherResult?.rawParams['**']).toBe('../../secret/photo.jpg')
})
it('index parse failure does not block wildcard sibling', () => {
const tree = {
id: '__root__',
isRoot: true,
fullPath: '/',
path: '/',
children: [
{
id: '/a/',
fullPath: '/a/',
path: 'a/',
options: {
params: {
parse: () => {
throw new Error('Invalid index')
},
},
skipRouteOnParseError: { params: true },
},
},
{
id: '/a/$',
fullPath: '/a/$',
path: 'a/$',
options: {},
},
],
}
const { processedTree } = processRouteTree(tree)
const result = findRouteMatch('/a', processedTree)
expect(result?.route.id).toBe('/a/$')
expect(result?.rawParams).toEqual({ '*': '', _splat: '' })
})
})

describe('multiple validated routes competing', () => {
Expand Down