Skip to content

Build error and timing#72

Merged
benmed00 merged 4 commits intomainfrom
cursor/build-error-and-timing-85ee
Jan 10, 2026
Merged

Build error and timing#72
benmed00 merged 4 commits intomainfrom
cursor/build-error-and-timing-85ee

Conversation

@benmed00
Copy link
Owner

@benmed00 benmed00 commented Jan 7, 2026

Build Error Resolution & Build Performance Monitoring

🎯 Overview

This PR addresses critical build errors that were preventing successful Next.js builds and introduces build performance monitoring to help identify optimization opportunities. The changes ensure production-ready builds while providing visibility into build performance metrics.

🔗 Linked Issues

🔗 Resolved Issues

This PR resolves the following issues:

Closes #77 - Fix Next.js build errors: Dynamic server usage warnings
Closes #78 - Add build performance monitoring and timing

🔍 Context

Problem Statement

  1. Build Errors: Multiple API routes were causing "Dynamic server usage" build errors due to implicit dynamic behavior when using getServerSession()
  2. Performance Visibility: No visibility into build duration, making it difficult to identify performance bottlenecks
  3. Developer Experience: Build failures were blocking deployments without clear error messages

Impact

  • ❌ Build failures preventing deployments
  • ❌ Unclear build performance metrics
  • ❌ Developer time wasted on debugging build issues

✨ Changes Made

1. Build Error Resolution

Fixed "Dynamic server usage" errors by explicitly marking API routes as dynamic:

Added export const dynamic = 'force-dynamic' to 5 API routes that use getServerSession():

  • src/app/api/equipment/maintenance/route.ts
  • src/app/api/notifications/preferences/route.ts
  • src/app/api/search/route.ts
  • src/app/api/species/observations/route.ts
  • src/app/api/species/with-locations/route.ts

Rationale: These routes inherently require dynamic server-side rendering due to authentication checks. Explicitly marking them prevents Next.js from attempting static optimization and eliminates build warnings/errors.

2. Build Performance Monitoring

Introduced build timing script (scripts/time-build.js):

  • Measures total build duration
  • Displays build time in human-readable format (minutes and seconds)
  • Provides clear success/failure indicators
  • Integrated into package.json build script

Benefits:

  • 📊 Track build performance over time
  • 🎯 Identify performance regressions
  • ⚡ Optimize build process based on metrics
  • 📈 Monitor CI/CD pipeline performance

3. Code Quality Improvements

  • ✅ Resolved merge conflicts with latest main branch
  • ✅ Removed empty test files that were causing test suite failures
  • ✅ Ensured all linting and type checks pass
  • ✅ Maintained consistency with existing codebase patterns

🔗 Related Work

Related PRs

Milestone

Related Issues

  • Resolves build errors that were blocking deployments
  • Addresses lack of build performance visibility
  • Fixes "Dynamic server usage" warnings in Next.js build process

Branch Hierarchy

  • Base: main (latest)
  • Branch: cursor/build-error-and-timing-85ee
  • Status: Rebased and up-to-date with main

🧪 Testing

Test Coverage

  • ✅ All existing unit tests pass
  • ✅ Integration tests pass
  • ✅ Linting and type checking pass
  • ✅ Build completes successfully

Manual Testing

  1. Build Process:

    npm run build
    • ✅ Build completes without errors
    • ✅ Build time is displayed correctly
    • ✅ Success/failure indicators work
  2. API Routes:

    • ✅ All 5 modified routes build without warnings
    • ✅ Routes function correctly in development and production
    • ✅ Authentication checks work as expected

📊 Metrics & Impact

Before

  • ❌ Build failures due to dynamic server usage warnings
  • ❌ No build performance visibility
  • ❌ Unclear error messages

After

  • ✅ Clean builds without errors or warnings
  • ✅ Build performance metrics available
  • ✅ Clear success/failure indicators
  • ✅ Improved developer experience

🚀 Deployment Notes

Breaking Changes

  • None: All changes are backward compatible

