Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
9b61e06e
Commit
9b61e06e
authored
Jan 12, 2026
by
Tim Neutkens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add regression test for console.error infinite loop (#88234)
parent
5746e3bb
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
478 additions
and
0 deletions
+478
-0
page.tsx
...nt/app-dir/console-error-loop/app/devtools-error/page.tsx
+84
-0
page.tsx
...nt/app-dir/console-error-loop/app/internal-error/page.tsx
+71
-0
layout.tsx
test/development/app-dir/console-error-loop/app/layout.tsx
+12
-0
page.tsx
.../app-dir/console-error-loop/app/non-error-object/page.tsx
+45
-0
page.tsx
test/development/app-dir/console-error-loop/app/page.tsx
+34
-0
page.tsx
...ment/app-dir/console-error-loop/app/rapid-errors/page.tsx
+37
-0
page.tsx
...nt/app-dir/console-error-loop/app/suspense-error/page.tsx
+20
-0
console-error-loop.test.ts
...ent/app-dir/console-error-loop/console-error-loop.test.ts
+170
-0
next.config.js
test/development/app-dir/console-error-loop/next.config.js
+5
-0
No files found.
test/development/app-dir/console-error-loop/app/devtools-error/page.tsx
0 → 100644
View file @
9b61e06e
'use client'
import
{
useEffect
,
useState
}
from
'react'
// This page tests the actual Next.js DevTools console.error behavior
// by triggering console.error in ways that might cause issues in the handler
export
default
function
DevToolsErrorPage
()
{
const
[
status
,
setStatus
]
=
useState
(
'waiting'
)
useEffect
(()
=>
{
// Track console.error calls to detect infinite loops
let
errorCallCount
=
0
const
startTime
=
Date
.
now
()
// Wrap the current console.error (which is already patched by Next.js DevTools)
const
currentConsoleError
=
console
.
error
console
.
error
=
function
(...
args
:
any
[])
{
errorCallCount
++
// If we're getting too many errors too quickly, it's likely an infinite loop
const
elapsed
=
Date
.
now
()
-
startTime
if
(
errorCallCount
>
100
&&
elapsed
<
5000
)
{
// Detected infinite loop - restore original and report
console
.
error
=
currentConsoleError
;(
window
as
any
).
__infiniteLoopDetected
=
true
;(
window
as
any
).
__errorCallCount
=
errorCallCount
setStatus
(
'infinite-loop-detected'
)
return
// Stop the loop
}
;(
window
as
any
).
__errorCallCount
=
errorCallCount
currentConsoleError
.
apply
(
console
,
args
)
}
// Expose for testing
;(
window
as
any
).
__infiniteLoopDetected
=
false
;(
window
as
any
).
__errorCallCount
=
0
;(
window
as
any
).
__testReady
=
true
return
()
=>
{
console
.
error
=
currentConsoleError
}
},
[])
// This triggers a console.error that goes through the actual Next.js DevTools handler
const
triggerComplexError
=
()
=>
{
setStatus
(
'triggered'
)
// Log an error with complex arguments that the DevTools handler processes
console
.
error
(
'%c%s%c%o
\
n
\
n%s
\
n
\
n%s
\
n'
,
'background: #e6e6e6;'
,
' Test '
,
''
,
new
Error
(
'Complex error with format string'
),
'Additional context'
,
'More info'
)
}
const
triggerMalformedArgs
=
()
=>
{
setStatus
(
'triggered-malformed'
)
// Log errors with unusual arguments that might trip up the handler
console
.
error
(
undefined
)
console
.
error
(
null
,
undefined
,
{
circular
:
{}
})
console
.
error
(
Symbol
(
'test'
),
BigInt
(
123
))
// Create circular reference
const
circular
:
any
=
{
a
:
1
}
circular
.
self
=
circular
console
.
error
(
'Circular:'
,
circular
)
}
return
(
<
div
>
<
h1
>
DevTools Error Handler Test
</
h1
>
<
p
id=
"status"
>
Status:
{
status
}
</
p
>
<
button
id=
"trigger-complex"
onClick=
{
triggerComplexError
}
>
Trigger Complex Error
</
button
>
<
button
id=
"trigger-malformed"
onClick=
{
triggerMalformedArgs
}
>
Trigger Malformed Args
</
button
>
</
div
>
)
}
test/development/app-dir/console-error-loop/app/internal-error/page.tsx
0 → 100644
View file @
9b61e06e
'use client'
import
{
useEffect
,
useState
}
from
'react'
// This page simulates the bug from https://github.com/vercel/next.js/issues/88234
// where an internal error in the console.error handler causes an infinite loop
export
default
function
InternalErrorPage
()
{
const
[
errorCount
,
setErrorCount
]
=
useState
(
0
)
const
[
testComplete
,
setTestComplete
]
=
useState
(
false
)
useEffect
(()
=>
{
// Track how many times console.error is called
let
count
=
0
const
originalError
=
console
.
error
// This simulates what happens when Next.js DevTools intercepts console.error
// and an internal error occurs during processing
console
.
error
=
function
(...
args
:
any
[])
{
count
++
setErrorCount
(
count
)
// Simulate an internal error that would occur during console.error processing
// This is similar to what happens with the _interop_require_wildcard bug
if
(
count
===
1
)
{
// On the first call, throw an error that will be caught and logged
// If there's no protection, this causes an infinite loop
try
{
// Simulate internal processing that fails
const
faultyFunction
=
(
undefined
as
any
).
notAFunction
faultyFunction
()
}
catch
(
internalError
)
{
// In the buggy scenario, this error gets logged via console.error
// which triggers the patched console.error again
originalError
.
call
(
console
,
'Internal DevTools error:'
,
internalError
)
}
}
// Call original to actually log
originalError
.
apply
(
console
,
args
)
}
// Expose count for the test
;(
window
as
any
).
__internalErrorCount
=
()
=>
count
// After 3 seconds, mark test complete and check the count
const
timeout
=
setTimeout
(()
=>
{
setTestComplete
(
true
)
;(
window
as
any
).
__finalErrorCount
=
count
},
3000
)
return
()
=>
{
console
.
error
=
originalError
clearTimeout
(
timeout
)
}
},
[])
const
triggerError
=
()
=>
{
console
.
error
(
'Test error to trigger the bug'
)
}
return
(
<
div
>
<
h1
>
Internal Error Test
</
h1
>
<
p
id=
"error-count"
>
Error count:
{
errorCount
}
</
p
>
<
p
id=
"test-status"
>
{
testComplete
?
'Test complete'
:
'Testing...'
}
</
p
>
<
button
id=
"trigger-internal-error"
onClick=
{
triggerError
}
>
Trigger Error with Internal Failure
</
button
>
</
div
>
)
}
test/development/app-dir/console-error-loop/app/layout.tsx
0 → 100644
View file @
9b61e06e
export
default
function
RootLayout
({
children
,
}:
{
children
:
React
.
ReactNode
})
{
return
(
<
html
>
<
head
/>
<
body
>
{
children
}
</
body
>
</
html
>
)
}
test/development/app-dir/console-error-loop/app/non-error-object/page.tsx
0 → 100644
View file @
9b61e06e
'use client'
import
{
useEffect
}
from
'react'
export
default
function
NonErrorObjectPage
()
{
useEffect
(()
=>
{
// Initialize error counter
;(
window
as
any
).
__errorCount
=
0
// Patch console.error to count calls
const
originalError
=
console
.
error
console
.
error
=
function
(...
args
:
any
[])
{
;(
window
as
any
).
__errorCount
++
originalError
.
apply
(
console
,
args
)
}
return
()
=>
{
console
.
error
=
originalError
}
},
[])
return
(
<
div
>
<
h1
>
Non-Error Object Console Error Test
</
h1
>
<
button
id=
"trigger-string-error"
onClick=
{
()
=>
console
.
error
(
'String error message'
)
}
>
Trigger String Error
</
button
>
<
button
id=
"trigger-object-error"
onClick=
{
()
=>
console
.
error
({
message
:
'Object error'
,
code
:
123
})
}
>
Trigger Object Error
</
button
>
<
button
id=
"trigger-null-error"
onClick=
{
()
=>
console
.
error
(
null
,
undefined
,
'mixed args'
)
}
>
Trigger Null Error
</
button
>
</
div
>
)
}
test/development/app-dir/console-error-loop/app/page.tsx
0 → 100644
View file @
9b61e06e
'use client'
import
{
useEffect
}
from
'react'
export
default
function
Home
()
{
useEffect
(()
=>
{
// Initialize error counter
;(
window
as
any
).
__errorCount
=
0
// Patch console.error to count calls (for testing purposes)
const
originalError
=
console
.
error
console
.
error
=
function
(...
args
:
any
[])
{
;(
window
as
any
).
__errorCount
++
originalError
.
apply
(
console
,
args
)
}
return
()
=>
{
console
.
error
=
originalError
}
},
[])
const
triggerError
=
()
=>
{
console
.
error
(
new
Error
(
'Test error for console loop check'
))
}
return
(
<
div
>
<
h1
>
Console Error Loop Test
</
h1
>
<
button
id=
"trigger-error"
onClick=
{
triggerError
}
>
Trigger Console Error
</
button
>
</
div
>
)
}
test/development/app-dir/console-error-loop/app/rapid-errors/page.tsx
0 → 100644
View file @
9b61e06e
'use client'
import
{
useEffect
}
from
'react'
export
default
function
RapidErrorsPage
()
{
useEffect
(()
=>
{
// Initialize error counter
;(
window
as
any
).
__errorCount
=
0
// Patch console.error to count calls
const
originalError
=
console
.
error
console
.
error
=
function
(...
args
:
any
[])
{
;(
window
as
any
).
__errorCount
++
originalError
.
apply
(
console
,
args
)
}
return
()
=>
{
console
.
error
=
originalError
}
},
[])
const
triggerRapidErrors
=
()
=>
{
// Trigger multiple console.errors rapidly
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
console
.
error
(
new
Error
(
`Rapid error
${
i
}
`
))
}
}
return
(
<
div
>
<
h1
>
Rapid Console Errors Test
</
h1
>
<
button
id=
"trigger-rapid-errors"
onClick=
{
triggerRapidErrors
}
>
Trigger Rapid Errors
</
button
>
</
div
>
)
}
test/development/app-dir/console-error-loop/app/suspense-error/page.tsx
0 → 100644
View file @
9b61e06e
import
{
Suspense
}
from
'react'
// Simulate an async component that might trigger console.error during suspense
async
function
AsyncContent
()
{
// Simulate async work
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
100
))
return
<
div
id=
"content"
>
Loaded
</
div
>
}
export
default
function
SuspenseErrorPage
()
{
return
(
<
div
>
<
h1
>
Suspense Error Test
</
h1
>
<
Suspense
fallback=
{
<
div
>
Loading...
</
div
>
}
>
<
AsyncContent
/>
</
Suspense
>
</
div
>
)
}
test/development/app-dir/console-error-loop/console-error-loop.test.ts
0 → 100644
View file @
9b61e06e
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
retry
}
from
'next-test-utils'
// Regression test for https://github.com/vercel/next.js/issues/88234
// DevTools console.error interceptor should not cause infinite error loops
describe
(
'console-error-loop'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
})
// This test reproduces the bug from issue #88234
// When an internal error occurs in the console.error handler (like the
// _interop_require_wildcard bug), it should NOT cause an infinite loop
it
(
'should not cause infinite loop when console.error handler throws internally'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/internal-error'
)
// Wait for page to be interactive
await
browser
.
waitForElementByCss
(
'#trigger-internal-error'
)
// Trigger the error that causes internal failure
await
browser
.
elementByCss
(
'#trigger-internal-error'
).
click
()
// Wait for potential infinite loop to manifest
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
3000
))
// Get the final error count - if there's an infinite loop, this would be huge
const
errorCount
=
await
browser
.
eval
(
'window.__finalErrorCount || 0'
)
// The error count should be small (just the initial error + internal error log)
// If there's an infinite loop, this would be in the hundreds or thousands
// This is the key assertion - it should FAIL if the bug exists
expect
(
errorCount
).
toBeLessThan
(
10
)
})
it
(
'should not cause infinite console.error loop when logging errors'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
// Wait for page to be interactive
await
browser
.
waitForElementByCss
(
'#trigger-error'
)
// Clear any existing logs
await
browser
.
eval
(
'window.__errorCount = 0'
)
// Click button to trigger console.error
await
browser
.
elementByCss
(
'#trigger-error'
).
click
()
// Wait a bit for any potential infinite loop to manifest
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
2000
))
// Get the error count
const
errorCount
=
await
browser
.
eval
(
'window.__errorCount'
)
// The error should only be logged once (or a small number of times),
// not infinitely. If there's an infinite loop, the count would be very high.
expect
(
errorCount
).
toBeLessThan
(
10
)
// Also verify the original error was logged
const
logs
=
await
browser
.
log
()
const
errorLogs
=
logs
.
filter
(
(
log
)
=>
log
.
source
===
'error'
&&
log
.
message
.
includes
(
'Test error for console loop check'
)
)
// Should have at least one error log
expect
(
errorLogs
.
length
).
toBeGreaterThan
(
0
)
// But not too many (infinite loop would cause many more)
expect
(
errorLogs
.
length
).
toBeLessThan
(
10
)
})
it
(
'should not cause infinite loop when console.error receives non-Error objects'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/non-error-object'
)
// Wait for page to be interactive
await
browser
.
waitForElementByCss
(
'#trigger-string-error'
)
// Trigger various types of console.error calls
await
browser
.
elementByCss
(
'#trigger-string-error'
).
click
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
))
await
browser
.
elementByCss
(
'#trigger-object-error'
).
click
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
))
await
browser
.
elementByCss
(
'#trigger-null-error'
).
click
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
))
// Wait for any potential infinite loop
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
2000
))
// Get the error count
const
errorCount
=
await
browser
.
eval
(
'window.__errorCount'
)
// Should have only 3 errors (one for each click), not an infinite amount
expect
(
errorCount
).
toBeLessThanOrEqual
(
10
)
})
it
(
'should not cause infinite loop when console.error is called rapidly'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/rapid-errors'
)
// Wait for page to be interactive
await
browser
.
waitForElementByCss
(
'#trigger-rapid-errors'
)
// Reset counter
await
browser
.
eval
(
'window.__errorCount = 0'
)
// Click button to trigger rapid console.errors
await
browser
.
elementByCss
(
'#trigger-rapid-errors'
).
click
()
// Wait for the rapid errors to complete and any potential loop to manifest
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
3000
))
// Get the error count
const
errorCount
=
await
browser
.
eval
(
'window.__errorCount'
)
// We trigger 10 rapid errors, so we expect around 10
// If there's an infinite loop, the count would be much higher
expect
(
errorCount
).
toBeGreaterThanOrEqual
(
10
)
expect
(
errorCount
).
toBeLessThan
(
50
)
// Allow some margin but catch infinite loops
})
it
(
'should handle console.error during suspense without infinite loop'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/suspense-error'
)
// Wait for the suspense content to load
await
retry
(
async
()
=>
{
const
text
=
await
browser
.
elementByCss
(
'#content'
).
text
()
expect
(
text
).
toBe
(
'Loaded'
)
})
// Check that there's no excessive error logging
const
logs
=
await
browser
.
log
()
const
errorLogs
=
logs
.
filter
((
log
)
=>
log
.
source
===
'error'
)
// Suspense might log some errors, but should not be infinite
expect
(
errorLogs
.
length
).
toBeLessThan
(
20
)
})
// This test checks the actual Next.js DevTools console.error handler
// for infinite loops when processing complex/malformed arguments
it
(
'should not cause infinite loop in DevTools handler with complex error args'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/devtools-error'
)
// Wait for test setup
await
retry
(
async
()
=>
{
const
ready
=
await
browser
.
eval
(
'window.__testReady'
)
expect
(
ready
).
toBe
(
true
)
})
// Trigger complex error that goes through DevTools handler
await
browser
.
elementByCss
(
'#trigger-complex'
).
click
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1000
))
// Trigger malformed args
await
browser
.
elementByCss
(
'#trigger-malformed'
).
click
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
2000
))
// Check for infinite loop detection
const
infiniteLoopDetected
=
await
browser
.
eval
(
'window.__infiniteLoopDetected'
)
const
errorCount
=
await
browser
.
eval
(
'window.__errorCallCount'
)
// Should not have detected infinite loop
expect
(
infiniteLoopDetected
).
toBe
(
false
)
// Error count should be reasonable (we triggered ~6 console.errors)
// If there's an infinite loop, this would be > 100
expect
(
errorCount
).
toBeLessThan
(
50
)
expect
(
errorCount
).
toBeGreaterThan
(
0
)
// Should have some errors logged
})
})
test/development/app-dir/console-error-loop/next.config.js
0 → 100644
View file @
9b61e06e
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{}
module
.
exports
=
nextConfig
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment