Repository: vercel/next.js
File: packages/next/src/server/app-render/staged-rendering.ts (TypeScript)

Code before:

    const boundaryStage = this.hasRuntimePrefetch
      ? RenderStage.Dynamic
      : RenderStage.Runtime
    return this.currentStage < boundaryStage
  }

  syncInterruptCurrentStageWithReason(reason: Error) {
    if (this.currentStage === RenderStage.Before) {
      return
    }

    // If Sync IO occurs during the initial (abandonable) render, we'll retry it,
    // so we want a slightly different flow.
    // See the implementation of `abandonRenderImpl` for more explanation.
    if (this.mayAbandon) {
      return this.abandonRenderImpl()
    }

    // If we're in the final render, we cannot abandon it. We need to advance to the Dynamic stage
    // and capture the interruption reason.
    switch (this.currentStage) {
      case RenderStage.Static: {
        this.staticInterruptReason = reason
        this.advanceStage(RenderStage.Dynamic)
        return
      }
      case RenderStage.Runtime: {
        // We only error for Sync IO in the runtime stage if the route
        // is configured to use runtime prefetching.
        // We do this to reflect the fact that during a runtime prefetch,
        // Sync IO aborts aborts the render.
        // Note that `canSyncInterrupt` should prevent us from getting here at all
        // if runtime prefetching isn't enabled.
        if (this.hasRuntimePrefetch) {
          this.runtimeInterruptReason = reason
          this.advanceStage(RenderStage.Dynamic)
        }
        return
      }
      case RenderStage.Dynamic:
      case RenderStage.Abandoned:
      default:
    }
  }

  getStaticInterruptReason() {
    return this.staticInterruptReason
  }

  getRuntimeInterruptReason() {

Review comment (suggestion):
```suggestion
    // The abandon listener will call abandonRender which advances through
```


Code after:
  }

  canSyncInterrupt() {
    // If we haven't started the render yet, it can't be interrupted.
    if (this.currentStage === RenderStage.Before) {
      return false
    }

    const boundaryStage = this.hasRuntimePrefetch
      ? RenderStage.Dynamic
      : RenderStage.Runtime
    return this.currentStage < boundaryStage
  }

  syncInterruptCurrentStageWithReason(reason: Error) {
    if (this.currentStage === RenderStage.Before) {
      return
    }

    // If the render has already been abandoned, there's nothing to interrupt.
    if (this.currentStage === RenderStage.Abandoned) {
      return
    }

    // If Sync IO occurs during an abandonable render, we trigger the abandon.
    // The abandon listener will call abandonRenderImpl which advances through
    // stages to let caches fill before marking as Abandoned.
    if (this.abandonController) {
      this.abandonController.abort()
      return
    }

    // If we're in the final render, we cannot abandon it. We need to advance to the Dynamic stage
    // and capture the interruption reason.
    switch (this.currentStage) {
      case RenderStage.Static: {
        this.staticInterruptReason = reason
        this.advanceStage(RenderStage.Dynamic)
        return
      }
      case RenderStage.Runtime: {
        // We only error for Sync IO in the runtime stage if the route
        // is configured to use runtime prefetching.
        // We do this to reflect the fact that during a runtime prefetch,
        // Sync IO aborts aborts the render.
        // Note that `canSyncInterrupt` should prevent us from getting here at all
        // if runtime prefetching isn't enabled.
        if (this.hasRuntimePrefetch) {
          this.runtimeInterruptReason = reason
          this.advanceStage(RenderStage.Dynamic)
        }