Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Storage Cleanup #46586

Merged
merged 2 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function getHandle({ page, mod }: any) {
extendedReq,
extendedRes,
// TODO: pass incrementalCache here
{},
{ supportsDynamicHTML: true },
request
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface StaticGenerationStore {
readonly isRevalidate?: boolean

forceDynamic?: boolean
revalidate?: boolean | number
revalidate?: false | number
forceStatic?: boolean
dynamicShouldError?: boolean
pendingRevalidates?: Promise<any>[]
Expand Down
10 changes: 5 additions & 5 deletions packages/next/src/server/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import type { StaticGenerationAsyncStorage } from '../client/components/static-g
import type { RequestAsyncStorage } from '../client/components/request-async-storage'
import { formatServerError } from '../lib/format-server-error'
import { MetadataTree } from '../lib/metadata/metadata'
import { runWithRequestAsyncStorage } from './run-with-request-async-storage'
import { runWithStaticGenerationAsyncStorage } from './run-with-static-generation-async-storage'
import { RequestAsyncStorageWrapper } from './async-storage/request-async-storage-wrapper'
import { StaticGenerationAsyncStorageWrapper } from './async-storage/static-generation-async-storage-wrapper'
import { collectMetadata } from '../lib/metadata/resolve-metadata'
import type { MetadataItems } from '../lib/metadata/resolve-metadata'
import { isClientReference } from '../build/is-client-reference'
Expand Down Expand Up @@ -184,7 +184,7 @@ export type RenderOptsPartial = {
dev?: boolean
serverComponentManifest?: FlightManifest
serverCSSManifest?: FlightCSSManifest
supportsDynamicHTML?: boolean
supportsDynamicHTML: boolean
runtime?: ServerRuntime
serverComponents?: boolean
assetPrefix?: string
Expand Down Expand Up @@ -2001,11 +2001,11 @@ export async function renderToHTMLOrFlight(
return renderResult
}

return runWithRequestAsyncStorage(
return RequestAsyncStorageWrapper.wrap(
requestAsyncStorage,
{ req, res, renderOpts },
() =>
runWithStaticGenerationAsyncStorage(
StaticGenerationAsyncStorageWrapper.wrap(
staticGenerationAsyncStorage,
{ pathname, renderOpts },
() => wrappedRender()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type RequestContext = {
pathname: string
renderOpts: {
incrementalCache?: IncrementalCache
supportsDynamicHTML?: boolean
supportsDynamicHTML: boolean
isRevalidate?: boolean
isBot?: boolean
}
Expand Down Expand Up @@ -45,11 +45,8 @@ export class StaticGenerationAsyncStorageWrapper
* These rules help ensure that other existing features like request caching,
* coalescing, and ISR continue working as intended.
*/
const supportsDynamicHTML =
typeof renderOpts.supportsDynamicHTML !== 'boolean' ||
renderOpts.supportsDynamicHTML

const isStaticGeneration = !supportsDynamicHTML && !renderOpts.isBot
const isStaticGeneration =
!renderOpts.supportsDynamicHTML && !renderOpts.isBot

const store: StaticGenerationStore = {
isStaticGeneration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export type AppRouteModule = {

export type StaticGenerationContext = {
incrementalCache?: IncrementalCache
supportsDynamicHTML?: boolean
supportsDynamicHTML: boolean
}

/**
Expand Down Expand Up @@ -309,23 +309,25 @@ export class AppRouteRouteHandler implements RouteHandler<AppRouteRouteMatch> {
staticGenerationAsyncStorage,
{
pathname: definition.pathname,
renderOpts: context || {},
renderOpts: context ?? {
supportsDynamicHTML: false,
},
},
() => {
const _req = (request ? request : wrapRequest(req)) as NextRequest

// We can currently only statically optimize if only GET/HEAD
// are used as a Prerender can't be used conditionally based
// on the method currently
const nonStaticHandlers = [
const nonStaticHandlers: ReadonlyArray<HTTP_METHOD> = [
'OPTIONS',
'POST',
'PUT',
'DELETE',
'PATCH',
]
const usedNonStaticHandlers = nonStaticHandlers.filter(
(name) => !!(module.handlers as any)[name]
(name) => name in module.handlers
)

if (usedNonStaticHandlers.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export type RenderOptsPartial = {
defaultLocale?: string
domainLocales?: DomainLocale[]
disableOptimizedLoading?: boolean
supportsDynamicHTML?: boolean
supportsDynamicHTML: boolean
isBot?: boolean
runtime?: ServerRuntime
serverComponents?: boolean
Expand Down
77 changes: 0 additions & 77 deletions packages/next/src/server/run-with-request-async-storage.ts

This file was deleted.

This file was deleted.