Skip to content

fix(rivetkit): fix fetch handler in nextjs serverless#3998

Closed
NathanFlurry wants to merge 1 commit into
01-21-fix_rivetkit_add_back_dev_hot_reloading_in_nextfrom
01-21-fix_rivetkit_fix_fetch_handler_in_nextjs_serverless
Closed

fix(rivetkit): fix fetch handler in nextjs serverless#3998
NathanFlurry wants to merge 1 commit into
01-21-fix_rivetkit_add_back_dev_hot_reloading_in_nextfrom
01-21-fix_rivetkit_fix_fetch_handler_in_nextjs_serverless

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Member Author

NathanFlurry commented Jan 22, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jan 22, 2026

PR Review: Fix fetch handler in Next.js serverless

Summary

This PR fixes a critical bug in the Next.js integration where the global fetch function was incorrectly passed to handleRequestWithFileWatcher instead of registry.handler. This would cause requests in development mode to bypass the RivetKit handler entirely.

Code Quality ✅

The fix is correct and appropriate:

  • Line 57 now correctly passes registry.handler instead of the global fetch function
  • This aligns with the production code path (line 61) which also uses registry.handler
  • The handleRequestWithFileWatcher function signature at line 84 accepts a generic fetch-compatible handler, so this change is type-safe

Bug Analysis 🐛

The bug:

  • In development mode, handleRequestWithFileWatcher was being passed the global fetch function
  • This would have caused requests to be handled by the browser/Node.js fetch API instead of RivetKit handler
  • The request would fail because the global fetch expects an absolute URL, not the RivetKit routing logic

Impact: This would break all development mode requests in Next.js serverless deployments.

Code Consistency ✅

The fix maintains consistency with the production code path. Both paths now correctly use registry.handler, which ensures the runtime is initialized, starts the serverless handler, and routes requests through RivetKit request handling logic.

Testing Recommendations 🧪

While this is a simple one-line fix, consider:

  1. Manual testing in Next.js development mode to verify requests are handled correctly
  2. Verifying that file watching still works as expected
  3. Testing with long-running SSE streams to ensure the abort signal handling works properly

Performance ✅

No performance concerns. The change simply routes to the correct handler.

Security ✅

No security concerns. This fixes a bug that would have prevented proper request handling.


Overall Assessment:LGTM - This is a straightforward bug fix that corrects an obvious error. The change is minimal, correct, and maintains consistency with the production code path.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 22, 2026

More templates

@rivetkit/cloudflare-workers

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/cloudflare-workers@3998

@rivetkit/db

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/db@3998

@rivetkit/framework-base

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/framework-base@3998

@rivetkit/next-js

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/next-js@3998

@rivetkit/react

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/react@3998

rivetkit

pnpm add https://pkg.pr.new/rivet-dev/rivet/rivetkit@3998

@rivetkit/sql-loader

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sql-loader@3998

@rivetkit/virtual-websocket

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/virtual-websocket@3998

@rivetkit/engine-runner

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner@3998

@rivetkit/engine-runner-protocol

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner-protocol@3998

commit: 45f73be

@NathanFlurry NathanFlurry force-pushed the 01-21-fix_rivetkit_add_back_dev_hot_reloading_in_next branch from 6681532 to 6e92446 Compare January 22, 2026 04:25
@NathanFlurry NathanFlurry force-pushed the 01-21-fix_rivetkit_fix_fetch_handler_in_nextjs_serverless branch from 8ada9bb to 45f73be Compare January 22, 2026 04:25
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app Bot commented Jan 22, 2026

Merge activity

  • Jan 22, 6:58 AM UTC: NathanFlurry added this pull request to the Graphite merge queue.
  • Jan 22, 6:59 AM UTC: CI is running for this pull request on a draft pull request (#4007) due to your merge queue CI optimization settings.
  • Jan 22, 7:00 AM UTC: Merged by the Graphite merge queue via draft PR: #4007.

@graphite-app graphite-app Bot closed this Jan 22, 2026
@graphite-app graphite-app Bot deleted the 01-21-fix_rivetkit_fix_fetch_handler_in_nextjs_serverless branch January 22, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant