mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Write to a marker file to determine when the slow server component finishes rendering instead of trying to sleep for some fixed amount of time.
21 lines
522 B
TypeScript
21 lines
522 B
TypeScript
import { setTimeout } from 'node:timers/promises'
|
|
import { access } from 'node:fs/promises'
|
|
import path from 'node:path'
|
|
import React from 'react'
|
|
|
|
export default async function waitForMarkerFile() {
|
|
const signal = React.cacheSignal()
|
|
if (!signal) {
|
|
throw new Error('cacheSignal returned null, are we not rendering?')
|
|
}
|
|
while (true) {
|
|
try {
|
|
await access(path.join(process.cwd(), 'slowComponentReady'))
|
|
return
|
|
} catch (e) {
|
|
await setTimeout(100, { signal })
|
|
continue
|
|
}
|
|
}
|
|
}
|