Skip to content

fix(rivetkit): add back dev hot reloading in next#3997

Closed
NathanFlurry wants to merge 1 commit into
01-21-fix_rivetkit_fix_routing_of__websocket_from
01-21-fix_rivetkit_add_back_dev_hot_reloading_in_next
Closed

fix(rivetkit): add back dev hot reloading in next#3997
NathanFlurry wants to merge 1 commit into
01-21-fix_rivetkit_fix_routing_of__websocket_from
01-21-fix_rivetkit_add_back_dev_hot_reloading_in_next

Conversation

@NathanFlurry

Copy link
Copy Markdown
Member

No description provided.

NathanFlurry commented Jan 22, 2026

Copy link
Copy Markdown
Member Author

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

claude Bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

PR Review: fix(rivetkit): add back dev hot reloading in next

Summary

This PR reverts a temporary debugging change that disabled the development hot reloading feature in the Next.js integration. The change restores the proper environment check for file watching.

Changes

File: rivetkit-typescript/packages/next-js/src/mod.ts:55

  • Before: if (false) - Hot reloading was disabled
  • After: if (process.env.NODE_ENV === "development") - Hot reloading enabled in development

Review

✅ Code Quality

  • The change is minimal and focused
  • Restores the intended behavior for development environments
  • The condition properly checks NODE_ENV which is the standard Next.js environment variable
  • Code follows existing patterns in the file (line 14 uses the same check for similar environment-based logic)

✅ Best Practices

  • Appropriate use of environment-based conditional logic
  • The file watching mechanism is well-documented with comments explaining the hack and why it's necessary (lines 147-154)
  • The implementation properly handles cleanup with abort controllers and interval clearing
  • Follows the codebase pattern of using environment checks for development-specific behavior

✅ Functionality

  • Re-enables the handleRequestWithFileWatcher function which:
    • Watches for file changes in the compiled Next.js route (.next/server/app/api/rivet/[...all]/route.js)
    • Aborts long-running requests when files change to prevent stale actors from running old code
    • Properly cleans up file watchers when streams finish or requests are aborted
  • This is necessary because Next.js doesn't terminate long-running requests on file changes, which would leave stale Rivet Actors running with old code during development
  • The file watcher correctly handles:
    • SSE streams (waits for stream completion)
    • Non-streaming responses (cleans up immediately)
    • Request aborts (cleans up listeners and intervals)

🔍 Observations

  1. Test Coverage: No tests found in this package - the hot reloading logic could benefit from integration tests to prevent accidental disabling in the future
  2. Polling Implementation: The file watcher uses polling (every 1000ms at line 191) rather than native file system events, which is documented as intentional to avoid cross-platform issues and inotify limit problems
  3. Hardcoded Path: The route path is hardcoded to .next/server/app/api/rivet/[...all]/route.js (line 160-162), which assumes a specific routing structure - this is acceptable for a framework integration but worth noting

✅ Security & Performance

  • Security: No security concerns introduced. The feature is properly scoped to development only
  • Performance:
    • Performance impact is limited to development environment only (production unaffected)
    • The polling interval (1s) is reasonable for development use and won't cause excessive CPU usage
    • Cleanup is properly handled to prevent memory leaks from abandoned intervals

📝 Minor Suggestions

While the PR is fine as-is, consider for future improvements:

  1. Add integration tests that verify the file watching behavior
  2. Consider adding a comment explaining why if (false) was temporarily used (if this was debugging code that accidentally got committed)

Verdict

LGTM

This is a clean fix that restores important development experience functionality. The change is:

  • Safe and well-scoped
  • Properly conditioned to only affect development environments
  • Necessary for maintaining a good developer experience with Next.js hot reloading
  • Consistent with the codebase patterns

The implementation is well-thought-out with proper cleanup, error handling, and documentation. Approving for merge.

@pkg-pr-new

pkg-pr-new Bot commented Jan 22, 2026

Copy link
Copy Markdown
More templates

@rivetkit/cloudflare-workers

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

@rivetkit/db

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

@rivetkit/framework-base

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

@rivetkit/next-js

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

@rivetkit/react

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

rivetkit

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

@rivetkit/sql-loader

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

@rivetkit/virtual-websocket

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

@rivetkit/engine-runner

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

@rivetkit/engine-runner-protocol

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

commit: 6e92446

@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_routing_of__websocket_ branch from 939ba39 to b7a6ac3 Compare January 22, 2026 04:25
@graphite-app

graphite-app Bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

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_add_back_dev_hot_reloading_in_next 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