Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Conversation

@graphite-app
Copy link

@graphite-app graphite-app bot commented Oct 19, 2025

This draft PR was created by the Graphite merge queue.
Trunk will be fast forwarded to the HEAD of this PR when CI passes, and the original PRs will be closed.

The following PRs are included in this draft PR:

@vercel
Copy link

vercel bot commented Oct 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
rivetkit-next-js-max Ready Ready Preview Comment Oct 19, 2025 11:40pm
rivetkit-serverless Ready Ready Preview Comment Oct 19, 2025 11:40pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@claude
Copy link

claude bot commented Oct 19, 2025

PR Review: Next.js Build Phase Fixes

This PR combines two fixes (#1408 and #1409) to address Next.js compatibility issues. Overall, the changes are well-motivated and solve real problems, but there are some considerations to address.


Code Quality & Best Practices

Strong Points:

  • Clean removal of commented-out code in eventsource.ts (lines 45-82) - good housekeeping
  • Typo fix: "implemnetation" → "implementation"
  • Improved comment formatting with proper multi-line structure
  • Follows existing code patterns consistently

Suggestions:

  1. Comment Style Consistency: The eventsource.ts file now has inline comments while websocket.ts lacks similar explanation. Consider adding a comment to websocket.ts explaining why the indirection is needed:

    // Use indirection to prevent webpack from bundling this optional peer dependency
    const moduleName = "ws";
    const ws = await import(/* webpackIgnore: true */ moduleName);
  2. Environment Variable Hardcoding: The Next.js phase detection in remote-manager-driver/mod.ts:62 uses a hardcoded string comparison. Consider:

    • Defining a constant for clarity: const NEXT_BUILD_PHASE = "phase-production-build"
    • The Next.js link in the comment is helpful, but the version is pinned. Consider using a permalink to a release tag rather than a specific commit SHA.

🐛 Potential Issues

Critical:

  1. Configuration Mutation (remote-manager-driver/mod.ts:64): The code mutates the runConfig parameter:
    runConfig.disableHealthCheck = true;
    This could have unintended side effects if the same config object is reused elsewhere. Recommendation: Either document this mutation clearly or create a defensive copy:
    this.#config = { ...runConfig, disableHealthCheck: true };

Minor:
2. Browser Environment Handling: In eventsource.ts, the browser environment check was removed. The code now only handles Node.js environments. While this might be intentional (the comment states browser EventSource doesn't support custom headers), it would be clearer to explicitly handle the browser case with a helpful error message rather than falling through to the mock.

  1. Error Type Loss: In eventsource.ts:28, the caught error is typed as err but not used. Consider logging it for debugging:
    catch (err) {
        logger().debug({ msg: "eventsource peer dependency not available", error: err });
        // EventSource not available

Performance Considerations

  • ✅ No performance regressions introduced
  • ✅ The singleton pattern for dynamic imports is maintained correctly
  • ✅ The string indirection for imports is a build-time concern with zero runtime cost

🔒 Security Concerns

  • ✅ No security issues identified
  • ✅ The getEnvUniversal function safely reads environment variables
  • ✅ No user input is involved in the environment variable check

🧪 Test Coverage

Concerns:

  1. Missing Tests: No test files were modified, and there appear to be no tests for:
    • The importEventSource() function
    • The importWebSocket() function
    • The Next.js build phase detection logic

Recommendations:

  • Add unit tests for the Next.js phase detection to ensure it works correctly
  • Consider adding integration tests that verify builds work correctly with webpack/Next.js
  • Test that the health check is properly disabled during build phase

📋 Additional Recommendations

  1. Consider Environment-Based Feature Flags: The Next.js detection is reactive. Consider if there's a better way to configure this (e.g., via ClientConfig options) to make it more explicit and testable.

  2. Logging Clarity: The log message at line 63 says "detected next.js build phase" - consider adding more context about why this matters:

    logger().info("detected next.js build phase, disabling health check to prevent build-time network requests");
  3. Type Safety: Consider using a branded type or enum for the NEXT_PHASE values if you expect to check for other phases in the future.


🎯 Verdict

Approval Status: ✅ Approve with minor suggestions

The fixes address real compatibility issues with Next.js, and the webpack ignore comments are the correct solution for optional peer dependencies. The main concern is the config mutation which should be addressed before merging.

Priority Fixes Before Merge:

  1. Address the runConfig mutation (either document or use immutable approach)
  2. Add basic test coverage for the Next.js detection logic

Nice-to-Have Improvements:

  1. Add explanatory comment to websocket.ts
  2. Improve error logging in eventsource.ts
  3. Add integration tests for build phase behavior

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants