Skip to content

Conversation

@FAL-coffee
Copy link

Description

Fixes port 42069 conflict (EADDRINUSE error) when running type generation tools and dev server simultaneously.

When react-router typegen or safe-routes typegen runs concurrently with the dev server, both processes attempt to bind to port 42069 used by TanStack DevTools, causing the second process to fail.

This PR adds automatic detection of type generation context and disables DevTools initialization when typegen is running, preventing unnecessary port usage.

Detection methods:

  • Environment variables: TYPEGEN_RUNNING=1, SAFE_ROUTES_TYPEGEN=1
  • npm lifecycle events: npm_lifecycle_event contains "typegen"
  • Command-line arguments: process.argv contains "typegen", "safe-routes"

Implementation:

  • Created isTypegenContext() utility for detection
  • Modified reactRouterDevTools() to return empty array in typegen context
  • Added comprehensive unit tests (18 new tests)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit tests
    • 13 tests for typegen detection logic (all passing)
    • 5 tests for plugin conditional behavior (all passing)
    • All existing 307 tests continue to pass
    • Type checking passes with no errors

Test commands:

pnpm test:lib   # 307/307 tests passing
pnpm test:types # No type errors

Manual verification needed:

# Verify no port conflict
TYPEGEN_RUNNING=1 pnpm dev &
pnpm typegen  # Should not throw EADDRINUSE

# Verify DevTools still works normally
pnpm dev  # DevTools should appear in browser

Checklist:

  • My code follows the guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Prevents EADDRINUSE error when running typegen and dev server simultaneously
by detecting type generation context and disabling DevTools.

- Add isTypegenContext() to detect typegen via env vars and argv
- Return empty plugin array when in typegen context
- Add comprehensive unit tests (18 tests total)
- Maintain backward compatibility for normal dev mode

Fixes port 42069 conflict with TanStack DevTools during typegen execution.
@FAL-coffee
Copy link
Author

#243

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