Skip to content

Conversation

tusharpandey13
Copy link
Contributor

@tusharpandey13 tusharpandey13 commented Sep 21, 2025

Fixes React import dependency in server-side helpers that caused bundling errors in Next.js middleware and edge runtime environments.

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

🔍 RCA

The import type React from "react" statement in with-page-auth-required.ts created a transitive dependency that caused Next.js bundler to include React references in edge runtime contexts where React is not available.
This affected ANY import from @auth0/nextjs-auth0/server due to module export bundling, not just direct usage of withPageAuthRequired.

📋 Changes

Changes AppRouterPageRoute return type from Promise<React.JSX.Element> to Promise<unknown> to maintain type safety without requiring React.

  • Changed src/server/helpers/with-page-auth-required.ts: Remove React import and change AppRouterPageRoute return type to Promise<unknown>
  • Changed src/server/helpers/with-page-auth-required.test.ts: Add type assertion for test compatibility with ReactDOMServer

📎 References

Fixes: #2328

🎯 Testing

Automated:

  • All existing 340 unit tests pass with the type safety improvements
  • Added type assertion in test file to maintain ReactDOMServer compatibility

Manual:

  1. Import Auth0Client from @auth0/nextjs-auth0/server in Next.js middleware
  2. Verify no "React is not defined" errors occur during build or runtime
  3. Confirm withPageAuthRequired still works with App Router pages
  4. Test in Next.js 14.2+ with Pages Router configuration
  5. Verify compiled output contains no React references in dist/server/ files

@tusharpandey13 tusharpandey13 requested a review from a team as a code owner September 21, 2025 19:36
@tusharpandey13 tusharpandey13 changed the title fix: do not import react in with-page-auth-required.ts bugfix: Remove React dependency from server helpers to fix edge runtime bundling Sep 21, 2025
@codecov-commenter
Copy link

codecov-commenter commented Sep 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.47%. Comparing base (6daabeb) to head (0b9f432).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2329   +/-   ##
=======================================
  Coverage   85.47%   85.47%           
=======================================
  Files          26       26           
  Lines        2636     2636           
  Branches      486      486           
=======================================
  Hits         2253     2253           
  Misses        377      377           
  Partials        6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tusharpandey13 tusharpandey13 marked this pull request as draft September 21, 2025 19:37
@tusharpandey13
Copy link
Contributor Author

@claude

Copy link
Contributor

github-actions bot commented Sep 21, 2025

Claude finished @tusharpandey13's task —— View job


Code Review Complete ✅

  • Read PR diff and understand changes
  • Review project context and architecture
  • Create pending review
  • Analyze changes for potential issues
  • Submit comprehensive review

Summary: This PR effectively solves the edge runtime bundling issue by removing the React import dependency from server helpers. The changes are minimal, focused, and maintain type safety while eliminating the problematic React reference. The solution is appropriate and ready for merge.


Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall Assessment

✅ This pull request is ready to be merged

The changes effectively solve the edge runtime bundling issue by removing the React import dependency from server helpers. The type safety is maintained while eliminating the problematic React reference that caused bundling errors in Next.js middleware and edge runtime contexts.

Key points:

  • Clean removal of React import without compromising functionality
  • Appropriate use of unknown type maintains type safety while avoiding React dependency
  • Test updates correctly handle the type assertion
  • All existing tests pass, indicating no regressions

@tusharpandey13 tusharpandey13 marked this pull request as ready for review September 21, 2025 19:59
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.

The ReferenceError: React is not defined error when using @auth0/nextjs-auth0/server
2 participants