generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Shallow routing for everyone (#811)
- Loading branch information
Showing
65 changed files
with
935 additions
and
164 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
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 |
---|---|---|
|
@@ -10,7 +10,8 @@ wrapping it with a `NuqsAdapter` context provider: | |
- [Next.js (pages router)](#nextjs-pages-router) | ||
- [React SPA (eg: with Vite)](#react-spa) | ||
- [Remix](#remix) | ||
- [React Router](#react-router) | ||
- [React Router v6](#react-router-v6) | ||
- [React Router v7](#react-router-v7) | ||
|
||
## Next.js | ||
|
||
|
@@ -102,11 +103,11 @@ export default function App() { | |
} | ||
``` | ||
|
||
## React Router | ||
## React Router v6 | ||
|
||
```tsx title="src/main.tsx" | ||
// [!code word:NuqsAdapter] | ||
import { NuqsAdapter } from 'nuqs/adapters/react-router' | ||
import { NuqsAdapter } from 'nuqs/adapters/react-router/v6' | ||
import { createBrowserRouter, RouterProvider } from 'react-router-dom' | ||
import App from './App' | ||
|
||
|
@@ -126,7 +127,31 @@ export function ReactRouter() { | |
} | ||
``` | ||
|
||
**Note**: If you are using react-router v7, please import the `NuqsAdapter{:ts}` from `nuqs/adapters/react-router/v7` | ||
## React Router v7 | ||
|
||
```tsx title="app/root.tsx" | ||
// [!code word:NuqsAdapter] | ||
import { NuqsAdapter } from 'nuqs/adapters/react-router/v7' | ||
import { Outlet } from 'react-router' | ||
|
||
// ... | ||
|
||
export default function App() { | ||
return ( | ||
<NuqsAdapter> | ||
<Outlet /> | ||
</NuqsAdapter> | ||
) | ||
} | ||
``` | ||
|
||
<Callout type="warn" title="Deprecation notice"> | ||
The generic import `nuqs/adapters/react-router` (pointing to v6) | ||
is deprecated and will be removed in [email protected]. | ||
|
||
Please pin your imports to the specific version, | ||
eg: `nuqs/adapters/react-router/v6` or `nuqs/adapters/react-router/v7`. | ||
</Callout> | ||
|
||
## Testing | ||
|
||
|
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,25 @@ | ||
import { testShallow } from 'e2e-shared/specs/shallow.cy' | ||
|
||
testShallow({ | ||
path: '/app/shallow/useQueryState', | ||
hook: 'useQueryState', | ||
nextJsRouter: 'app' | ||
}) | ||
|
||
testShallow({ | ||
path: '/app/shallow/useQueryStates', | ||
hook: 'useQueryStates', | ||
nextJsRouter: 'app' | ||
}) | ||
|
||
testShallow({ | ||
path: '/pages/shallow/useQueryState', | ||
hook: 'useQueryState', | ||
nextJsRouter: 'pages' | ||
}) | ||
|
||
testShallow({ | ||
path: '/pages/shallow/useQueryStates', | ||
hook: 'useQueryStates', | ||
nextJsRouter: 'pages' | ||
}) |
35 changes: 35 additions & 0 deletions
35
packages/e2e/next/src/app/app/(shared)/shallow/useQueryState/page.tsx
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,35 @@ | ||
import { ShallowUseQueryState } from 'e2e-shared/specs/shallow' | ||
import { ShallowDisplay } from 'e2e-shared/specs/shallow-display' | ||
import { | ||
createSearchParamsCache, | ||
parseAsString, | ||
type SearchParams | ||
} from 'nuqs/server' | ||
import { Suspense } from 'react' | ||
|
||
type PageProps = { | ||
searchParams: Promise<SearchParams> | ||
} | ||
|
||
const cache = createSearchParamsCache( | ||
{ | ||
state: parseAsString | ||
}, | ||
{ | ||
urlKeys: { | ||
state: 'test' | ||
} | ||
} | ||
) | ||
|
||
export default async function Page({ searchParams }: PageProps) { | ||
await cache.parse(searchParams) | ||
return ( | ||
<> | ||
<Suspense> | ||
<ShallowUseQueryState /> | ||
</Suspense> | ||
<ShallowDisplay environment="server" state={cache.get('state')} /> | ||
</> | ||
) | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/e2e/next/src/app/app/(shared)/shallow/useQueryStates/page.tsx
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,35 @@ | ||
import { ShallowUseQueryStates } from 'e2e-shared/specs/shallow' | ||
import { ShallowDisplay } from 'e2e-shared/specs/shallow-display' | ||
import { | ||
createSearchParamsCache, | ||
parseAsString, | ||
type SearchParams | ||
} from 'nuqs/server' | ||
import { Suspense } from 'react' | ||
|
||
type PageProps = { | ||
searchParams: Promise<SearchParams> | ||
} | ||
|
||
const cache = createSearchParamsCache( | ||
{ | ||
state: parseAsString | ||
}, | ||
{ | ||
urlKeys: { | ||
state: 'test' | ||
} | ||
} | ||
) | ||
|
||
export default async function Page({ searchParams }: PageProps) { | ||
await cache.parse(searchParams) | ||
return ( | ||
<> | ||
<Suspense> | ||
<ShallowUseQueryStates /> | ||
</Suspense> | ||
<ShallowDisplay environment="server" state={cache.get('state')} /> | ||
</> | ||
) | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/e2e/next/src/pages/pages/shallow/useQueryState.tsx
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,26 @@ | ||
import { ShallowUseQueryState } from 'e2e-shared/specs/shallow' | ||
import { ShallowDisplay } from 'e2e-shared/specs/shallow-display' | ||
import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next' | ||
|
||
type Props = { | ||
serverState: string | null | ||
} | ||
|
||
export default function Page({ serverState }: Props) { | ||
return ( | ||
<> | ||
<ShallowUseQueryState /> | ||
<ShallowDisplay environment="server" state={serverState} /> | ||
</> | ||
) | ||
} | ||
|
||
export function getServerSideProps( | ||
ctx: GetServerSidePropsContext | ||
): GetServerSidePropsResult<Props> { | ||
return { | ||
props: { | ||
serverState: ctx.query.test as string | null | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/e2e/next/src/pages/pages/shallow/useQueryStates.tsx
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,26 @@ | ||
import { ShallowUseQueryStates } from 'e2e-shared/specs/shallow' | ||
import { ShallowDisplay } from 'e2e-shared/specs/shallow-display' | ||
import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next' | ||
|
||
type Props = { | ||
serverState: string | null | ||
} | ||
|
||
export default function Page({ serverState }: Props) { | ||
return ( | ||
<> | ||
<ShallowUseQueryStates /> | ||
<ShallowDisplay environment="server" state={serverState} /> | ||
</> | ||
) | ||
} | ||
|
||
export function getServerSideProps( | ||
ctx: GetServerSidePropsContext | ||
): GetServerSidePropsResult<Props> { | ||
return { | ||
props: { | ||
serverState: ctx.query.test as string | null | ||
} | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
packages/e2e/react-router/v6/cypress/e2e/shared/shallow.cy.ts
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,11 @@ | ||
import { testShallow } from 'e2e-shared/specs/shallow.cy' | ||
|
||
testShallow({ | ||
path: '/shallow/useQueryState', | ||
hook: 'useQueryState' | ||
}) | ||
|
||
testShallow({ | ||
path: '/shallow/useQueryStates', | ||
hook: 'useQueryStates' | ||
}) |
Oops, something went wrong.