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

revert CacheSignal.cacheReady changes

parent dfd66b4c
...@@ -733,7 +733,7 @@ async function prospectiveRuntimeServerPrerender( ...@@ -733,7 +733,7 @@ async function prospectiveRuntimeServerPrerender(
// The cacheSignal helps us track whether caches are still filling or we are ready // The cacheSignal helps us track whether caches are still filling or we are ready
// to cut the render off. // to cut the render off.
const cacheSignal = new CacheSignal('prerender') const cacheSignal = new CacheSignal()
const initialServerPrerenderStore: PrerenderStoreModernRuntime = { const initialServerPrerenderStore: PrerenderStoreModernRuntime = {
type: 'prerender-runtime', type: 'prerender-runtime',
...@@ -2211,7 +2211,7 @@ async function renderToStream( ...@@ -2211,7 +2211,7 @@ async function renderToStream(
// This render might end up being used as a prospective render (if there's cache misses), // 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. // 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. // 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, // TODO(restart-on-cache-miss): technically, we only need to wait for pending *server* modules here,
...@@ -2828,7 +2828,7 @@ async function spawnDynamicValidationInDev( ...@@ -2828,7 +2828,7 @@ async function spawnDynamicValidationInDev(
// The cacheSignal helps us track whether caches are still filling or we are // The cacheSignal helps us track whether caches are still filling or we are
// ready to cut the render off. // ready to cut the render off.
const cacheSignal = new CacheSignal('prerender') const cacheSignal = new CacheSignal()
const captureOwnerStackClient = React.captureOwnerStack const captureOwnerStackClient = React.captureOwnerStack
const captureOwnerStackServer = ComponentMod.captureOwnerStack const captureOwnerStackServer = ComponentMod.captureOwnerStack
...@@ -3568,7 +3568,7 @@ async function prerenderToStream( ...@@ -3568,7 +3568,7 @@ async function prerenderToStream(
// The cacheSignal helps us track whether caches are still filling or we are ready // The cacheSignal helps us track whether caches are still filling or we are ready
// to cut the render off. // to cut the render off.
const cacheSignal = new CacheSignal('prerender') const cacheSignal = new CacheSignal()
let resumeDataCache: RenderResumeDataCache | PrerenderResumeDataCache let resumeDataCache: RenderResumeDataCache | PrerenderResumeDataCache
let renderResumeDataCache: RenderResumeDataCache | null = null let renderResumeDataCache: RenderResumeDataCache | null = null
......
...@@ -5,11 +5,8 @@ ...@@ -5,11 +5,8 @@
* and should only be used in codepaths gated with this feature. * and should only be used in codepaths gated with this feature.
*/ */
import { waitAtLeastOneReactRenderTask } from '../../lib/scheduler'
import { InvariantError } from '../../shared/lib/invariant-error' import { InvariantError } from '../../shared/lib/invariant-error'
type CacheSignalMode = 'prerender' | 'render'
export class CacheSignal { export class CacheSignal {
private count = 0 private count = 0
private earlyListeners: Array<() => void> = [] private earlyListeners: Array<() => void> = []
...@@ -19,7 +16,7 @@ export class CacheSignal { ...@@ -19,7 +16,7 @@ export class CacheSignal {
private subscribedSignals: Set<CacheSignal> | null = null private subscribedSignals: Set<CacheSignal> | null = null
constructor(private mode: CacheSignalMode) { constructor() {
if (process.env.NEXT_RUNTIME === 'edge') { if (process.env.NEXT_RUNTIME === 'edge') {
// we rely on `process.nextTick`, which is not supported in edge // we rely on `process.nextTick`, which is not supported in edge
throw new InvariantError( throw new InvariantError(
...@@ -73,23 +70,7 @@ export class CacheSignal { ...@@ -73,23 +70,7 @@ export class CacheSignal {
* if there are no inflight cache reads then we wait at least one task to allow initial * if there are no inflight cache reads then we wait at least one task to allow initial
* cache reads to be initiated. * cache reads to be initiated.
*/ */
async cacheReady(): Promise<void> { cacheReady() {
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() {
return new Promise<void>((resolve) => { return new Promise<void>((resolve) => {
this.listeners.push(resolve) this.listeners.push(resolve)
if (this.count === 0) { if (this.count === 0) {
......
...@@ -8,9 +8,7 @@ import { isThenable } from '../../../shared/lib/is-thenable' ...@@ -8,9 +8,7 @@ import { isThenable } from '../../../shared/lib/is-thenable'
let _moduleLoadingSignal: CacheSignal | null let _moduleLoadingSignal: CacheSignal | null
function getModuleLoadingSignal() { function getModuleLoadingSignal() {
if (!_moduleLoadingSignal) { if (!_moduleLoadingSignal) {
// The mode doesn't really matter here, because we never wait for `cacheReady()` on this signal, _moduleLoadingSignal = new CacheSignal()
// only other signals that subscribe to it via `trackPendingModules`.
_moduleLoadingSignal = new CacheSignal('prerender')
} }
return _moduleLoadingSignal return _moduleLoadingSignal
} }
......
...@@ -376,7 +376,7 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -376,7 +376,7 @@ export class AppRouteRouteModule extends RouteModule<
*/ */
const prospectiveController = new AbortController() const prospectiveController = new AbortController()
let prospectiveRenderIsDynamic = false let prospectiveRenderIsDynamic = false
const cacheSignal = new CacheSignal('prerender') const cacheSignal = new CacheSignal()
let dynamicTracking = createDynamicTrackingState(undefined) let dynamicTracking = createDynamicTrackingState(undefined)
// TODO: Route handlers are never resumed, so it's counter-intuitive // 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