Skip to content

Commit 06765ee

Browse files
committed
revert CacheSignal.cacheReady changes
1 parent dfd66b4 commit 06765ee

File tree

4 files changed

+8
-29
lines changed

4 files changed

+8
-29
lines changed

packages/next/src/server/app-render/app-render.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ async function prospectiveRuntimeServerPrerender(
733733

734734
// The cacheSignal helps us track whether caches are still filling or we are ready
735735
// to cut the render off.
736-
const cacheSignal = new CacheSignal('prerender')
736+
const cacheSignal = new CacheSignal()
737737

738738
const initialServerPrerenderStore: PrerenderStoreModernRuntime = {
739739
type: 'prerender-runtime',
@@ -2211,7 +2211,7 @@ async function renderToStream(
22112211

22122212
// This render might end up being used as a prospective render (if there's cache misses),
22132213
// so we need to set it up for filling caches.
2214-
const cacheSignal = new CacheSignal('render')
2214+
const cacheSignal = new CacheSignal()
22152215

22162216
// If we encounter async modules that delay rendering, we'll also need to restart.
22172217
// TODO(restart-on-cache-miss): technically, we only need to wait for pending *server* modules here,
@@ -2828,7 +2828,7 @@ async function spawnDynamicValidationInDev(
28282828

28292829
// The cacheSignal helps us track whether caches are still filling or we are
28302830
// ready to cut the render off.
2831-
const cacheSignal = new CacheSignal('prerender')
2831+
const cacheSignal = new CacheSignal()
28322832

28332833
const captureOwnerStackClient = React.captureOwnerStack
28342834
const captureOwnerStackServer = ComponentMod.captureOwnerStack
@@ -3568,7 +3568,7 @@ async function prerenderToStream(
35683568

35693569
// The cacheSignal helps us track whether caches are still filling or we are ready
35703570
// to cut the render off.
3571-
const cacheSignal = new CacheSignal('prerender')
3571+
const cacheSignal = new CacheSignal()
35723572

35733573
let resumeDataCache: RenderResumeDataCache | PrerenderResumeDataCache
35743574
let renderResumeDataCache: RenderResumeDataCache | null = null

packages/next/src/server/app-render/cache-signal.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
* and should only be used in codepaths gated with this feature.
66
*/
77

8-
import { waitAtLeastOneReactRenderTask } from '../../lib/scheduler'
98
import { InvariantError } from '../../shared/lib/invariant-error'
109

11-
type CacheSignalMode = 'prerender' | 'render'
12-
1310
export class CacheSignal {
1411
private count = 0
1512
private earlyListeners: Array<() => void> = []
@@ -19,7 +16,7 @@ export class CacheSignal {
1916

2017
private subscribedSignals: Set<CacheSignal> | null = null
2118

22-
constructor(private mode: CacheSignalMode) {
19+
constructor() {
2320
if (process.env.NEXT_RUNTIME === 'edge') {
2421
// we rely on `process.nextTick`, which is not supported in edge
2522
throw new InvariantError(
@@ -73,23 +70,7 @@ export class CacheSignal {
7370
* if there are no inflight cache reads then we wait at least one task to allow initial
7471
* cache reads to be initiated.
7572
*/
76-
async cacheReady(): Promise<void> {
77-
if (this.mode === 'prerender') {
78-
return await this.cacheReadyImpl()
79-
} else {
80-
// During a render, React pings pending tasks (that are waiting for something async to resolve) using `setImmediate`.
81-
// This is unlike a prerender, where they are pinged in a microtask.
82-
// This means that, if we're warming caches via a render (not a prerender),
83-
// we need to give React more time to continue rendering after a cache has resolved
84-
// in order to make sure we've discovered all the caches needed for the current render.
85-
do {
86-
await this.cacheReadyImpl()
87-
await waitAtLeastOneReactRenderTask()
88-
} while (this.hasPendingReads())
89-
}
90-
}
91-
92-
private cacheReadyImpl() {
73+
cacheReady() {
9374
return new Promise<void>((resolve) => {
9475
this.listeners.push(resolve)
9576
if (this.count === 0) {

packages/next/src/server/app-render/module-loading/track-module-loading.instance.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import { isThenable } from '../../../shared/lib/is-thenable'
88
let _moduleLoadingSignal: CacheSignal | null
99
function getModuleLoadingSignal() {
1010
if (!_moduleLoadingSignal) {
11-
// The mode doesn't really matter here, because we never wait for `cacheReady()` on this signal,
12-
// only other signals that subscribe to it via `trackPendingModules`.
13-
_moduleLoadingSignal = new CacheSignal('prerender')
11+
_moduleLoadingSignal = new CacheSignal()
1412
}
1513
return _moduleLoadingSignal
1614
}

packages/next/src/server/route-modules/app-route/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ export class AppRouteRouteModule extends RouteModule<
376376
*/
377377
const prospectiveController = new AbortController()
378378
let prospectiveRenderIsDynamic = false
379-
const cacheSignal = new CacheSignal('prerender')
379+
const cacheSignal = new CacheSignal()
380380
let dynamicTracking = createDynamicTrackingState(undefined)
381381

382382
// TODO: Route handlers are never resumed, so it's counter-intuitive

0 commit comments

Comments
 (0)