mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
6dbf9c32ec
We insert the content returning from `useServerInsertedHTML` to head element for app dir, but it shouldn't only inject once since there're suspense boundaries that could hold insertions. ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` Co-authored-by: JJ Kasper <jj@jjsweb.site>
20 lines
454 B
JavaScript
20 lines
454 B
JavaScript
export function createDataFetcher(data, { timeout = 0, expire = 10 }) {
|
|
let result
|
|
let promise
|
|
return function Data() {
|
|
if (result) return result
|
|
if (!promise)
|
|
promise = new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
result = data
|
|
setTimeout(() => {
|
|
result = undefined
|
|
promise = undefined
|
|
}, expire)
|
|
resolve()
|
|
}, timeout)
|
|
})
|
|
throw promise
|
|
}
|
|
}
|