Skip to content

Commit

Permalink
rename "unstable_after" -> "after"
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Dec 6, 2024
1 parent f29090e commit aff12ad
Show file tree
Hide file tree
Showing 74 changed files with 202 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn get_next_cjs_optimizer_rule(enable_mdx_rs: bool) -> ModuleRule {
"userAgent".into(),
"next/dist/server/web/spec-extension/user-agent".into(),
),
("unstable_after".into(), "next/dist/server/after".into()),
("after".into(), "next/dist/server/after".into()),
]),
},
)]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ impl ReactServerComponentValidator {

invalid_client_imports: vec![JsWord::from("server-only"), JsWord::from("next/headers")],

invalid_client_lib_apis_mapping: [("next/server", vec!["unstable_after"])].into(),
invalid_client_lib_apis_mapping: [("next/server", vec!["after"])].into(),
imports: ImportMap::default(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export { userAgent } from 'next/dist/server/web/spec-extension/user-agent'
export { URLPattern } from 'next/dist/compiled/@edge-runtime/primitives/url'
export { ImageResponse } from 'next/dist/server/web/spec-extension/image-response'
export type { ImageResponseOptions } from 'next/dist/compiled/@vercel/og/types'
export { unstable_after } from 'next/dist/server/after'
export { after } from 'next/dist/server/after'
export { connection } from 'next/dist/server/request/connection'
export type { UnsafeUnwrappedSearchParams } from 'next/dist/server/request/search-params'
export type { UnsafeUnwrappedParams } from 'next/dist/server/request/params'
4 changes: 2 additions & 2 deletions packages/next/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const serverExports = {
.userAgent,
URLPattern: require('next/dist/server/web/spec-extension/url-pattern')
.URLPattern,
unstable_after: require('next/dist/server/after').unstable_after,
after: require('next/dist/server/after').after,
connection: require('next/dist/server/request/connection').connection,
}

Expand All @@ -26,5 +26,5 @@ exports.ImageResponse = serverExports.ImageResponse
exports.userAgentFromString = serverExports.userAgentFromString
exports.userAgent = serverExports.userAgent
exports.URLPattern = serverExports.URLPattern
exports.unstable_after = serverExports.unstable_after
exports.after = serverExports.after
exports.connection = serverExports.connection
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function getRender({
if (event?.waitUntil) {
// TODO(after):
// remove `internal_runWithWaitUntil` and the `internal-edge-wait-until` module
// when consumers switch to `unstable_after`.
// when consumers switch to `after`.
const waitUntilPromise = internal_getCurrentFunctionWaitUntil()
if (waitUntilPromise) {
event.waitUntil(waitUntilPromise)
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/after/after-context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('AfterContext', () => {
let workAsyncStorage: WASMod['workAsyncStorage']
let workUnitAsyncStorage: WSMod['workUnitAsyncStorage']
let AfterContext: AfterContextMod['AfterContext']
let after: AfterMod['unstable_after']
let after: AfterMod['after']

beforeAll(async () => {
// @ts-expect-error
Expand All @@ -32,7 +32,7 @@ describe('AfterContext', () => {
AfterContext = AfterContextMod.AfterContext

const AfterMod = await import('./after')
after = AfterMod.unstable_after
after = AfterMod.after
})

const createRun =
Expand Down
14 changes: 6 additions & 8 deletions packages/next/src/server/after/after-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ export class AfterContext {
// TODO(after): implement tracing
this.addCallback(task)
} else {
throw new Error(
'`unstable_after()`: Argument must be a promise or a function'
)
throw new Error('`after()`: Argument must be a promise or a function')
}
}

private addCallback(callback: AfterCallback) {
// if something is wrong, throw synchronously, bubbling up to the `unstable_after` callsite.
// if something is wrong, throw synchronously, bubbling up to the `after` callsite.
if (!this.waitUntil) {
errorWaitUntilNotAvailable()
}
Expand Down Expand Up @@ -127,8 +125,8 @@ export class AfterContext {
// TODO(after): should we log this if we have a onTaskError callback?
console.error(
taskKind === 'promise'
? `A promise passed to \`unstable_after()\` rejected:`
: `An error occurred in a function passed to \`unstable_after()\`:`,
? `A promise passed to \`after()\` rejected:`
: `An error occurred in a function passed to \`after()\`:`,
error
)
if (this.onTaskError) {
Expand All @@ -138,7 +136,7 @@ export class AfterContext {
} catch (handlerError) {
console.error(
new InvariantError(
'`onTaskError` threw while handling an error thrown from an `unstable_after` task',
'`onTaskError` threw while handling an error thrown from an `after` task',
{
cause: handlerError,
}
Expand All @@ -151,6 +149,6 @@ export class AfterContext {

function errorWaitUntilNotAvailable(): never {
throw new Error(
'`unstable_after()` will not work correctly, because `waitUntil` is not available in the current environment.'
'`after()` will not work correctly, because `waitUntil` is not available in the current environment.'
)
}
6 changes: 3 additions & 3 deletions packages/next/src/server/after/after.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export type AfterCallback<T = unknown> = () => T | Promise<T>
/**
* This function allows you to schedule callbacks to be executed after the current request finishes.
*/
export function unstable_after<T>(task: AfterTask<T>): void {
export function after<T>(task: AfterTask<T>): void {
const workStore = workAsyncStorage.getStore()

if (!workStore) {
// TODO(after): the linked docs page talks about *dynamic* APIs, which unstable_after soon won't be anymore
// TODO(after): the linked docs page talks about *dynamic* APIs, which after soon won't be anymore
throw new Error(
'`unstable_after` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context'
'`after` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context'
)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/after/builtin-request-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export function getBuiltinRequestContext():
return ctx?.get()
}

/** This should be considered unstable until `unstable_after` is stablized. */
/** This should be considered unstable until `after` is stablized. */
const NEXT_REQUEST_CONTEXT_SYMBOL = Symbol.for('@next/request-context')

type GlobalThisWithRequestContext = typeof globalThis & {
[NEXT_REQUEST_CONTEXT_SYMBOL]?: BuiltinRequestContext
}

/** A request context provided by the platform.
* It should be considered unstable until `unstable_after` is stablized. */
* It should be considered unstable until `after` is stablized. */
export type BuiltinRequestContext = {
get(): BuiltinRequestContextValue | undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { afterTaskAsyncStorageInstance as afterTaskAsyncStorage } from './after-
import type { WorkUnitStore } from './work-unit-async-storage.external'

export interface AfterTaskStore {
/** The phase in which the topmost `unstable_after` was called.
/** The phase in which the topmost `after` was called.
*
* NOTE: Can be undefined when running `generateStaticParams`,
* where we only have a `workStore`, no `workUnitStore`.
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ export default abstract class Server<
if (builtinRequestContext) {
// the platform provided a request context.
// use the `waitUntil` from there, whether actually present or not --
// if not present, `unstable_after` will error.
// if not present, `after` will error.

// NOTE: if we're in an edge runtime sandbox, this context will be used to forward the outer waitUntil.
return builtinRequestContext.waitUntil
Expand All @@ -1774,7 +1774,7 @@ export default abstract class Server<
// we're built for a serverless environment, and `waitUntil` is not available,
// but using a noop would likely lead to incorrect behavior,
// because we have no way of keeping the invocation alive.
// return nothing, and `unstable_after` will error if used.
// return nothing, and `after` will error if used.
//
// NOTE: for edge functions, `NextWebServer` always runs in minimal mode.
//
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/dynamic-rendering-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function makeHangingPromise<T>(
() => {
reject(
new Error(
`During prerendering, ${expression} rejects when the prerender is complete. Typically these errors are handled by React but if you move ${expression} to a different context by using \`setTimeout\`, \`unstable_after\`, or similar functions you may observe this error and you should handle it in that context.`
`During prerendering, ${expression} rejects when the prerender is complete. Typically these errors are handled by React but if you move ${expression} to a different context by using \`setTimeout\`, \`after\`, or similar functions you may observe this error and you should handle it in that context.`
)
)
},
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/request/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function connection(): Promise<void> {
!isRequestAPICallableInsideAfter()
) {
throw new Error(
`Route ${workStore.route} used "connection" inside "unstable_after(...)". The \`connection()\` function is used to indicate the subsequent code must only run when there is an actual Request, but "unstable_after(...)" executes after the request, so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/canary/app/api-reference/functions/unstable_after`
`Route ${workStore.route} used "connection" inside "after(...)". The \`connection()\` function is used to indicate the subsequent code must only run when there is an actual Request, but "after(...)" executes after the request, so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/canary/app/api-reference/functions/after`
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/request/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function cookies(): Promise<ReadonlyRequestCookies> {
) {
throw new Error(
// TODO(after): clarify that this only applies to pages?
`Route ${workStore.route} used "cookies" inside "unstable_after(...)". This is not supported. If you need this data inside an "unstable_after" callback, use "cookies" outside of the callback. See more info here: https://nextjs.org/docs/canary/app/api-reference/functions/unstable_after`
`Route ${workStore.route} used "cookies" inside "after(...)". This is not supported. If you need this data inside an "after" callback, use "cookies" outside of the callback. See more info here: https://nextjs.org/docs/canary/app/api-reference/functions/after`
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/request/draft-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function trackDynamicDraftMode(expression: string) {
)
} else if (workUnitStore.phase === 'after') {
throw new Error(
`Route ${store.route} used "${expression}" inside \`unstable_after\`. The enabled status of draftMode can be read inside \`unstable_after\` but you cannot enable or disable draftMode. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_after`
`Route ${store.route} used "${expression}" inside \`after\`. The enabled status of draftMode can be read inside \`after\` but you cannot enable or disable draftMode. See more info here: https://nextjs.org/docs/app/api-reference/functions/after`
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/request/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function headers(): Promise<ReadonlyHeaders> {
!isRequestAPICallableInsideAfter()
) {
throw new Error(
`Route ${workStore.route} used "headers" inside "unstable_after(...)". This is not supported. If you need this data inside an "unstable_after" callback, use "headers" outside of the callback. See more info here: https://nextjs.org/docs/canary/app/api-reference/functions/unstable_after`
`Route ${workStore.route} used "headers" inside "after(...)". This is not supported. If you need this data inside an "after" callback, use "headers" outside of the callback. See more info here: https://nextjs.org/docs/canary/app/api-reference/functions/after`
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/web/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export { NextRequest } from '../spec-extension/request'
export { NextResponse } from '../spec-extension/response'
export { userAgent, userAgentFromString } from '../spec-extension/user-agent'
export { URLPattern } from '../spec-extension/url-pattern'
export { unstable_after } from '../../after'
export { after } from '../../after'
export { connection } from '../../request/connection'
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ describe('Error Overlay for server components compiler errors in pages', () => {
}
})

test("importing unstable_after from 'next/server' in pages", async () => {
test("importing after from 'next/server' in pages", async () => {
await using sandbox = await createSandbox(next, initialFiles)
const { session } = sandbox

await next.patchFile(
'components/Comp.js',
outdent`
import { unstable_after } from 'next/server'
import { after } from 'next/server'
export default function Page() {
return 'hello world'
Expand All @@ -168,13 +168,13 @@ describe('Error Overlay for server components compiler errors in pages', () => {
.toMatchInlineSnapshot(`
"./components/Comp.js:1:10
Ecmascript file had an error
> 1 | import { unstable_after } from 'next/server'
| ^^^^^^^^^^^^^^
> 1 | import { after } from 'next/server'
| ^^^^^
2 |
3 | export default function Page() {
4 | return 'hello world'
You're importing a component that needs "unstable_after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components"
You're importing a component that needs "after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components"
`)
} else {
expect(
Expand All @@ -184,13 +184,13 @@ describe('Error Overlay for server components compiler errors in pages', () => {
)
).toMatchInlineSnapshot(`
"./components/Comp.js
Error: x You're importing a component that needs "unstable_after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-
| your-application/rendering/server-components
Error: x You're importing a component that needs "after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-
| application/rendering/server-components
|
|
,-[1:1]
1 | import { unstable_after } from 'next/server'
: ^^^^^^^^^^^^^^
1 | import { after } from 'next/server'
: ^^^^^
2 |
3 | export default function Page() {
4 | return 'hello world'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { unstable_after as after } from 'next/server'
import { after } from 'next/server'
import { cliLog } from '../../utils/log'

export const dynamic = 'force-dynamic'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Log from './basic/utils/log'
import { assertHasRedbox, getRedboxSource } from '../../../lib/next-test-utils'
import { join } from 'path'

describe('unstable_after() - invalid usages', () => {
describe('after() - invalid usages', () => {
const { next } = nextTestSetup({
files: join(__dirname, 'basic'),
})
Expand All @@ -27,7 +27,7 @@ describe('unstable_after() - invalid usages', () => {

await assertHasRedbox(session)
expect(await getRedboxSource(session)).toMatch(
/You're importing a component that needs "?unstable_after"?\. That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component\./
/You're importing a component that needs "?after"?\. That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component\./
)
expect(getAfterLogs()).toHaveLength(0)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Link from 'next/link'
import { unstable_after as after } from 'next/server'
import { after } from 'next/server'
import React from 'react'
import { fetchRandomValue } from '../lib/fetch-random-value'
import { RefreshButton } from './refresh-button'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unstable_after as after, connection } from 'next/server'
import { after, connection } from 'next/server'
import { setTimeout } from 'timers/promises'

export default async function Page() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isNextDev, nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'

describe('unstable_after during server shutdown - custom server', () => {
describe('after during server shutdown - custom server', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
startCommand: 'node server.mjs',
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('unstable_after during server shutdown - custom server', () => {
// unlike the above test for `next dev`, NextCustomServer has no logic that'd cause it to skip cleanups in dev mode,
// so this is the same in both modes
it.each(['SIGINT', 'SIGTERM'] as const)(
'waits for unstable_after callbacks when the server receives %s',
'waits for after callbacks when the server receives %s',
async (signal) => {
await next.render('/')
await retry(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unstable_after as after, connection } from 'next/server'
import { after, connection } from 'next/server'
import { setTimeout } from 'timers/promises'

export default async function Page() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'

describe('unstable_after during server shutdown - next start', () => {
describe('after during server shutdown - next start', () => {
const { next, skipped, isNextDev } = nextTestSetup({
files: __dirname,
skipDeployment: true, // the tests use cli logs
Expand All @@ -24,7 +24,7 @@ describe('unstable_after during server shutdown - next start', () => {
// `next dev` shuts down the child process that runs the server without waiting for cleanups,
// so `after` callbacks won't have the chance to complete
it.each(['SIGINT', 'SIGTERM'] as const)(
'does not wait for unstable_after callbacks when the server receives %s',
'does not wait for after callbacks when the server receives %s',
async (signal) => {
await next.render('/')
await retry(async () => {
Expand All @@ -38,7 +38,7 @@ describe('unstable_after during server shutdown - next start', () => {

if (!isNextDev) {
it.each(['SIGINT', 'SIGTERM'] as const)(
'waits for unstable_after callbacks when the server receives %s',
'waits for after callbacks when the server receives %s',
async (signal) => {
await next.render('/')
await retry(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unstable_after as after } from 'next/server'
import { after } from 'next/server'
import { draftMode } from 'next/headers'

export function testDraftMode(/** @type {string} */ route) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cookies, headers } from 'next/headers'
import { unstable_after as after, connection } from 'next/server'
import { after, connection } from 'next/server'

export function testRequestAPIs(/** @type {string} */ route) {
after(async () => {
Expand Down
Loading

0 comments on commit aff12ad

Please sign in to comment.