-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: unstable_after in a simulated invocation
- Loading branch information
1 parent
8bac76a
commit 4ef0690
Showing
10 changed files
with
524 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Suspense } from 'react' | ||
import { unstable_after as after } from 'next/server' | ||
import { cliLog } from '../../utils/log' | ||
import { sleep } from '../../utils/sleep' | ||
|
||
// don't waste time prerendering, after() will bail out anyway | ||
export const dynamic = 'force-dynamic' | ||
|
||
export default async function Page() { | ||
cliLog({ source: '[page] /delay-deep (Page) - render' }) | ||
return ( | ||
<Suspense fallback={'Loading...'}> | ||
<Inner>Delay</Inner> | ||
</Suspense> | ||
) | ||
} | ||
|
||
async function Inner({ children }) { | ||
cliLog({ | ||
source: '[page] /delay-deep (Inner) - render, sleeping', | ||
}) | ||
|
||
await sleep(1000) | ||
|
||
cliLog({ | ||
source: '[page] /delay-deep (Inner) - render, done sleeping', | ||
}) | ||
|
||
return ( | ||
<div> | ||
<Suspense fallback="Loading 2..."> | ||
<Inner2>{children}</Inner2> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
async function Inner2({ children }) { | ||
cliLog({ | ||
source: '[page] /delay-deep (Inner2) - render, sleeping', | ||
}) | ||
|
||
await sleep(1000) | ||
|
||
cliLog({ | ||
source: '[page] /delay-deep (Inner2) - render, done sleeping', | ||
}) | ||
|
||
after(async () => { | ||
await sleep(1000) | ||
cliLog({ source: '[page] /delay-deep (Inner2) - after' }) | ||
}) | ||
|
||
return <>{children}</> | ||
} |
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
46 changes: 46 additions & 0 deletions
46
test/e2e/app-dir/next-after-app/app/route-streaming/route.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,46 @@ | ||
import { unstable_after as after } from 'next/server' | ||
import { cliLog } from '../../utils/log' | ||
import { sleep } from '../../utils/sleep' | ||
import { maybeInstallInvocationShutdownHook } from '../../utils/simulated-invocation' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
// (patched in tests) | ||
// export const runtime = 'REPLACE_ME' | ||
|
||
export async function GET() { | ||
maybeInstallInvocationShutdownHook() | ||
|
||
/** @type {ReadableStream<Uint8Array>} */ | ||
const result = new ReadableStream({ | ||
async start(controller) { | ||
cliLog({ | ||
source: '[route handler] /route-streaming - body, sleeping', | ||
}) | ||
await sleep(500) | ||
cliLog({ | ||
source: '[route handler] /route-streaming - body, done sleeping', | ||
}) | ||
|
||
const encoder = new TextEncoder() | ||
for (const chunk of ['one', 'two', 'three']) { | ||
await sleep(500) | ||
controller.enqueue(encoder.encode(chunk + '\r\n')) | ||
} | ||
|
||
after(async () => { | ||
await sleep(1000) | ||
cliLog({ | ||
source: '[route handler] /route-streaming - after', | ||
}) | ||
}) | ||
controller.close() | ||
}, | ||
}) | ||
return new Response(result, { | ||
headers: { | ||
'content-type': 'text/plain; charset=utf-8', | ||
'transfer-encoding': 'chunked', | ||
}, | ||
}) | ||
} |
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
Oops, something went wrong.