Skip to content

Commit f83ec5a

Browse files
authored
Merge branch 'canary' into 05-16-upgrade_react_beta
2 parents df5934d + aed5242 commit f83ec5a

File tree

14 files changed

+170
-51
lines changed

14 files changed

+170
-51
lines changed

packages/next/src/build/webpack-config.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,14 +1710,15 @@ export default async function getBaseWebpackConfig(
17101710
const layer = resource.contextInfo.issuerLayer
17111711
let runtime
17121712

1713-
if (layer === WEBPACK_LAYERS.serverSideRendering) {
1714-
runtime = 'app-page'
1715-
} else if (!layer || layer === WEBPACK_LAYERS.api) {
1716-
runtime = 'pages'
1717-
} else {
1718-
throw new Error(
1719-
`shared-runtime module ${moduleName} cannot be used in ${layer} layer`
1720-
)
1713+
switch (layer) {
1714+
case WEBPACK_LAYERS.serverSideRendering:
1715+
case WEBPACK_LAYERS.reactServerComponents:
1716+
case WEBPACK_LAYERS.appPagesBrowser:
1717+
case WEBPACK_LAYERS.actionBrowser:
1718+
runtime = 'app-page'
1719+
break
1720+
default:
1721+
runtime = 'pages'
17211722
}
17221723
resource.request = `next/dist/server/future/route-modules/${runtime}/vendored/contexts/${moduleName}`
17231724
}

test/e2e/app-dir/navigation/navigation.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,11 +909,4 @@ describe('app dir - navigation', () => {
909909
})
910910
})
911911
})
912-
913-
describe('pages api', () => {
914-
it('should not error if just import the navigation api in pages/api', async () => {
915-
const res = await next.fetch('/api/navigation')
916-
expect(res.status).toBe(200)
917-
})
918-
})
919912
})

test/e2e/app-dir/navigation/pages/api/navigation.js

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require('next/router')
2+
3+
export default function Page() {
4+
return <p>just work</p>
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Use `require` to skip the api check
2+
require('next/navigation')
3+
4+
export default function handle(_, res) {
5+
res.send('just work')
6+
}

test/e2e/app-dir/rsc-basic/rsc-basic.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ describe('app dir - rsc basics', () => {
5959
})
6060
}
6161

