This repository reproduces and fixes a dev-mode RangeError: Maximum call stack size exceeded caused by React's visitAsyncNode function when using database clients like Gel/EdgeDB.
Affected versions: Next.js 16.0.7+ with React 19.2.0+
When async Server Components call database queries (e.g., Gel's .run() method), React's dev-mode async tracking enters infinite recursion due to circular promise chains.
# 1. Clone and install
git clone https://github.com/jere-co/next-debug.git
cd next-debug
pnpm install --ignore-scripts # Skip postinstall to NOT apply patch# 2. Start dev server
pnpm dev
# 3. Visit http://localhost:3000# You'll see: RangeError: Maximum call stack size exceeded# Apply the patch
node patch-visitAsyncNode.cjs
# Restart dev server
pnpm dev
# Visit http://localhost:3000 - page renders successfully- Copy
patch-visitAsyncNode.cjsto your project root - Add to
package.json:
{
"scripts": {
"postinstall": "node patch-visitAsyncNode.cjs"
}
}- Run
pnpm install(or npm/yarn)
The patch auto-applies after each install. To restore original files:
node patch-visitAsyncNode.cjs --restoreReact's visitAsyncNode function uses null as both:
- An "in progress" marker during traversal
- A valid cached result
When circular async node references exist (common with database clients), revisiting a node returns null as if it were a cached result, causing infinite recursion.
Use an IN_PROGRESS sentinel Symbol and always cache results:
constIN_PROGRESS=Symbol.for("react.asyncTraversal.inProgress");functionvisitAsyncNode(request,task,node,visited,cutOff){if(visited.has(node)){constmemo=visited.get(node);if(memo===IN_PROGRESS)returnnull;// Cycle detected, no I/O on this pathreturnmemo;}visited.set(node,IN_PROGRESS);constresult=visitAsyncNodeImpl(request,task,node,visited,cutOff);visited.set(node,result);// Always cachereturnresult;}Note: We return null (not undefined) on cycle detection because undefined signals "abort" semantics which would skip emitting I/O info for other non-cyclic branches.
patch-visitAsyncNode.cjs - Reusable patch script (copy to your project)
PATCH-README.md - Standalone docs for the patch script
react/ - React fork with fix applied
docs/ - Background analysis
BUG-REPORT.md
ROOT-CAUSE-ANALYSIS.md
FINAL-ANALYSIS.md