Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for notFound during streaming (#44078)
Add test for notFound case added in #41735
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 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,41 @@ | ||
import { Suspense } from 'react' | ||
import { notFound } from 'next/navigation' | ||
|
||
function createSuspenseyComponent(Component, { timeout = 0, expire = 10 }) { | ||
let result | ||
let promise | ||
return function Data() { | ||
if (result) return result | ||
if (!promise) | ||
promise = new Promise((resolve) => { | ||
setTimeout(() => { | ||
result = <Component /> | ||
setTimeout(() => { | ||
result = undefined | ||
promise = undefined | ||
}, expire) | ||
resolve() | ||
}, timeout) | ||
}) | ||
throw promise | ||
} | ||
} | ||
|
||
function NotFound() { | ||
notFound() | ||
return <></> | ||
} | ||
|
||
const SuspenseyNotFound = createSuspenseyComponent(NotFound, { | ||
timeout: 300, | ||
}) | ||
|
||
export default function () { | ||
return ( | ||
<div className="suspense"> | ||
<Suspense fallback="fallback"> | ||
<SuspenseyNotFound /> | ||
</Suspense> | ||
</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