Commit 06765ee2 authored by Janka Uryga's avatar Janka Uryga

revert CacheSignal.cacheReady changes

parent dfd66b4c
......@@ -733,7 +733,7 @@ async function prospectiveRuntimeServerPrerender(
// The cacheSignal helps us track whether caches are still filling or we are ready
// to cut the render off.
const cacheSignal = new CacheSignal('prerender')
const cacheSignal = new CacheSignal()
const initialServerPrerenderStore: PrerenderStoreModernRuntime = {
type: 'prerender-runtime',
......@@ -2211,7 +2211,7 @@ async function renderToStream(
// This render might end up being used as a prospective render (if there's cache misses),
// so we need to set it up for filling caches.
const cacheSignal = new CacheSignal('render')
const cacheSignal = new CacheSignal()
// If we encounter async modules that delay rendering, we'll also need to restart.
// TODO(restart-on-cache-miss): technically, we only need to wait for pending *server* modules here,
......@@ -2828,7 +2828,7 @@ async function spawnDynamicValidationInDev(
// The cacheSignal helps us track whether caches are still filling or we are
// ready to cut the render off.
const cacheSignal = new CacheSignal('prerender')
const cacheSignal = new CacheSignal()
const captureOwnerStackClient = React.captureOwnerStack
const captureOwnerStackServer = ComponentMod.captureOwnerStack
......@@ -3568,7 +3568,7 @@ async function prerenderToStream(
// The cacheSignal helps us track whether caches are still filling or we are ready
// to cut the render off.
const cacheSignal = new CacheSignal('prerender')
const cacheSignal = new CacheSignal()
let resumeDataCache: RenderResumeDataCache | PrerenderResumeDataCache
let renderResumeDataCache: RenderResumeDataCache | null = null
......
......@@ -5,11 +5,8 @@
* and should only be used in codepaths gated with this feature.
*/
import { waitAtLeastOneReactRenderTask } from '../../lib/scheduler'
import { InvariantError } from '../../shared/lib/invariant-error'
type CacheSignalMode = 'prerender' | 'render'
export class CacheSignal {
private count = 0
private earlyListeners: Array<() => void> = []
......@@ -19,7 +16,7 @@ export class CacheSignal {
private subscribedSignals: Set<CacheSignal> | null = null
constructor(private mode: CacheSignalMode) {
constructor() {
if (process.env.NEXT_RUNTIME === 'edge') {
// we rely on `process.nextTick`, which is not supported in edge
throw new InvariantError(
......@@ -73,23 +70,7 @@ export class CacheSignal {
* if there are no inflight cache reads then we wait at least one task to allow initial
* cache reads to be initiated.
*/
async cacheReady(): Promise<void> {
if (this.mode === 'prerender') {
return await this.cacheReadyImpl()
} else {
// During a render, React pings pending tasks (that are waiting for something async to resolve) using `setImmediate`.
// This is unlike a prerender, where they are pinged in a microtask.
// This means that, if we're warming caches via a render (not a prerender),
// we need to give React more time to continue rendering after a cache has resolved
// in order to make sure we've discovered all the caches needed for the current render.
do {
await this.cacheReadyImpl()
await waitAtLeastOneReactRenderTask()
} while (this.hasPendingReads())
}
}
private cacheReadyImpl() {
cacheReady() {
return new Promise<void>((resolve) => {
this.listeners.push(resolve)
if (this.count === 0) {
......
......@@ -8,9 +8,7 @@ import { isThenable } from '../../../shared/lib/is-thenable'
let _moduleLoadingSignal: CacheSignal | null
function getModuleLoadingSignal() {
if (!_moduleLoadingSignal) {
// The mode doesn't really matter here, because we never wait for `cacheReady()` on this signal,
// only other signals that subscribe to it via `trackPendingModules`.
_moduleLoadingSignal = new CacheSignal('prerender')
_moduleLoadingSignal = new CacheSignal()
}
return _moduleLoadingSignal
}
......
......@@ -376,7 +376,7 @@ export class AppRouteRouteModule extends RouteModule<
*/
const prospectiveController = new AbortController()
let prospectiveRenderIsDynamic = false
const cacheSignal = new CacheSignal('prerender')
const cacheSignal = new CacheSignal()
let dynamicTracking = createDynamicTrackingState(undefined)
// TODO: Route handlers are never resumed, so it's counter-intuitive
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment