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.
* test: Add push test * chore: Add push test on pages router * chore: Skip broken app router push test on latest * fix: Use pages router via internals Going through the history API only on shallow updates doesn't notify the pages router, which can handle shallow updates directly. Definitely a hack, but it allows also setting the asPath for dynamic routes. There is still an issue with basePath being applied twice, but that's an internal Next.js bug for another day. * chore: Fix workflow * chore: Restore test now that 14.0.4 has been released * chore: Use 14.0.4 as baseline * chore: Fix double basePath application Disabling the bloom filter causing invalid collisions between the pages and app routers. * chore: Restore hard fail on CI * test: Drop Next.js version injection (no longer needed) * doc: Add note about internals usage
- Loading branch information
Showing
7 changed files
with
234 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/// <reference types="cypress" /> | ||
|
||
describe('push', () => { | ||
it('works in app router', () => { | ||
cy.visit('/app/push') | ||
cy.contains('#hydration-marker', 'hydrated').should('be.hidden') | ||
cy.get('#server-side').should('have.text', '0') | ||
cy.get('#server').should('have.text', '0') | ||
cy.get('#client').should('have.text', '0') | ||
|
||
cy.get('button#server-incr').click() | ||
cy.location('search').should('eq', '?server=1') | ||
cy.get('#server-side').should('have.text', '1') | ||
cy.get('#server').should('have.text', '1') | ||
cy.get('#client').should('have.text', '0') | ||
|
||
cy.get('button#client-incr').click() | ||
cy.location('search').should('eq', '?server=1&client=1') | ||
cy.get('#server-side').should('have.text', '1') | ||
cy.get('#server').should('have.text', '1') | ||
cy.get('#client').should('have.text', '1') | ||
|
||
cy.go('back') | ||
cy.location('search').should('eq', '?server=1') | ||
cy.get('#server-side').should('have.text', '1') | ||
cy.get('#server').should('have.text', '1') | ||
cy.get('#client').should('have.text', '0') | ||
|
||
cy.go('back') | ||
cy.location('search').should('be.empty') | ||
cy.get('#server-side').should('have.text', '0') | ||
cy.get('#server').should('have.text', '0') | ||
cy.get('#client').should('have.text', '0') | ||
|
||
cy.go('forward') | ||
cy.location('search').should('eq', '?server=1') | ||
cy.get('#server-side').should('have.text', '1') | ||
cy.get('#server').should('have.text', '1') | ||
cy.get('#client').should('have.text', '0') | ||
|
||
cy.go('forward') | ||
cy.location('search').should('eq', '?server=1&client=1') | ||
cy.get('#server-side').should('have.text', '1') | ||
cy.get('#server').should('have.text', '1') | ||
cy.get('#client').should('have.text', '1') | ||
}) | ||
|
||
it('works in pages router', () => { | ||
cy.visit('/pages/push') | ||
cy.get('#server-side').should('have.text', '0') | ||
cy.get('#server').should('have.text', '0') | ||
cy.get('#client').should('have.text', '0') | ||
|
||
cy.get('button#server-incr').click() | ||
cy.location('search').should('eq', '?server=1') | ||
cy.get('#server-side').should('have.text', '1') | ||
cy.get('#server').should('have.text', '1') | ||
cy.get('#client').should('have.text', '0') | ||
|
||
cy.get('button#client-incr').click() | ||
cy.location('search').should('eq', '?server=1&client=1') | ||
cy.get('#server-side').should('have.text', '1') | ||
cy.get('#server').should('have.text', '1') | ||
cy.get('#client').should('have.text', '1') | ||
|
||
cy.go('back') | ||
cy.location('search').should('eq', '?server=1') | ||
cy.get('#server-side').should('have.text', '1') | ||
cy.get('#server').should('have.text', '1') | ||
cy.get('#client').should('have.text', '0') | ||
|
||
cy.go('back') | ||
cy.location('search').should('be.empty') | ||
cy.get('#server-side').should('have.text', '0') | ||
cy.get('#server').should('have.text', '0') | ||
cy.get('#client').should('have.text', '0') | ||
|
||
cy.go('forward') | ||
cy.location('search').should('eq', '?server=1') | ||
cy.get('#server-side').should('have.text', '1') | ||
cy.get('#server').should('have.text', '1') | ||
cy.get('#client').should('have.text', '0') | ||
|
||
cy.go('forward') | ||
cy.location('search').should('eq', '?server=1&client=1') | ||
cy.get('#server-side').should('have.text', '1') | ||
cy.get('#server').should('have.text', '1') | ||
cy.get('#client').should('have.text', '1') | ||
}) | ||
}) |
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,28 @@ | ||
'use client' | ||
|
||
import { useQueryState } from 'next-usequerystate' | ||
import { parser } from './searchParams' | ||
|
||
export function Client() { | ||
const [client, setClient] = useQueryState('client', parser) | ||
const [server, setServer] = useQueryState( | ||
'server', | ||
parser.withOptions({ shallow: false }) | ||
) | ||
return ( | ||
<> | ||
<p> | ||
Client: <span id="client">{client}</span> | ||
</p> | ||
<p> | ||
Server: <span id="server">{server}</span> | ||
</p> | ||
<button id="client-incr" onClick={() => setClient(c => c + 1)}> | ||
Client Incr | ||
</button> | ||
<button id="server-incr" onClick={() => setServer(c => c + 1)}> | ||
Server Incr | ||
</button> | ||
</> | ||
) | ||
} |
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,18 @@ | ||
import { Client } from './client' | ||
import { parser } from './searchParams' | ||
|
||
export default function Page({ | ||
searchParams | ||
}: { | ||
searchParams: Record<string, string | string[] | undefined> | ||
}) { | ||
const server = parser.parseServerSide(searchParams.server) | ||
return ( | ||
<> | ||
<p> | ||
Server side: <span id="server-side">{server}</span> | ||
</p> | ||
<Client /> | ||
</> | ||
) | ||
} |
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,5 @@ | ||
import { parseAsInteger } from 'next-usequerystate' | ||
|
||
export const parser = parseAsInteger.withDefault(0).withOptions({ | ||
history: 'push' | ||
}) |
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 { GetServerSideProps } from 'next' | ||
import { Client } from '../../../app/app/push/client' | ||
import { parser } from '../../../app/app/push/searchParams' | ||
|
||
export default function Page({ server }: { server: number }) { | ||
return ( | ||
<> | ||
<p> | ||
Server side: <span id="server-side">{server}</span> | ||
</p> | ||
<Client /> | ||
</> | ||
) | ||
} | ||
|
||
export const getServerSideProps = (async ctx => { | ||
const server = parser.parseServerSide(ctx.query.server) | ||
return { | ||
props: { | ||
server | ||
} | ||
} | ||
}) satisfies GetServerSideProps<{ | ||
server: number | ||
}> |
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