62+
describe('next internal shared context', () => {
63+
it('should not error if just load next/navigation module in pages/api', async () => {
64+
const res = await next.fetch('/api/navigation')
65+
expect(res.status).toBe(200)
66+
expect(await res.text()).toBe('just work')
67+
})
68+
69+
it('should not error if just load next/router module in app page', async () => {
70+
const res = await next.fetch('/shared-context/server')
71+
expect(res.status).toBe(200)
72+
expect(await res.text()).toContain('just work')
73+
})
74+
})
75+
6276
it('should correctly render page returning null', async () => {
6377
const homeHTML = await next.render('/return-null/page')
6478
const $ = cheerio.load(homeHTML)

test/integration/create-next-app/examples.test.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { trace } from 'next/dist/trace'
2+
import { createNextInstall } from '../../lib/create-next-install'
13
import {
24
EXAMPLE_PATH,
35
EXAMPLE_REPO,
@@ -10,12 +12,23 @@ import {
1012
} from './utils'
1113

1214
describe('create-next-app --example', () => {
15+
let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
16+
beforeAll(async () => {
17+
nextInstall = await createNextInstall({
18+
parentSpan: trace('test'),
19+
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
20+
})
21+
})
1322
it('should create on valid Next.js example name', async () => {
1423
await useTempDir(async (cwd) => {
1524
const projectName = 'valid-example'
16-
const res = await run([projectName, '--example', 'basic-css'], {
17-
cwd,
18-
})
25+
const res = await run(
26+
[projectName, '--example', 'basic-css'],
27+
nextInstall.installDir,
28+
{
29+
cwd,
30+
}
31+
)
1932
expect(res.exitCode).toBe(0)
2033
projectFilesShouldExist({
2134
cwd,
@@ -34,9 +47,13 @@ describe('create-next-app --example', () => {
3447
it('should create with GitHub URL', async () => {
3548
await useTempDir(async (cwd) => {
3649
const projectName = 'github-url'
37-
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
38-
cwd,
39-
})
50+
const res = await run(
51+
[projectName, '--example', FULL_EXAMPLE_PATH],
52+
nextInstall.installDir,
53+
{
54+
cwd,
55+
}
56+
)
4057

4158
expect(res.exitCode).toBe(0)
4259
projectFilesShouldExist({
@@ -64,6 +81,7 @@ describe('create-next-app --example', () => {
6481
// GH#39665
6582
'https://github.com/vercel/nextjs-portfolio-starter/',
6683
],
84+
nextInstall.installDir,
6785
{
6886
cwd,
6987
}
@@ -97,6 +115,7 @@ describe('create-next-app --example', () => {
97115
'--example-path',
98116
EXAMPLE_PATH,
99117
],
118+
nextInstall.installDir,
100119
{
101120
cwd,
102121
}
@@ -131,6 +150,7 @@ describe('create-next-app --example', () => {
131150
'--example-path',
132151
EXAMPLE_PATH,
133152
],
153+
nextInstall.installDir,
134154
{
135155
cwd,
136156
}
@@ -168,6 +188,7 @@ describe('create-next-app --example', () => {
168188
'__internal-testing-retry',
169189
'--import-alias=@/*',
170190
],
191+
nextInstall.installDir,
171192
{
172193
cwd,
173194
input: '\n', // 'Yes' to retry
@@ -199,6 +220,7 @@ describe('create-next-app --example', () => {
199220
'default',
200221
'--import-alias=@/*',
201222
],
223+
nextInstall.installDir,
202224
{
203225
cwd,
204226
}
@@ -217,10 +239,14 @@ describe('create-next-app --example', () => {
217239
it('should not create if --example flag value is invalid', async () => {
218240
await useTempDir(async (cwd) => {
219241
const projectName = 'invalid-example'
220-
const res = await run([projectName, '--example', 'not a real example'], {
221-
cwd,
222-
reject: false,
223-
})
242+
const res = await run(
243+
[projectName, '--example', 'not a real example'],
244+
nextInstall.installDir,
245+
{
246+
cwd,
247+
reject: false,
248+
}
249+
)
224250

225251
expect(res.exitCode).toBe(1)
226252
projectFilesShouldNotExist({
@@ -244,6 +270,7 @@ describe('create-next-app --example', () => {
244270
'--no-tailwind',
245271
'--example',
246272
],
273+
nextInstall.installDir,
247274
{
248275
cwd,
249276
reject: false,

test/integration/create-next-app/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import {
66
projectFilesShouldExist,
77
projectFilesShouldNotExist,
88
} from './utils'
9+
import { createNextInstall } from '../../lib/create-next-install'
10+
import { trace } from 'next/dist/trace'
11+
12+
let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
13+
beforeAll(async () => {
14+
nextInstall = await createNextInstall({
15+
parentSpan: trace('test'),
16+
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
17+
})
18+
})
919

1020
describe('create-next-app', () => {
1121
it('should not create if the target directory is not empty', async () => {
@@ -25,6 +35,7 @@ describe('create-next-app', () => {
2535
'--no-src-dir',
2636
'--no-import-alias',
2737
],
38+
nextInstall.installDir,
2839
{
2940
cwd,
3041
reject: false,
@@ -64,6 +75,7 @@ describe('create-next-app', () => {
6475
'--no-src-dir',
6576
'--no-import-alias',
6677
],
78+
nextInstall.installDir,
6779
{
6880
cwd,
6981
reject: false,
@@ -93,6 +105,7 @@ describe('create-next-app', () => {
93105
'--no-import-alias',
94106
'--skip-install',
95107
],
108+
nextInstall.installDir,
96109
{
97110
cwd,
98111
}

test/integration/create-next-app/package-manager/bun.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { trace } from 'next/dist/trace'
2+
import { createNextInstall } from '../../../lib/create-next-install'
13
import {
24
command,
35
DEFAULT_FILES,
@@ -16,6 +18,14 @@ beforeEach(async () => {
1618
.catch(() => command('npm', ['i', '-g', 'bun']))
1719
})
1820

21+
let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
22+
beforeAll(async () => {
23+
nextInstall = await createNextInstall({
24+
parentSpan: trace('test'),
25+
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
26+
})
27+
})
28+
1929
describe('create-next-app with package manager bun', () => {
2030
it('should use bun for --use-bun flag', async () => {
2131
await useTempDir(async (cwd) => {
@@ -31,6 +41,7 @@ describe('create-next-app with package manager bun', () => {
3141
'--no-tailwind',
3242
'--no-import-alias',
3343
],
44+
nextInstall.installDir,
3445
{
3546
cwd,
3647
}
@@ -59,6 +70,7 @@ it('should use bun when user-agent is bun', async () => {
5970
'--no-tailwind',
6071
'--no-import-alias',
6172
],
73+
nextInstall.installDir,
6274
{
6375
cwd,
6476
env: { npm_config_user_agent: 'bun' },
@@ -79,6 +91,7 @@ it('should use bun for --use-bun flag with example', async () => {
7991
const projectName = 'use-bun-with-example'
8092
const res = await run(
8193
[projectName, '--use-bun', '--example', FULL_EXAMPLE_PATH],
94+
nextInstall.installDir,
8295
{ cwd }
8396
)
8497

@@ -94,10 +107,14 @@ it('should use bun for --use-bun flag with example', async () => {
94107
it('should use bun when user-agent is bun with example', async () => {
95108
await useTempDir(async (cwd) => {
96109
const projectName = 'user-agent-bun-with-example'
97-
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
98-
cwd,
99-
env: { npm_config_user_agent: 'bun' },
100-
})
110+
const res = await run(
111+
[projectName, '--example', FULL_EXAMPLE_PATH],
112+
nextInstall.installDir,
113+
{
114+
cwd,
115+
env: { npm_config_user_agent: 'bun' },
116+
}
117+
)
101118

102119
expect(res.exitCode).toBe(0)
103120
projectFilesShouldExist({

test/integration/create-next-app/package-manager/npm.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1+
import { trace } from 'next/dist/trace'
12
import {
23
DEFAULT_FILES,
34
FULL_EXAMPLE_PATH,
45
projectFilesShouldExist,
56
run,
67
useTempDir,
78
} from '../utils'
9+
import { createNextInstall } from '../../../lib/create-next-install'
810

911
const lockFile = 'package-lock.json'
1012
const files = [...DEFAULT_FILES, lockFile]
1113

14+
let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
15+
beforeAll(async () => {
16+
nextInstall = await createNextInstall({
17+
parentSpan: trace('test'),
18+
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
19+
})
20+
})
21+
1222
describe('create-next-app with package manager npm', () => {
1323
it('should use npm for --use-npm flag', async () => {
1424
await useTempDir(async (cwd) => {
@@ -24,6 +34,7 @@ describe('create-next-app with package manager npm', () => {
2434
'--no-tailwind',
2535
'--no-import-alias',
2636
],
37+
nextInstall.installDir,
2738
{
2839
cwd,
2940
}
@@ -52,6 +63,7 @@ it('should use npm when user-agent is npm', async () => {
5263
'--no-tailwind',
5364
'--no-import-alias',
5465
],
66+
nextInstall.installDir,
5567
{
5668
cwd,
5769
env: { npm_config_user_agent: 'npm' },
@@ -72,6 +84,7 @@ it('should use npm for --use-npm flag with example', async () => {
7284
const projectName = 'use-npm-with-example'
7385
const res = await run(
7486
[projectName, '--use-npm', '--example', FULL_EXAMPLE_PATH],
87+
nextInstall.installDir,
7588
{ cwd }
7689
)
7790

@@ -87,10 +100,14 @@ it('should use npm for --use-npm flag with example', async () => {
87100
it('should use npm when user-agent is npm with example', async () => {
88101
await useTempDir(async (cwd) => {
89102
const projectName = 'user-agent-npm-with-example'
90-
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
91-
cwd,
92-
env: { npm_config_user_agent: 'npm' },
93-
})
103+
const res = await run(
104+
[projectName, '--example', FULL_EXAMPLE_PATH],
105+
nextInstall.installDir,
106+
{
107+
cwd,
108+
env: { npm_config_user_agent: 'npm' },
109+
}
110+
)
94111

95112
expect(res.exitCode).toBe(0)
96113
projectFilesShouldExist({

0 commit comments

Comments
 (0)