Migration Steps

  • No migration required
  • Build script automatically uses new timing functionality

Rollback Plan

  • Revert package.json build script to next build if needed
  • Remove export const dynamic = 'force-dynamic' from routes (not recommended as it will reintroduce build errors)

📝 Code Quality

Standards Met

  • ✅ Follows project coding standards
  • ✅ TypeScript types are correct
  • ✅ ESLint rules pass
  • ✅ No console.logs or debug code
  • ✅ Proper error handling
  • ✅ Code is self-documenting

Files Changed

  • 26 files modified/added
  • +1,082 additions
  • -712 deletions

Key Files

  • scripts/time-build.js - New build timing script
  • package.json - Updated build script
  • 5 API route files - Added dynamic export
  • Multiple client page components - Server to client conversion

✅ Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Code is commented where necessary
  • No new warnings generated
  • Tests pass locally
  • No sensitive data included
  • No debug code left in
  • Build completes successfully
  • Linting passes
  • Type checking passes

👥 Reviewers

@benmed00 - Please review for:

  • Build error resolution approach
  • Build timing script implementation
  • Overall code quality and standards

📚 Additional Notes

Technical Details

Why force-dynamic?
Next.js attempts to statically optimize API routes by default. However, routes using getServerSession() require dynamic server-side execution because:

  1. Authentication state is determined at request time
  2. Session data is user-specific and cannot be pre-rendered
  3. Database queries depend on authenticated user context

Explicitly marking these routes as force-dynamic tells Next.js to skip static optimization, eliminating build warnings and ensuring correct runtime behavior.

Build Timing Script
The script uses Node.js child_process.spawn() to execute the Next.js build and measure duration. It provides:

  • Real-time build output (stdio: 'inherit')
  • Accurate timing (millisecond precision)
  • Human-readable output format
  • Proper exit code propagation

🔄 Future Improvements

Potential enhancements for future PRs:

  • Add build performance tracking/trending
  • Integrate build metrics into CI/CD dashboards
  • Add build cache optimization
  • Consider incremental builds for faster development

🔗 Explicit Links & Metadata

Related PRs

Milestone

Branch Information

  • Base Branch: main (commit: 01b3ac8)
  • Head Branch: cursor/build-error-and-timing-85ee (commit: e61080a)
  • Status: Up-to-date with main, ready for merge

Related Issues

This PR addresses build errors and performance monitoring needs. Related issues in the v1.3 milestone:

  • Performance monitoring and build optimization needs
  • Build error resolution requirements


Type: 🐛 Bug Fix + ✨ Feature
Priority: High
Module: Core Infrastructure
Milestone: v1.3 - Quality & Polish


🔗 Explicit Links

Related PRs

Milestone

Branch Information

  • Base Branch: main
  • Head Branch: cursor/build-error-and-timing-85ee
  • Status: Up-to-date with main, ready for merge

Related Issues

This PR addresses build errors and performance monitoring needs. Related issues may be found in the project board under the v1.3 milestone.


Type: 🐛 Bug Fix + ✨ Feature
Priority: High
Module: Core Infrastructure
Milestone: v1.3 - Quality & Polish

@cursor
Copy link

cursor bot commented Jan 7, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@benmed00 benmed00 marked this pull request as ready for review January 7, 2026 00:52
@benmed00 benmed00 added this to the v1.3 - Quality & Polish milestone Jan 9, 2026
@benmed00 benmed00 added bug Something isn't working module:species Species database priority:high High priority type:bug Bug fix type:documentation Documentation type:feature New feature type:performance Performance improvement type:testing Testing labels Jan 9, 2026
@benmed00 benmed00 self-assigned this Jan 9, 2026
benmed00 and others added 4 commits January 10, 2026 00:09
Adds a script to time the build process and sets several API routes to dynamic.

