-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16b12f9
commit c3a3aff
Showing
16 changed files
with
504 additions
and
1 deletion.
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,27 @@ | ||
import { unstable_after as after } from 'next/server' | ||
import { cache } from 'react' | ||
import { persistentLog } from '../../../utils/log' | ||
import { headers } from 'next/headers' | ||
|
||
const thing = cache(() => Symbol('cache me please')) | ||
|
||
export default function Index({ params }) { | ||
const hostFromRender = headers().get('host') | ||
const valueFromRender = thing() | ||
|
||
after(() => { | ||
const hostFromAfter = headers().get('host') | ||
const valueFromAfter = thing() | ||
|
||
persistentLog({ | ||
source: '[page] /[id]/dynamic', | ||
value: params.id, | ||
assertions: { | ||
'cache() works in after()': valueFromRender === valueFromAfter, | ||
'headers() works in after()': hostFromRender === hostFromAfter, | ||
}, | ||
}) | ||
}) | ||
|
||
return <div>Page with after()</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { unstable_after as after } from 'next/server' | ||
import { persistentLog } from '../../utils/log' | ||
|
||
export default function Layout({ children }) { | ||
after(async () => { | ||
persistentLog({ source: '[layout] /[id]' }) | ||
}) | ||
return <>{children}</> | ||
} |
28 changes: 28 additions & 0 deletions
28
test/e2e/app-dir/next-after/app/[id]/setting-cookies/page.js
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 @@ | ||
import { unstable_after as after } from 'next/server' | ||
import { cookies } from 'next/headers' | ||
|
||
export default function Index() { | ||
after(() => { | ||
cookies().set('testCookie', 'after-render') | ||
}) | ||
const action = async () => { | ||
'use server' | ||
cookies().set('testCookie', 'action') | ||
|
||
after(() => { | ||
cookies().set('testCookie', 'after-action') | ||
}) | ||
} | ||
|
||
return ( | ||
<div> | ||
<h1>Page with after() that tries to set cookies</h1> | ||
<div id="cookie"> | ||
Cookie: {JSON.stringify(cookies().get('testCookie')?.value ?? null)} | ||
</div> | ||
<form action={action}> | ||
<button type="submit">Submit</button> | ||
</form> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { unstable_after as after } from 'next/server' | ||
import { cache } from 'react' | ||
import { persistentLog } from '../../../utils/log' | ||
import { headers } from 'next/headers' | ||
|
||
const thing = cache(() => Symbol('cache me please')) | ||
|
||
export default function Index({ params }) { | ||
const action = async () => { | ||
'use server' | ||
|
||
const hostFromAction = headers().get('host') | ||
const valueFromAction = thing() | ||
|
||
after(() => { | ||
const valueFromAfter = thing() | ||
const hostFromAfter = headers().get('host') | ||
|
||
persistentLog({ | ||
source: '[action] /[id]/with-action', | ||
value: params.id, | ||
assertions: { | ||
'cache() works in after()': valueFromAction === valueFromAfter, | ||
'headers() works in after()': hostFromAction === hostFromAfter, | ||
}, | ||
}) | ||
}) | ||
} | ||
|
||
return ( | ||
<div> | ||
<h1>Page with after() in an action</h1> | ||
<form action={action}> | ||
<button type="submit">Submit</button> | ||
</form> | ||
</div> | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
test/e2e/app-dir/next-after/app/[id]/with-metadata/page.js
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 { unstable_after as after } from 'next/server' | ||
import { persistentLog } from '../../../utils/log' | ||
|
||
export function generateMetadata({ params }) { | ||
after(() => { | ||
persistentLog({ | ||
source: '[metadata] /[id]/with-metadata', | ||
value: params.id, | ||
}) | ||
}) | ||
return { | ||
title: `With metadata: ${params.id}`, | ||
} | ||
} | ||
|
||
export default function Page() { | ||
return <div>With metadata</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Suspense } from 'react' | ||
import { unstable_after as after } from 'next/server' | ||
import { persistentLog } from '../../utils/log' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export default async function Page() { | ||
after(() => { | ||
persistentLog({ source: '[page] /delay (Page)' }) | ||
}) | ||
return ( | ||
<Suspense fallback={'Loading...'}> | ||
<Inner>Delay</Inner> | ||
</Suspense> | ||
) | ||
} | ||
|
||
async function Inner({ children }) { | ||
after(() => { | ||
persistentLog({ source: '[page] /delay (Inner)' }) | ||
}) | ||
|
||
// the test intercepts this to assert on whether the after() callbacks ran | ||
// before and after we finish handling the request. | ||
await fetch('https://example.test/delayed-request', { | ||
signal: AbortSignal.timeout(10_000), | ||
}) | ||
|
||
return <>{children}</> | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/next-after/app/interrupted/calls-not-found/page.js
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 @@ | ||
import { notFound } from 'next/navigation' | ||
import { unstable_after as after } from 'next/server' | ||
import { persistentLog } from '../../../utils/log' | ||
|
||
export default function Page() { | ||
after(() => { | ||
persistentLog({ | ||
source: '[page] /interrupted/calls-not-found', | ||
}) | ||
}) | ||
notFound() | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/next-after/app/interrupted/calls-redirect/page.js
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 @@ | ||
import { redirect } from 'next/navigation' | ||
import { unstable_after as after } from 'next/server' | ||
import { persistentLog } from '../../../utils/log' | ||
|
||
export default function Page() { | ||
after(() => { | ||
persistentLog({ | ||
source: '[page] /interrupted/calls-redirect', | ||
}) | ||
}) | ||
redirect('/interrupted/redirect-target') | ||
} |
11 changes: 11 additions & 0 deletions
11
test/e2e/app-dir/next-after/app/interrupted/redirect-target/page.js
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 { unstable_after as after } from 'next/server' | ||
import { persistentLog } from '../../../utils/log' | ||
|
||
export default function Page() { | ||
after(() => { | ||
persistentLog({ | ||
source: '[page] /interrupted/redirect-target', | ||
}) | ||
}) | ||
return <div>Redirect</div> | ||
} |
11 changes: 11 additions & 0 deletions
11
test/e2e/app-dir/next-after/app/interrupted/throws-error/page.js
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 { unstable_after as after } from 'next/server' | ||
import { persistentLog } from '../../../utils/log' | ||
|
||
export default function Page() { | ||
after(() => { | ||
persistentLog({ | ||
source: '[page] /interrupted/throws-error', | ||
}) | ||
}) | ||
throw new Error('User error') | ||
} |
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,10 @@ | ||
export default function AppLayout({ children }) { | ||
return ( | ||
<html> | ||
<head> | ||
<title>after</title> | ||
</head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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,3 @@ | ||
export default function Page() { | ||
return <div>Redirect</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { unstable_after as after } from 'next/server' | ||
import { persistentLog } from '../../utils/log' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export async function GET() { | ||
const data = { message: 'Hello, world!' } | ||
after(() => { | ||
persistentLog({ source: '[route handler] /route' }) | ||
}) | ||
|
||
return Response.json({ data }) | ||
} |
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 @@ | ||
import { unstable_after as after } from 'next/server' | ||
import { persistentLog } from '../../utils/log' | ||
|
||
// (patched in tests) | ||
// export const dynamic = 'REPLACE_ME' | ||
|
||
export default function Index() { | ||
after(async () => { | ||
persistentLog({ source: '[page] /static' }) | ||
}) | ||
return <div>Page with after()</div> | ||
} |
Oops, something went wrong.