Skip to content

Commit ada4ab9

Browse files
committed
Make static where possible
1 parent 2684a46 commit ada4ab9

File tree

9 files changed

+81
-93
lines changed

9 files changed

+81
-93
lines changed

test/e2e/app-dir/server-source-maps/fixtures/default/app/bad-sourcemap/page.js

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/app-dir/server-source-maps/fixtures/default/app/bad-sourcemap/page.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/app-dir/server-source-maps/fixtures/default/app/rsc-error-log-cause/page.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { connection } from 'next/server'
2-
31
function logError(cause) {
42
const error = new Error('rsc-error-log-cause', { cause })
53
console.error(error)
64
}
75

8-
export default async function Page() {
9-
await connection()
10-
6+
export default function Page() {
117
const error = new Error('Boom')
128
logError(error)
139
return null

test/e2e/app-dir/server-source-maps/fixtures/default/app/rsc-error-log-custom-name/page.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { connection } from 'next/server'
2-
31
class UnnamedError extends Error {}
42
class NamedError extends Error {
53
name = 'MyError'
64
}
75

8-
export default async function Page() {
9-
await connection()
10-
6+
export default function Page() {
117
console.error(new UnnamedError('rsc-error-log-custom-name-Foo'))
128
console.error(new NamedError('rsc-error-log-custom-name-Bar'))
139
return null

test/e2e/app-dir/server-source-maps/fixtures/default/app/rsc-error-log-ignore-listed/page.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { connection } from 'next/server'
21
import { runInternal } from 'internal-pkg'
32
import { runInternalSourceMapped } from 'internal-pkg/sourcemapped'
43
import { runInternalIgnored } from 'internal-pkg/ignored'
@@ -11,8 +10,6 @@ function logError() {
1110
}
1211

1312
export default async function Page() {
14-
await connection()
15-
1613
runInternal(function runWithInternal() {
1714
runInternalSourceMapped(function runWithInternalSourceMapped() {
1815
runExternal(function runWithExternal() {
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { someClass } from './styles.module.css'
2-
import { connection } from 'next/server'
32

43
function logError() {
54
const error = new Error('rsc-error-log')
65
console.error(error)
76
}
87

9-
export default async function Page() {
10-
await connection()
11-
8+
export default function Page() {
129
logError()
1310
return <p className={someClass}>Hello, Dave!</p>
1411
}

test/e2e/app-dir/server-source-maps/fixtures/default/bad-sourcemap/page.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
// Then change the `sources` entry in the sourcemap to `["custom://[badhost]/app/bad-sourcemap/page.js"]`
33
// tsc compile errors can be ignored
44

5-
import { connection } from 'next/server'
6-
75
function logError() {
86
console.error(new Error('bad-sourcemap'))
97
}
108

11-
export default async function Page() {
12-
await connection()
9+
export default function Page() {
1310
logError()
1411
return <p>Hello, Dave!</p>
1512
}

test/e2e/app-dir/server-source-maps/server-source-maps-edge.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ describe('app-dir - server source maps edge runtime', () => {
2424

2525
if (isNextDev) {
2626
await retry(() => {
27-
expect(next.cliOutput.slice(outputIndex)).toContain('Error: Boom')
27+
expect(next.cliOutput.slice(outputIndex)).toContain(
28+
'Error: rsc-error-log'
29+
)
2830
})
2931
expect(normalizeCliOutput(next.cliOutput.slice(outputIndex))).toContain(
30-
'\nError: Boom' +
32+
'\nError: rsc-error-log' +
3133
'\n at logError (app/rsc-error-log/page.js:2:16)' +
3234
'\n at Page (app/rsc-error-log/page.js:6:2)' +
3335
'\n 1 | function logError() {' +
34-
"\n> 2 | console.error(new Error('Boom'))" +
36+
"\n> 2 | console.error(new Error('rsc-error-log'))" +
3537
'\n | ^' +
3638
'\n 3 | }' +
3739
'\n 4 |' +
@@ -50,17 +52,17 @@ describe('app-dir - server source maps edge runtime', () => {
5052

5153
if (isNextDev) {
5254
await retry(() => {
53-
expect(next.cliOutput.slice(outputIndex)).toContain('Error: Boom')
55+
expect(next.cliOutput.slice(outputIndex)).toContain('Error: ssr-throw')
5456
})
5557

5658
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
5759
expect(cliOutput).toContain(
58-
'\n ⨯ Error: Boom' +
60+
'\n ⨯ Error: ssr-throw' +
5961
'\n at throwError (app/ssr-throw/page.js:4:8)' +
6062
'\n at Page (app/ssr-throw/page.js:8:2)' +
6163
'\n 2 |' +
6264
'\n 3 | function throwError() {' +
63-
"\n> 4 | throw new Error('Boom')" +
65+
"\n> 4 | throw new Error('ssr-throw')" +
6466
'\n | ^' +
6567
'\n 5 | }' +
6668
'\n 6 |' +
@@ -79,16 +81,16 @@ describe('app-dir - server source maps edge runtime', () => {
7981

8082
if (isNextDev) {
8183
await retry(() => {
82-
expect(next.cliOutput.slice(outputIndex)).toMatch(/Error: Boom/)
84+
expect(next.cliOutput.slice(outputIndex)).toMatch(/Error: rsc-throw/)
8385
})
8486

8587
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
8688
expect(cliOutput).toContain(
87-
'\n ⨯ Error: Boom' +
89+
'\n ⨯ Error: rsc-throw' +
8890
'\n at throwError (app/rsc-throw/page.js:2:8)' +
8991
'\n at Page (app/rsc-throw/page.js:6:2)' +
9092
'\n 1 | function throwError() {' +
91-
"\n> 2 | throw new Error('Boom')" +
93+
"\n> 2 | throw new Error('rsc-throw')" +
9294
'\n | ^' +
9395
'\n 3 | }' +
9496
'\n 4 |' +

test/e2e/app-dir/server-source-maps/server-source-maps.test.ts

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ describe('app-dir - server source maps', () => {
3636
})
3737
expect(normalizeCliOutput(next.cliOutput.slice(outputIndex))).toContain(
3838
'\nError: rsc-error-log' +
39-
'\n at logError (app/rsc-error-log/page.js:5:16)' +
40-
'\n at Page (app/rsc-error-log/page.js:12:2)' +
41-
'\n 3 |' +
42-
'\n 4 | function logError() {' +
43-
"\n> 5 | const error = new Error('rsc-error-log')" +
39+
'\n at logError (app/rsc-error-log/page.js:4:16)' +
40+
'\n at Page (app/rsc-error-log/page.js:9:2)' +
41+
'\n 2 |' +
42+
'\n 3 | function logError() {' +
43+
"\n> 4 | const error = new Error('rsc-error-log')" +
4444
'\n | ^' +
45-
'\n 6 | console.error(error)' +
46-
'\n 7 | }' +
47-
'\n 8 |' +
45+
'\n 5 | console.error(error)' +
46+
'\n 6 | }' +
47+
'\n 7 |' +
4848
'\n'
4949
)
5050
} else {
@@ -64,24 +64,23 @@ describe('app-dir - server source maps', () => {
6464
})
6565
expect(normalizeCliOutput(next.cliOutput.slice(outputIndex))).toContain(
6666
'\nError: rsc-error-log-cause' +
67-
'\n at logError (app/rsc-error-log-cause/page.js:4:16)' +
68-
'\n at Page (app/rsc-error-log-cause/page.js:12:2)' +
69-
'\n 2 |' +
70-
'\n 3 | function logError(cause) {' +
71-
"\n> 4 | const error = new Error('rsc-error-log-cause', { cause })" +
67+
'\n at logError (app/rsc-error-log-cause/page.js:2:16)' +
68+
'\n at Page (app/rsc-error-log-cause/page.js:8:2)' +
69+
'\n 1 | function logError(cause) {' +
70+
"\n> 2 | const error = new Error('rsc-error-log-cause', { cause })" +
7271
'\n | ^' +
73-
'\n 5 | console.error(error)' +
74-
'\n 6 | }' +
75-
'\n 7 | {' +
72+
'\n 3 | console.error(error)' +
73+
'\n 4 | }' +
74+
'\n 5 | {' +
7675
'\n [cause]: Error: Boom' +
77-
'\n at Page (app/rsc-error-log-cause/page.js:11:16)' +
78-
'\n 9 | await connection()' +
79-
'\n 10 |' +
80-
"\n > 11 | const error = new Error('Boom')" +
76+
'\n at Page (app/rsc-error-log-cause/page.js:7:16)' +
77+
'\n 5 |' +
78+
'\n 6 | export default function Page() {' +
79+
"\n > 7 | const error = new Error('Boom')" +
8180
'\n | ^' +
82-
'\n 12 | logError(error)' +
83-
'\n 13 | return null' +
84-
'\n 14 | }' +
81+
'\n 8 | logError(error)' +
82+
'\n 9 | return null' +
83+
'\n 10 | }' +
8584
'\n'
8685
)
8786
} else {
@@ -207,39 +206,39 @@ describe('app-dir - server source maps', () => {
207206
expect(normalizeCliOutput(next.cliOutput.slice(outputIndex))).toContain(
208207
isTurbopack
209208
? '\nError: rsc-error-log-ignore-listed' +
210-
'\n at logError (app/rsc-error-log-ignore-listed/page.js:9:16)' +
211-
'\n at runWithInternalIgnored (app/rsc-error-log-ignore-listed/page.js:21:12)' +
212-
'\n at runWithExternalSourceMapped (app/rsc-error-log-ignore-listed/page.js:20:29)' +
213-
'\n at runWithExternal (app/rsc-error-log-ignore-listed/page.js:19:32)' +
214-
'\n at runWithInternalSourceMapped (app/rsc-error-log-ignore-listed/page.js:18:18)' +
209+
'\n at logError (app/rsc-error-log-ignore-listed/page.js:8:16)' +
210+
'\n at runWithInternalIgnored (app/rsc-error-log-ignore-listed/page.js:18:12)' +
211+
'\n at runWithExternalSourceMapped (app/rsc-error-log-ignore-listed/page.js:17:29)' +
212+
'\n at runWithExternal (app/rsc-error-log-ignore-listed/page.js:16:32)' +
213+
'\n at runWithInternalSourceMapped (app/rsc-error-log-ignore-listed/page.js:15:18)' +
215214
// Realpath does not point into node_modules so we don't ignore it.
216215
// TODO(veil): Should be internal-pkg/sourcemapped.ts
217216
'\n at runInternalSourceMapped (sourcemapped.ts:5:9)' +
218-
'\n at runWithInternal (app/rsc-error-log-ignore-listed/page.js:17:28)' +
217+
'\n at runWithInternal (app/rsc-error-log-ignore-listed/page.js:14:28)' +
219218
// Realpath does not point into node_modules so we don't ignore it.
220219
'\n at runInternal (internal-pkg/index.js:2:9)' +
221-
'\n at Page (app/rsc-error-log-ignore-listed/page.js:16:14)' +
222-
'\n 7 |' +
220+
'\n at Page (app/rsc-error-log-ignore-listed/page.js:13:14)' +
221+
'\n 6 |' +
223222
'\n'
224223
: '\nError: rsc-error-log-ignore-listed' +
225-
'\n at logError (app/rsc-error-log-ignore-listed/page.js:9:16)' +
226-
'\n at runWithInternalIgnored (app/rsc-error-log-ignore-listed/page.js:21:12)' +
224+
'\n at logError (app/rsc-error-log-ignore-listed/page.js:8:16)' +
225+
'\n at runWithInternalIgnored (app/rsc-error-log-ignore-listed/page.js:18:12)' +
227226
// TODO(veil): Webpacks's sourcemap loader drops `ignoreList`
228227
// TODO(veil): Webpack's sourcemap loader creates an incorrect `sources` entry.
229228
// Can be worked around by using `./sourcemapped.ts` instead of `sourcemapped.ts`.
230229
'\n at runInternalIgnored (webpack-internal:/(rsc)/internal-pkg/ignored.ts:6:9)' +
231-
'\n at runWithExternalSourceMapped (app/rsc-error-log-ignore-listed/page.js:20:29)' +
232-
'\n at runWithExternal (app/rsc-error-log-ignore-listed/page.js:19:32)' +
233-
'\n at runWithInternalSourceMapped (app/rsc-error-log-ignore-listed/page.js:18:18)' +
230+
'\n at runWithExternalSourceMapped (app/rsc-error-log-ignore-listed/page.js:17:29)' +
231+
'\n at runWithExternal (app/rsc-error-log-ignore-listed/page.js:16:32)' +
232+
'\n at runWithInternalSourceMapped (app/rsc-error-log-ignore-listed/page.js:15:18)' +
234233
// TODO(veil): Webpack's sourcemap loader creates an incorrect `sources` entry.
235234
// Can be worked around by using `./sourcemapped.ts` instead of `sourcemapped.ts`.
236235
// Realpath does not point into node_modules so we don't ignore it.
237236
'\n at runInternalSourceMapped (webpack-internal:/(rsc)/internal-pkg/sourcemapped.ts:5:9)' +
238-
'\n at runWithInternal (app/rsc-error-log-ignore-listed/page.js:17:28)' +
237+
'\n at runWithInternal (app/rsc-error-log-ignore-listed/page.js:14:28)' +
239238
// Realpath does not point into node_modules so we don't ignore it.
240239
'\n at runInternal (internal-pkg/index.js:2:9)' +
241-
'\n at Page (app/rsc-error-log-ignore-listed/page.js:16:14)' +
242-
'\n 7 |' +
240+
'\n at Page (app/rsc-error-log-ignore-listed/page.js:13:14)' +
241+
'\n 6 |' +
243242
'\n'
244243
)
245244
} else {
@@ -293,42 +292,47 @@ describe('app-dir - server source maps', () => {
293292
})
294293

295294
it('logged errors preserve their name', async () => {
296-
const outputIndex = next.cliOutput.length
297-
await next.render('/rsc-error-log-custom-name')
295+
let cliOutput = next.cliOutput
296+
if (isNextDev) {
297+
const outputIndex = next.cliOutput.length
298+
await next.render('/rsc-error-log-custom-name')
299+
cliOutput = next.cliOutput.slice(outputIndex)
300+
}
298301

299302
await retry(() => {
300-
expect(next.cliOutput.slice(outputIndex)).toContain(
303+
expect(cliOutput).toContain(
301304
// TODO: isNextDev ? 'UnnamedError: rsc-error-log-custom-name-Foo' : '[Error]: rsc-error-log-custom-name-Foo'
302305
isNextDev
303306
? 'Error: rsc-error-log-custom-name-Foo'
304307
: 'Error: rsc-error-log-custom-name-Foo'
305308
)
306309
})
307310

308-
expect(next.cliOutput.slice(outputIndex)).toContain(
311+
expect(cliOutput).toContain(
309312
// TODO: isNextDev ? 'NamedError [MyError]: rsc-error-log-custom-name-Bar' : '[MyError]: rsc-error-log-custom-name-Bar'
310-
isNextDev ? 'Error [MyError]: rsc-error-log-custom-name-Bar' : 'Error [MyError]: rsc-error-log-custom-name-Bar'
313+
isNextDev
314+
? 'Error [MyError]: rsc-error-log-custom-name-Bar'
315+
: 'Error [MyError]: rsc-error-log-custom-name-Bar'
311316
)
312317
})
313318

314319
it('handles invalid sourcemaps gracefully', async () => {
315-
const outputIndex = next.cliOutput.length
316-
await next.render('/bad-sourcemap')
317-
318-
await retry(() => {
319-
expect(normalizeCliOutput(next.cliOutput.slice(outputIndex))).toContain(
320-
'Error: bad-sourcemap'
321-
)
322-
})
323-
324320
if (isNextDev) {
321+
const outputIndex = next.cliOutput.length
322+
await next.render('/bad-sourcemap')
323+
324+
await retry(() => {
325+
expect(normalizeCliOutput(next.cliOutput.slice(outputIndex))).toContain(
326+
'Error: bad-sourcemap'
327+
)
328+
})
325329
if (isTurbopack) {
326330
expect(normalizeCliOutput(next.cliOutput.slice(outputIndex))).toContain(
327331
// Node.js is fine with invalid URLs in index maps apparently.
328332
'' +
329333
'\nError: bad-sourcemap' +
330-
'\n at logError (custom://[badhost]/app/bad-sourcemap/page.js:8:16)' +
331-
'\n at Page (custom://[badhost]/app/bad-sourcemap/page.js:13:2)' +
334+
'\n at logError (custom://[badhost]/app/bad-sourcemap/page.js:6:16)' +
335+
'\n at Page (custom://[badhost]/app/bad-sourcemap/page.js:10:2)' +
332336
// TODO: Remove blank line
333337
'\n'
334338
)
@@ -340,15 +344,16 @@ describe('app-dir - server source maps', () => {
340344
'' +
341345
`\nwebpack-internal:///(rsc)/./app/bad-sourcemap/page.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null` +
342346
'\nError: bad-sourcemap' +
343-
'\n at logError (webpack-internal:///(rsc)/./app/bad-sourcemap/page.js:14:19)' +
344-
'\n at Page (webpack-internal:///(rsc)/./app/bad-sourcemap/page.js:18:5)'
347+
'\n at logError (webpack-internal:///(rsc)/./app/bad-sourcemap/page.js:12:19)' +
348+
'\n at Page (webpack-internal:///(rsc)/./app/bad-sourcemap/page.js:15:5)'
345349
)
346-
// Expect the invalid sourcemap warning only once.
350+
// Expect the invalid sourcemap warning only once per render.
351+
// Dynamic I/O renders three times.
347352
expect(
348353
normalizeCliOutput(next.cliOutput.slice(outputIndex)).split(
349354
'Invalid source map.'
350355
).length - 1
351-
).toEqual(1)
356+
).toEqual(3)
352357
}
353358
} else {
354359
// TODO: test `next start` with `--enable-source-maps`

0 commit comments

Comments
 (0)