diff --git a/packages/e2e/next/cypress/e2e/repro-758.cy.js b/packages/e2e/next/cypress/e2e/repro-758.cy.js new file mode 100644 index 00000000..a8acaef3 --- /dev/null +++ b/packages/e2e/next/cypress/e2e/repro-758.cy.js @@ -0,0 +1,12 @@ +/// + +describe('repro-758', () => { + it('honors urlKeys when navigating back after a push', () => { + cy.visit('/app/repro-758') + cy.contains('#hydration-marker', 'hydrated').should('be.hidden') + cy.get('button').click() + cy.get('#state').should('have.text', 'test') + cy.go('back') + cy.get('#state').should('be.empty') + }) +}) diff --git a/packages/e2e/next/src/app/app/repro-758/page.tsx b/packages/e2e/next/src/app/app/repro-758/page.tsx new file mode 100644 index 00000000..f2cf0d36 --- /dev/null +++ b/packages/e2e/next/src/app/app/repro-758/page.tsx @@ -0,0 +1,34 @@ +'use client' + +import { parseAsString, useQueryStates } from 'nuqs' +import { Suspense } from 'react' + +export default function Page() { + return ( + + + + ) +} + +function Client() { + const [{ query }, setSearchParams] = useQueryStates( + { + query: parseAsString + }, + { + history: 'push', + urlKeys: { + query: 'q' + } + } + ) + return ( + <> + +

{query}

+ + ) +} diff --git a/packages/nuqs/src/useQueryStates.ts b/packages/nuqs/src/useQueryStates.ts index 67fe3dac..c96f8101 100644 --- a/packages/nuqs/src/useQueryStates.ts +++ b/packages/nuqs/src/useQueryStates.ts @@ -123,7 +123,7 @@ export function useQueryStates( ) setInternalState(state) }, [ - Object.keys(resolvedUrlKeys) + Object.values(resolvedUrlKeys) .map(key => initialSearchParams?.get(key)) .join('&') ])