Skip to content

stripSearchParams not working properly alongside retainSearchParams #7551

Description

@OwenVey

Which project does this relate to?

Router

Describe the bug

When using stripSearchParams along side retainSearchParams, the params specified in retainSearchParams are not long stripped from the URL that are also specified in stripSearchParams.

const DEFAULTS = {
  param1: 1,
  param2: 2,
} as const;

export const Route = createFileRoute('/')({
  validateSearch: v.object({
    param1: v.optional(v.fallback(v.number(), DEFAULTS.param1), DEFAULTS.param1),
    param2: v.optional(v.fallback(v.number(), DEFAULTS.param2), DEFAULTS.param2),
  }),
  search: {
    middlewares: [retainSearchParams(['param2']), stripSearchParams(DEFAULTS)],
  },
  component: Home,
});

In the above example, param2 is never stripped from the URL, even when the value is 2

Complete minimal reproducer

https://github.com/OwenVey/query-param-bug

Steps to Reproduce the Bug

  1. Run the dev server of the project
  2. Go to http://localhost:3000/ in your browser
  3. Notice that param3 is not stripped from the URL

Expected behavior

If a param is specified in retainSearchParams as well as stripSearchParams, it should still be stripped from the URL when the default value is set.

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.170.11
  • OS: Windows
  • Browser: Chrome
  • Browser Version: 149.0.7827.54 (Official Build) (64-bit)
  • Bundler: Vite
  • Bundler Version: 8.0.16

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions