generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Sync with useSearchParams in 14.1.0
* fix: Set the history state to null As recommended in the Next.js docs for shallow routing. Historically, while Next.js didn't support shallow routing (<14.1.0), maintaining the history state was the way to keep the app router state. * chore: Remove dead code No need to pass pages-router specific code here, as this branch now only runs in the app router context. * fix: Quick fix attempt for older versions * chore: Fence test and add push check * chore: Disable 14.0.5-canary.54 in CI The fix only applies to GA versions. * chore: Update comment for later reference * chore: Restore test against 14.0.4 * chore: Update comment
- Loading branch information
Showing
6 changed files
with
70 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// <reference types="cypress" /> | ||
|
||
if (Cypress.env('supportsShallowRouting')) { | ||
it('useSearchParams', () => { | ||
cy.visit('/app/useSearchParams') | ||
cy.contains('#hydration-marker', 'hydrated').should('be.hidden') | ||
cy.get('input').type('foo', { delay: 0 }) | ||
cy.get('#searchParams').should('have.text', 'q=foo') | ||
cy.get('button').click() | ||
cy.get('#searchParams').should('have.text', 'q=foo&push=true') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use client' | ||
|
||
import { useSearchParams } from 'next/navigation' | ||
import { parseAsBoolean, useQueryState } from 'nuqs' | ||
import { Suspense } from 'react' | ||
|
||
export default function Page() { | ||
return ( | ||
<Suspense> | ||
<Client /> | ||
</Suspense> | ||
) | ||
} | ||
|
||
function Client() { | ||
const [q, setQ] = useQueryState('q', { defaultValue: '' }) | ||
const [, setPush] = useQueryState( | ||
'push', | ||
parseAsBoolean.withDefault(false).withOptions({ history: 'push' }) | ||
) | ||
const searchParams = useSearchParams() | ||
return ( | ||
<div> | ||
<input type="text" value={q} onChange={e => setQ(e.target.value)} /> | ||
<pre id="searchParams">{searchParams?.toString() ?? 'null'}</pre> | ||
<button onClick={() => setPush(true)}>Push</button> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.