Commit 7e0fc3b
authored
Turbopack: refactor segment config parsing (#83297)
Closes PACK-5382
Previously, Turbopack validated every single module for route segment config, leading to false positives (on non-page files) and worse build performance. There were also three separate implementations of this logic.
Now, all of these cases are fatal errors, not just warnings.
Examples for errors
```
./bench/basic-app/app/export/inherit/page.tsx:1:28
Next.js can't recognize the exported `preferredRegion` field in route. It needs to be a static string or array of static strings.
> 1 | export { default, runtime, preferredRegion } from '../basic/foo'
| ^^^^^^^^^^^^^^^
The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compiled-time.
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
```
This error message is slightly different now:
```
browser log: ./test/integration/app-dir-export/app/another/[slug]/page.js:6:8
Next.js can't recognize the exported `generateStaticParams` field in route. App pages cannot use both "use client" and export function "generateStaticParams()".
4 |
5 |
> 6 | export function generateStaticParams() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 7 | return [{ slug: 'first' }, { slug: 'second' }]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 8 | }
| ^^
9 |
10 | export default async function Page(props) {
11 | const params = await props.params
The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compiled-time.
Import traces:
Client Component Browser:
./test/integration/app-dir-export/app/another/[slug]/page.js [Client Component Browser]
./test/integration/app-dir-export/app/another/[slug]/page.js [Server Component]
Client Component SSR:
./test/integration/app-dir-export/app/another/[slug]/page.js [Client Component SSR]
./test/integration/app-dir-export/app/another/[slug]/page.js [Server Component]
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
```1 parent f2e3357 commit 7e0fc3b
File tree
33 files changed
+4408
-6294
lines changed- crates
- next-api/src
- next-core/src
- next_app
- metadata
- next_client
- next_server
- next-custom-transforms/src/transforms
- page_static_info
- test
- e2e/app-dir/app-edge
- app/export/inherit
- integration
- app-dir-export/test
- invalid-middleware-matchers/test
- production/exported-runtimes-value-validation
- turbopack/crates/turbopack-ecmascript
- src/analyzer
- tests/analyzer/graph
- peg
- react-dom-production
33 files changed
+4408
-6294
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
1106 | 1106 | | |
1107 | 1107 | | |
1108 | 1108 | | |
1109 | | - | |
| 1109 | + | |
1110 | 1110 | | |
1111 | 1111 | | |
1112 | 1112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
89 | | - | |
90 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
91 | 95 | | |
92 | | - | |
| 96 | + | |
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
| |||
175 | 179 | | |
176 | 180 | | |
177 | 181 | | |
178 | | - | |
179 | | - | |
180 | 182 | | |
181 | | - | |
182 | | - | |
| 183 | + | |
| 184 | + | |
183 | 185 | | |
184 | 186 | | |
185 | 187 | | |
| |||
190 | 192 | | |
191 | 193 | | |
192 | 194 | | |
193 | | - | |
| 195 | + | |
194 | 196 | | |
195 | 197 | | |
196 | 198 | | |
| |||
247 | 249 | | |
248 | 250 | | |
249 | 251 | | |
250 | | - | |
| 252 | + | |
251 | 253 | | |
252 | 254 | | |
253 | 255 | | |
| |||
296 | 298 | | |
297 | 299 | | |
298 | 300 | | |
299 | | - | |
| 301 | + | |
300 | 302 | | |
301 | 303 | | |
302 | 304 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
930 | 930 | | |
931 | 931 | | |
932 | 932 | | |
933 | | - | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
934 | 936 | | |
935 | 937 | | |
936 | 938 | | |
| |||
944 | 946 | | |
945 | 947 | | |
946 | 948 | | |
947 | | - | |
| 949 | + | |
948 | 950 | | |
949 | | - | |
| 951 | + | |
950 | 952 | | |
951 | 953 | | |
952 | 954 | | |
| |||
955 | 957 | | |
956 | 958 | | |
957 | 959 | | |
958 | | - | |
| 960 | + | |
959 | 961 | | |
960 | 962 | | |
961 | 963 | | |
| |||
964 | 966 | | |
965 | 967 | | |
966 | 968 | | |
967 | | - | |
968 | | - | |
| 969 | + | |
| 970 | + | |
969 | 971 | | |
970 | 972 | | |
971 | 973 | | |
| |||
976 | 978 | | |
977 | 979 | | |
978 | 980 | | |
979 | | - | |
| 981 | + | |
980 | 982 | | |
981 | 983 | | |
982 | 984 | | |
983 | 985 | | |
984 | 986 | | |
985 | 987 | | |
986 | 988 | | |
987 | | - | |
988 | | - | |
| 989 | + | |
| 990 | + | |
989 | 991 | | |
990 | 992 | | |
991 | 993 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
69 | | - | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
1412 | 1413 | | |
1413 | 1414 | | |
1414 | 1415 | | |
1415 | | - | |
1416 | | - | |
1417 | | - | |
1418 | | - | |
1419 | | - | |
1420 | | - | |
1421 | | - | |
1422 | | - | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
1423 | 1420 | | |
1424 | | - | |
| 1421 | + | |
1425 | 1422 | | |
1426 | 1423 | | |
1427 | 1424 | | |
| |||
0 commit comments