Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dynamic segments & multitenancy for Next.js pages router #917

Merged
merged 10 commits into from
Feb 17, 2025
Prev Previous commit
Next Next commit
chore: Fix multitenant test
  • Loading branch information
franky47 committed Feb 17, 2025
commit ecc182d33d0666b1d71a7053a00e701813a50f46
30 changes: 16 additions & 14 deletions packages/e2e/next/cypress/e2e/multitenant.cy.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { createTest, type TestConfig } from 'e2e-shared/create-test'
import { getShallowUrl } from 'e2e-shared/specs/shallow.defs'
import { getOptionsUrl } from 'e2e-shared/lib/options'

function testMultiTenant(options: TestConfig) {
function testMultiTenant(
options: TestConfig & {
expectedPathname: string
}
) {
const factory = createTest('Multitenant', ({ path }) => {
for (const shallow of [true, false]) {
for (const history of ['replace', 'push'] as const) {
it(`Updates with ({ shallow: ${shallow}, history: ${history} })`, () => {
cy.visit(getShallowUrl(path, { shallow, history }))
cy.visit(getOptionsUrl(path, { shallow, history }))
cy.contains('#hydration-marker', 'hydrated').should('be.hidden')
cy.get('#client-state').should('be.empty')
cy.get('#server-state').should('be.empty')
cy.get('#client-tenant').should('have.text', 'david')
cy.get('#server-tenant').should('have.text', 'david')
cy.get('#router-pathname').should(
'have.text',
options.nextJsRouter === 'pages'
? '/pages/multitenant/[tenant]'
: '/app/multitenant'
options.expectedPathname
)
cy.get('button').click()
cy.get('#client-state').should('have.text', 'pass')
cy.get('#client-tenant').should('have.text', 'david')
cy.get('#server-tenant').should('have.text', 'david')
cy.get('#router-pathname').should(
'have.text',
options.nextJsRouter === 'pages'
? '/pages/multitenant/[tenant]'
: '/app/multitenant'
options.expectedPathname
)
if (shallow === false) {
cy.get('#server-state').should('have.text', 'pass')
@@ -43,9 +43,7 @@ function testMultiTenant(options: TestConfig) {
cy.get('#server-state').should('be.empty')
cy.get('#router-pathname').should(
'have.text',
options.nextJsRouter === 'pages'
? '/pages/multitenant/[tenant]'
: '/app/multitenant'
options.expectedPathname
)
})
}
@@ -57,10 +55,14 @@ function testMultiTenant(options: TestConfig) {

testMultiTenant({
path: '/app/multitenant',
nextJsRouter: 'app'
nextJsRouter: 'app',
description: 'Dynamic route',
expectedPathname: '/app/multitenant'
})

testMultiTenant({
path: '/pages/multitenant',
nextJsRouter: 'pages'
nextJsRouter: 'pages',
description: 'Dynamic route',
expectedPathname: '/pages/multitenant/[tenant]'
})
4 changes: 2 additions & 2 deletions packages/e2e/next/src/app/app/multitenant/[tenant]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Display } from 'e2e-shared/components/display'
import { ShallowUseQueryState } from 'e2e-shared/specs/shallow'
import { ShallowDisplay } from 'e2e-shared/specs/shallow-display'
import {
createSearchParamsCache,
parseAsString,
@@ -36,7 +36,7 @@ export default async function TenantPage({ params, searchParams }: PageProps) {
<Suspense>
<ShallowUseQueryState />
</Suspense>
<ShallowDisplay environment="server" state={cache.get('state')} />
<Display environment="server" state={cache.get('state')} />
<p id="server-tenant">{tenant}</p>
<Suspense>
<TenantClient />
4 changes: 2 additions & 2 deletions packages/e2e/next/src/pages/pages/multitenant/[tenant].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Display } from 'e2e-shared/components/display'
import { ShallowUseQueryState } from 'e2e-shared/specs/shallow'
import { ShallowDisplay } from 'e2e-shared/specs/shallow-display'
import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next'
import { useParams } from 'next/navigation'
import { useRouter } from 'next/router'
@@ -15,7 +15,7 @@ export default function Page({ serverState, tenant }: Props) {
return (
<>
<ShallowUseQueryState />
<ShallowDisplay environment="server" state={serverState} />
<Display environment="server" state={serverState} />
<p id="server-tenant">{tenant}</p>
<p id="client-tenant">{params?.tenant}</p>
<p id="router-pathname">{router.pathname}</p>