Skip to content

Commit

Permalink
Revert "Dedupe sync access warning on the Server by callsite" (#70736)
Browse files Browse the repository at this point in the history
This fails the 18.3.1 matrix since `React.cache` is unavailable.

Needs to be relanded with a patch to no-op in this case.

Reverts #70672
  • Loading branch information
ztanner authored Oct 3, 2024
1 parent fb85644 commit ebffec2
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 477 deletions.

This file was deleted.

28 changes: 11 additions & 17 deletions packages/next/src/server/request/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { actionAsyncStorage } from '../../client/components/action-async-storage
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout'
import { makeResolvedReactPromise } from './utils'
import { makeHangingPromise } from '../dynamic-rendering-utils'
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-loger'

/**
* In this version of Next.js `cookies()` returns a Promise however you can still reference the properties of the underlying cookies object
Expand Down Expand Up @@ -513,30 +512,25 @@ const noop = () => {}
const warnForSyncIteration = process.env
.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS
? noop
: createDedupedByCallsiteServerErrorLoggerDev(
function getSyncIterationMessage(route?: string) {
const prefix = route ? ` In route ${route} ` : ''
return (
`${prefix}cookies were iterated over. ` +
: function warnForSyncIteration(route?: string) {
const prefix = route ? ` In route ${route} ` : ''
console.error(
`${prefix}cookies were iterated over. ` +
`\`cookies()\` should be awaited before using its value. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
)
}
)
)
}

const warnForSyncAccess = process.env.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS
? noop
: createDedupedByCallsiteServerErrorLoggerDev(function getSyncAccessMessage(
route: undefined | string,
expression: string
) {
: function warnForSyncAccess(route: undefined | string, expression: string) {
const prefix = route ? ` In route ${route} a ` : 'A '
return (
console.error(
`${prefix}cookie property was accessed directly with \`${expression}\`. ` +
`\`cookies()\` should be awaited before using its value. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
`\`cookies()\` should be awaited before using its value. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
)
})
}

function polyfilledResponseCookiesIterator(
this: ResponseCookies
Expand Down
14 changes: 5 additions & 9 deletions packages/next/src/server/request/draft-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { DraftModeProvider } from '../../server/async-storage/draft-mode-pr

import { workAsyncStorage } from '../../client/components/work-async-storage.external'
import { trackDynamicDataAccessed } from '../app-render/dynamic-rendering'
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-loger'

/**
* In this version of Next.js `draftMode()` returns a Promise however you can still reference the properties of the underlying draftMode object
Expand Down Expand Up @@ -165,14 +164,11 @@ const noop = () => {}

const warnForSyncAccess = process.env.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS
? noop
: createDedupedByCallsiteServerErrorLoggerDev(function getSyncAccessWarning(
route: undefined | string,
expression: string
) {
: function warnForSyncAccess(route: undefined | string, expression: string) {
const prefix = route ? ` In route ${route} a ` : 'A '
return (
console.error(
`${prefix}\`draftMode()\` property was accessed directly with \`${expression}\`. ` +
`\`draftMode()\` should be awaited before using its value. ` +
`Learn more: https://nextjs.org/docs/messages/draft-mode-sync-access`
`\`draftMode()\` should be awaited before using its value. ` +
`Learn more: https://nextjs.org/docs/messages/draft-mode-sync-access`
)
})
}
28 changes: 11 additions & 17 deletions packages/next/src/server/request/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout'
import { makeResolvedReactPromise } from './utils'
import { makeHangingPromise } from '../dynamic-rendering-utils'
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-loger'

/**
* In this version of Next.js `headers()` returns a Promise however you can still reference the properties of the underlying Headers instance
Expand Down Expand Up @@ -428,30 +427,25 @@ const noop = () => {}
const warnForSyncIteration = process.env
.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS
? noop
: createDedupedByCallsiteServerErrorLoggerDev(
function getSyncIterationMessage(route?: string) {
const prefix = route ? ` In route ${route} ` : ''
return (
`${prefix}headers were iterated over. ` +
: function warnForSyncIteration(route?: string) {
const prefix = route ? ` In route ${route} ` : ''
console.error(
`${prefix}headers were iterated over. ` +
`\`headers()\` should be awaited before using its value. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
)
}
)
)
}

const warnForSyncAccess = process.env.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS
? noop
: createDedupedByCallsiteServerErrorLoggerDev(function getSyncAccessMessage(
route: undefined | string,
expression: string
) {
: function warnForSyncAccess(route: undefined | string, expression: string) {
const prefix = route ? ` In route ${route} a ` : 'A '
return (
console.error(
`${prefix}header property was accessed directly with \`${expression}\`. ` +
`\`headers()\` should be awaited before using its value. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
`\`headers()\` should be awaited before using its value. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
)
})
}

type HeadersExtensions = {
[K in keyof ReadonlyHeaders]: unknown
Expand Down
38 changes: 21 additions & 17 deletions packages/next/src/server/request/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { InvariantError } from '../../shared/lib/invariant-error'
import { makeResolvedReactPromise, describeStringPropertyAccess } from './utils'
import { makeHangingPromise } from '../dynamic-rendering-utils'
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-loger'

export type Params = Record<string, string | Array<string> | undefined>

Expand Down Expand Up @@ -491,41 +490,46 @@ const noop = () => {}

const warnForSyncAccess = process.env.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS
? noop
: createDedupedByCallsiteServerErrorLoggerDev(function getSyncAccessMessage(
route: undefined | string,
expression: string
) {
: function warnForSyncAccess(route: undefined | string, expression: string) {
if (process.env.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS) {
return
}

const prefix = route ? ` In route ${route} a ` : 'A '
return (
console.error(
`${prefix}param property was accessed directly with ${expression}. ` +
`\`params\` should be awaited before accessing its properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
`\`params\` should be awaited before accessing its properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
)
})
}

const warnForEnumeration = process.env.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS
? noop
: createDedupedByCallsiteServerErrorLoggerDev(function getEnumerationMessage(
: function warnForEnumeration(
route: undefined | string,
missingProperties: Array<string>
) {
if (process.env.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS) {
return
}

const prefix = route ? ` In route ${route} ` : ''
if (missingProperties.length) {
const describedMissingProperties =
describeListOfPropertyNames(missingProperties)
return (
console.error(
`${prefix}params are being enumerated incompletely missing these properties: ${describedMissingProperties}. ` +
`\`params\` should be awaited before accessing its properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
`\`params\` should be awaited before accessing its properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
)
} else {
return (
console.error(
`${prefix}params are being enumerated. ` +
`\`params\` should be awaited before accessing its properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
`\`params\` should be awaited before accessing its properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
)
}
})
}

function describeListOfPropertyNames(properties: Array<string>) {
switch (properties.length) {
Expand Down
30 changes: 13 additions & 17 deletions packages/next/src/server/request/search-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from '../app-render/prerender-async-storage.external'
import { InvariantError } from '../../shared/lib/invariant-error'
import { makeHangingPromise } from '../dynamic-rendering-utils'
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-loger'
import {
describeStringPropertyAccess,
describeHasCheckingStringProperty,
Expand Down Expand Up @@ -648,41 +647,38 @@ const noop = () => {}

const warnForSyncAccess = process.env.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS
? noop
: createDedupedByCallsiteServerErrorLoggerDev(function getSyncAccessMessage(
route: undefined | string,
expression: string
) {
: function warnForSyncAccess(route: undefined | string, expression: string) {
const prefix = route ? ` In route ${route} a ` : 'A '
return (
console.error(
`${prefix}searchParam property was accessed directly with ${expression}. ` +
`\`searchParams\` should be awaited before accessing properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
`\`searchParams\` should be awaited before accessing properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
)
})
}

const warnForEnumeration = process.env.__NEXT_DISABLE_SYNC_DYNAMIC_API_WARNINGS
? noop
: createDedupedByCallsiteServerErrorLoggerDev(function getEnumerationMessage(
: function warnForEnumeration(
route: undefined | string,
missingProperties: Array<string>
) {
const prefix = route ? ` In route ${route} ` : ''
if (missingProperties.length) {
const describedMissingProperties =
describeListOfPropertyNames(missingProperties)
return (
console.error(
`${prefix}searchParams are being enumerated incompletely missing these properties: ${describedMissingProperties}. ` +
`\`searchParams\` should be awaited before accessing its properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
`\`searchParams\` should be awaited before accessing its properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
)
} else {
return (
console.error(
`${prefix}searchParams are being enumerated. ` +
`\`searchParams\` should be awaited before accessing its properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
`\`searchParams\` should be awaited before accessing its properties. ` +
`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`
)
}
})
}

function describeListOfPropertyNames(properties: Array<string>) {
switch (properties.length) {
Expand Down
1 change: 0 additions & 1 deletion test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

e2e/**/tsconfig.json
production/**/tsconfig.json
development/**/tsconfig.json

test-junit-report/
turbopack-test-junit-report/
7 changes: 0 additions & 7 deletions test/development/app-dir/dynamic-io-warnings/app/layout.tsx

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit ebffec2

Please sign in to comment.