-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve top level await coverage (#64508)
## What? - Changes webpack output target to `es6` (required for `async function` output) - Adds tests for top level await in server components and client components (App Router) - Converted the async-modules tests to `test/e2e` - Has one skipped test that @gnoff is going to look into. This shouldn't block merging this PR 👍 Adds additional tests for top level `await`. Since [Next.js 13.4.5](https://github.com/vercel/next.js/releases/tag/v13.4.5) webpack has top level await support enabled by default. Similarly Turbopack supports top level await by default as well. TLDR: You can remove `topLevelAwait: true` from the webpack configuration. In writing these tests I found that client components are missing some kind of handling for top level await (async modules) so I've raised that to @gnoff who is going to have a look. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # --> Closes NEXT-3126 Fixes #43382
- Loading branch information
1 parent
dccc6ec
commit 1fd93ee
Showing
26 changed files
with
2,817 additions
and
564 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
test/e2e/async-modules-app/app/app-router/client-component/skipped-page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use client' | ||
const appValue = await Promise.resolve('hello') | ||
|
||
export default function Page() { | ||
return <p id="app-router-client-component-value">{appValue}</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const appValue = await Promise.resolve('hello') | ||
|
||
export default function Page() { | ||
return <p id="app-router-value">{appValue}</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const metadata = { | ||
title: 'Next.js', | ||
description: 'Generated by Next.js', | ||
} | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* eslint-env jest */ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('Async modules', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
it('app router server component async module', async () => { | ||
const browser = await next.browser('/app-router') | ||
expect(await browser.elementByCss('#app-router-value').text()).toBe('hello') | ||
}) | ||
|
||
// TODO: Investigate/fix issue with React loading async modules failing. | ||
// Rename app/app-router/client-component/skipped-page.tsx to app/app-router/client-component/page.tsx to run this test. | ||
it.skip('app router client component async module', async () => { | ||
const browser = await next.browser('/app-router/client') | ||
expect( | ||
await browser.elementByCss('#app-router-client-component-value').text() | ||
).toBe('hello') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* eslint-env jest */ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { check } from 'next-test-utils' | ||
|
||
describe('Async modules', () => { | ||
const { next, isNextDev: dev } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('ssr async page modules', async () => { | ||
const $ = await next.render$('/') | ||
expect($('#app-value').text()).toBe('hello') | ||
expect($('#page-value').text()).toBe('42') | ||
}) | ||
|
||
it('csr async page modules', async () => { | ||
const browser = await next.browser('/') | ||
expect(await browser.elementByCss('#app-value').text()).toBe('hello') | ||
expect(await browser.elementByCss('#page-value').text()).toBe('42') | ||
expect(await browser.elementByCss('#doc-value').text()).toBe('doc value') | ||
}) | ||
|
||
it('works on async api routes', async () => { | ||
const res = await next.fetch('/api/hello') | ||
expect(res.status).toBe(200) | ||
const result = await res.json() | ||
expect(result).toHaveProperty('value', 42) | ||
}) | ||
|
||
it('works with getServerSideProps', async () => { | ||
const browser = await next.browser('/gssp') | ||
expect(await browser.elementByCss('#gssp-value').text()).toBe('42') | ||
}) | ||
|
||
it('works with getStaticProps', async () => { | ||
const browser = await next.browser('/gsp') | ||
expect(await browser.elementByCss('#gsp-value').text()).toBe('42') | ||
}) | ||
|
||
it('can render async 404 pages', async () => { | ||
const browser = await next.browser('/dhiuhefoiahjeoij') | ||
expect(await browser.elementByCss('#content-404').text()).toBe("hi y'all") | ||
}) | ||
|
||
// TODO: investigate this test flaking | ||
it.skip('can render async AMP pages', async () => { | ||
const browser = await next.browser('/config') | ||
await check( | ||
() => browser.elementByCss('#amp-timeago').text(), | ||
'just now', | ||
true | ||
) | ||
}) | ||
;(dev ? it.skip : it)('can render async error page', async () => { | ||
const browser = await next.browser('/make-error') | ||
expect(await browser.elementByCss('#content-error').text()).toBe( | ||
'hello error' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
experimental: { | ||
amp: { | ||
validator: require.resolve('./amp-validator-wasm.js'), | ||
}, | ||
}, | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.