Co-authored-by: benyakoub.pro <benyakoub.pro@gmail.com>
Co-authored-by: benyakoub.pro <benyakoub.pro@gmail.com>
- Remove src/lib/pagination.test.ts (empty file)
- Remove src/lib/validation-helpers.test.ts (empty file)
- All tests now pass successfully
@benmed00 benmed00 added enhancement New feature or request type:maintenance module:core and removed type:feature New feature type:documentation Documentation type:testing Testing module:species Species database labels Jan 10, 2026
@cursor cursor bot force-pushed the cursor/build-error-and-timing-85ee branch from 246b8c5 to e61080a Compare January 10, 2026 00:10
@github-actions github-actions bot removed bug Something isn't working enhancement New feature or request labels Jan 10, 2026
@benmed00 benmed00 added bug Something isn't working enhancement New feature or request labels Jan 10, 2026
@benmed00 benmed00 merged commit 43c2e3c into main Jan 10, 2026
12 checks passed
@benmed00 benmed00 deleted the cursor/build-error-and-timing-85ee branch January 10, 2026 00:27
@benmed00 benmed00 mentioned this pull request Jan 10, 2026
16 tasks
cursor bot pushed a commit that referenced this pull request Jan 10, 2026
Build error and timing

This PR resolves build errors and introduces build performance monitoring.

## Changes

- Fixed 'Dynamic server usage' build errors by adding `export const dynamic = 'force-dynamic'` to 5 API routes
- Added build timing script (`scripts/time-build.js`) for performance monitoring
- Removed empty test files causing test failures
- Resolved merge conflicts with main branch

## Impact

- ✅ Clean builds without errors or warnings
- ✅ Build performance metrics available
- ✅ All tests passing (98/98)
- ✅ Improved developer experience

## Related

- Closes #77 - Fix Next.js build errors: Dynamic server usage warnings
- Closes #78 - Add build performance monitoring and timing
- Related to PR #76 (Performance optimizations)
- Related to PR #75 (Global search)
- Milestone: v1.3 - Quality & Polish

## Technical Details

- Files changed: 26
- Additions: +1,082
- Deletions: -712
- Commits: 4

PR #72
benmed00 added a commit that referenced this pull request Jan 10, 2026
Global entity search implementation

This PR implements global entity search and addresses critical platform priorities.

## Changes

### Global Entity Search
- Unified search API across 11 entity types (species, missions, equipment, employees, documents, publications, users, expenses, budgets, water quality, air quality, climate data)
- Real-time search UI component with debouncing and keyboard navigation
- Integrated into main header for global access

### Testing Infrastructure
- Added 98 unit and integration tests (password policy, 2FA, export utilities, API routes)
- E2E tests with Playwright (auth, search, export flows)
- Comprehensive test coverage for critical components

### Performance Optimizations
- HTTP caching on `/api/air-quality` route
- Standardized pagination utilities applied to documents and publications

### Security Enhancements
- Rate limiting on all export endpoints (Excel, PDF, CSV)
- Complete 2FA implementation with TOTP and backup codes
- Password management API with policy enforcement

### Extended Export Functionality
- New CSV export endpoint (`/api/export/csv`)
- Updated export buttons component with CSV option
- Support for water quality, air quality, and climate data exports

## Impact

- ✅ Unified search experience across all entities
- ✅ Comprehensive test coverage (98 tests)
- ✅ Improved API performance with caching
- ✅ Enhanced security with rate limiting and 2FA
- ✅ Extended export capabilities (CSV support)

## Related

- Closes #79 - Implement global entity search across all platform entities
- Closes #80 - Add comprehensive testing infrastructure (unit, integration, E2E)
- Related to PR #72 (Build error fixes - dynamic routes for search)
- Related to PR #76 (Performance optimizations)
- Milestone: v1.1 - Performance & User Experience

## Technical Details

- Files changed: 58
- Additions: +5,909
- Deletions: -1,126
- Commits: 10

PR #75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request module:core priority:high High priority type:bug Bug fix type:maintenance type:performance Performance improvement

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add build performance monitoring and timing Fix Next.js build errors: Dynamic server usage warnings

2 participants

Comments