Skip to content

Commit

Permalink
Merge branch 'canary' into revert-66286-fix/esm-client-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner authored Jun 10, 2024
2 parents c41ec7c + fa05f11 commit 5fd2d41
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 40 deletions.
22 changes: 19 additions & 3 deletions docs/02-app/02-api-reference/04-functions/unstable_after.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const nextConfig = {
module.exports = nextConfig
```

The function accepts a callback that will be executed after the response is finished:

```tsx filename="app/layout.tsx switcher
import { unstable_after as after } from 'next/server'
import { log } from '@/app/utils'
Expand Down Expand Up @@ -52,11 +54,25 @@ export default function Layout({ children }) {
> - `unstable_after()` is a [dynamic function](/docs/app/building-your-application/rendering/server-components#dynamic-functions) that will opt a route into dynamic rendering. This behavior can be overridden with the [`export dynamic = "force-static"`](/docs/app/api-reference/file-conventions/route-segment-config#dynamic) segment config.
> - You can use React `cache` to deduplicate functions called inside `unstable_after()`.
> - [`cookies()`](/docs/app/api-reference/functions/cookies) cannot be set inside `unstable_after()` since the response has already been sent.
> - `unstable_after()` can be nested inside other `unstable_after()` calls.
### Parameters
## Parameters

- A function that will be executed after the response is finished.
- A callback function which will be executed after the response is finished.

### Returns
## Returns

- `unstable_after()` does not return a value.

## Alternatives

The use case for `unstable_after()` is to process secondary tasks without blocking the primary response. It's similar to using the platform's [`waitUntil()`](https://vercel.com/docs/functions/functions-api-reference) or removing `await` from a promise, but with the following differences:

- **[`waitUntil()`]**: accepts promise and enqueues a task to be executed during the lifecycle of the request, whereas `unstable_after()` accepts a callback that will be executed **after** the response is finished.
- **Removing `await`**: starts executing during the response, which uses resources. It's also not reliable in serverless environments as the function stops computation immediately after the response is sent, potentially interrupting the task.

We recommend using `unstable_after()` as it has been designed to consider other Next.js APIs and contexts.

## Serverless function duration

`unstable_after()` will run for the platform's default or configured max duration of a serverless function. If your platform supports it, you can configure the timeout limit using the [`maxDuration`](/docs/app/api-reference/file-conventions/route-segment-config#maxduration) route segment config.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "15.0.0-canary.23"
"version": "15.0.0-canary.24"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"description": "ESLint configuration used by Next.js.",
"main": "index.js",
"license": "MIT",
Expand All @@ -10,7 +10,7 @@
},
"homepage": "https://nextjs.org/docs/app/building-your-application/configuring/eslint#eslint-config",
"dependencies": {
"@next/eslint-plugin-next": "15.0.0-canary.23",
"@next/eslint-plugin-next": "15.0.0-canary.24",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.0 || 7.0.0 - 7.2.0",
"eslint-import-resolver-node": "^0.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"description": "ESLint plugin for Next.js.",
"main": "dist/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/font",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"private": true,
"scripts": {
"clean": "node ../../scripts/rm.mjs native",
Expand Down
12 changes: 6 additions & 6 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -93,7 +93,7 @@
]
},
"dependencies": {
"@next/env": "15.0.0-canary.23",
"@next/env": "15.0.0-canary.24",
"@swc/helpers": "0.5.11",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001579",
Expand Down Expand Up @@ -157,10 +157,10 @@
"@jest/types": "29.5.0",
"@mswjs/interceptors": "0.23.0",
"@napi-rs/triples": "1.2.0",
"@next/polyfill-module": "15.0.0-canary.23",
"@next/polyfill-nomodule": "15.0.0-canary.23",
"@next/react-refresh-utils": "15.0.0-canary.23",
"@next/swc": "15.0.0-canary.23",
"@next/polyfill-module": "15.0.0-canary.24",
"@next/polyfill-nomodule": "15.0.0-canary.24",
"@next/react-refresh-utils": "15.0.0-canary.24",
"@next/swc": "15.0.0-canary.24",
"@opentelemetry/api": "1.6.0",
"@playwright/test": "1.41.2",
"@swc/core": "1.5.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/third-parties/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/third-parties",
"version": "15.0.0-canary.23",
"version": "15.0.0-canary.24",
"repository": {
"url": "vercel/next.js",
"directory": "packages/third-parties"
Expand All @@ -26,7 +26,7 @@
"third-party-capital": "1.0.20"
},
"devDependencies": {
"next": "15.0.0-canary.23",
"next": "15.0.0-canary.24",
"outdent": "0.8.0",
"prettier": "2.5.1"
},
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
expectUnsupportedModuleDevError,
expectUnsupportedModuleProdError,
getUnsupportedModuleWarning,
getModuleNotFound,
} from './utils'

jest.setTimeout(1000 * 60 * 2)
Expand Down Expand Up @@ -296,14 +297,29 @@ describe('Edge runtime code with imports', () => {
stderr: true,
})
expect(stderr).toContain(getUnsupportedModuleWarning(moduleName))
context.app = await nextStart(
context.appDir,
context.appPort,
appOption
)
const res = await fetchViaHTTP(context.appPort, url)

let logs = { stdout: '', stderr: '' }
const port = await findPort()

const options = {
onStdout(msg) {
logs.output += msg
logs.stdout += msg
},
onStderr(msg) {
logs.output += msg
logs.stderr += msg
},
}

await nextStart(context.appDir, port, options)
const res = await fetchViaHTTP(port, url)
expect(res.status).toBe(200)
expectNoError(moduleName)

expect(logs.output).not.toContain(
getUnsupportedModuleWarning(moduleName)
)
expect(logs.output).not.toContain(getModuleNotFound(moduleName))
})
}
)
Expand Down

0 comments on commit 5fd2d41

Please sign in to comment.