From 9a79328ccee1e315ef4d8ecf902081cb2ef518f8 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Sun, 9 Nov 2025 15:42:46 +0100 Subject: [PATCH 1/2] fix(solid-router): setting search params with 2 parallel navigate calls --- packages/router-core/src/router.ts | 17 +++++++++++++++-- .../solid-router/tests/useNavigate.test.tsx | 5 ++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 5f99c978a6..b2d15225b8 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -896,6 +896,7 @@ export class RouterCore< rewrite?: LocationRewrite origin?: string latestLocation!: ParsedLocation> + pendingBuiltLocation?: ParsedLocation> basepath!: string routeTree!: TRouteTree routesById!: RoutesById @@ -1593,7 +1594,7 @@ export class RouterCore< } = {}, ): ParsedLocation => { // We allow the caller to override the current location - const currentLocation = dest._fromLocation || this.latestLocation + const currentLocation = dest._fromLocation || this.pendingBuiltLocation || this.latestLocation const allCurrentLocationMatches = this.matchRoutes(currentLocation, { _buildLocation: true, @@ -1956,7 +1957,9 @@ export class RouterCore< _includeValidateSearch: true, }) - return this.commitLocation({ + this.pendingBuiltLocation = location as ParsedLocation> + + const commitPromise = this.commitLocation({ ...location, viewTransition, replace, @@ -1964,6 +1967,16 @@ export class RouterCore< hashScrollIntoView, ignoreBlocker, }) + + // Clear pending location after commit starts + // We do this on next microtask to allow synchronous navigate calls to chain + Promise.resolve().then(() => { + if (this.pendingBuiltLocation === location) { + this.pendingBuiltLocation = undefined + } + }) + + return commitPromise } /** diff --git a/packages/solid-router/tests/useNavigate.test.tsx b/packages/solid-router/tests/useNavigate.test.tsx index c660f6d64f..531f0a474d 100644 --- a/packages/solid-router/tests/useNavigate.test.tsx +++ b/packages/solid-router/tests/useNavigate.test.tsx @@ -1253,7 +1253,7 @@ test('when navigating to /posts/$postId/info which is imperatively masked as /po expect(window.location.pathname).toEqual('/posts/id1') }) -test.skip('when setting search params with 2 parallel navigate calls', async () => { +test('when setting search params with 2 parallel navigate calls', async () => { const rootRoute = createRootRoute() const IndexComponent = () => { @@ -1301,6 +1301,9 @@ test.skip('when setting search params with 2 parallel navigate calls', async () render(() => ) + // Wait for router to initialize with defaults + await screen.findByTestId('param1') + // console.log(router.state.location) expect(router.state.location.search).toEqual({ param1: 'param1-default', From c29874d4ecc0006d3a02b3dbc53b6f7f3c33fba7 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 9 Nov 2025 14:43:56 +0000 Subject: [PATCH 2/2] ci: apply automated fixes --- packages/router-core/src/router.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index b2d15225b8..994900543c 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -1594,7 +1594,8 @@ export class RouterCore< } = {}, ): ParsedLocation => { // We allow the caller to override the current location - const currentLocation = dest._fromLocation || this.pendingBuiltLocation || this.latestLocation + const currentLocation = + dest._fromLocation || this.pendingBuiltLocation || this.latestLocation const allCurrentLocationMatches = this.matchRoutes(currentLocation, { _buildLocation: true, @@ -1957,7 +1958,9 @@ export class RouterCore< _includeValidateSearch: true, }) - this.pendingBuiltLocation = location as ParsedLocation> + this.pendingBuiltLocation = location as ParsedLocation< + FullSearchSchema + > const commitPromise = this.commitLocation({ ...location,