Skip to content

Conversation

@kargig
Copy link
Owner

@kargig kargig commented Jan 1, 2026

Summary

This pull request addresses critical frontend build issues, API error handling bugs, and validation improvements. It fixes a logic bug in the API retry mechanism that prevented exponential backoff, resolves Temporal Dead Zone issues in API helpers, optimizes the frontend build process by consolidating vendor chunks, and implements lazy loading for improved initial load times. Additionally, it fixes Nginx logging configuration and adds proper prop validation to the BackgroundLogo component.

Changes Made

Frontend Architecture & Build

  • Updated Vite Configuration:
    • Consolidated all node_modules into a single vendor chunk to prevent circular dependencies and initialization order issues (e.g., "Cannot read properties of undefined (reading 'forwardRef')").
    • Added dedupe: ['react', 'react-dom'] to ensure a single instance of React is used, resolving potential useId hook errors.
  • Lazy Loading: Implemented lazy loading for routes in App.js using React.lazy and Suspense, significantly reducing the initial bundle size and improving load performance.
  • Dependencies:
    • Moved playwright to devDependencies.
    • Added prop-types dependency.

API & Error Handling

  • Fixed Retry Logic: Corrected a logic bug in frontend/src/api.js where the _gatewayRetry flag was prematurely preventing subsequent retries. This restores the intended exponential backoff behavior (1s, 2s, 4s) for 504 Gateway Timeouts and 5xx Server Errors, crucial for handling Fly.io cold starts.
  • Fixed Hoisting/TDZ Issues: Hoisted getFieldNameFromLoc and extractFieldErrors helper functions in api.js to the top of the module to prevent potential ReferenceError (Temporal Dead Zone) during module initialization.
  • Refactoring: Refactored the API interceptor error handler into cleaner helper functions (handle401Error, handleRetryableError) to reduce complexity and improve maintainability.

Components & Validation

  • BackgroundLogo: Removed unused React import and added missing PropTypes validation for opacity, size, and className.
  • Turnstile Config: Renamed siteKey variable in turnstileConfig.js to avoid potential variable name collisions during minification.

Infrastructure (Nginx)

  • Logging Fix: Commented out access_log off and log_not_found off directives in nginx/prod.conf to fix logging configuration issues in the production environment.

Testing

  • Manual Verification:
    • Verified that the application loads successfully without "ReferenceError" or initialization crashes.
    • Simulated 401 login failures to confirm extractErrorMessage correctly parses and displays error messages (e.g., "Incorrect username/email or password").
    • Confirmed that the API retry mechanism correctly attempts multiple retries on gateway errors.
  • Linting: Ran npm run lint within the divemap_frontend container to ensure all code quality issues in modified files were resolved.

Related Issues

  • Resolves build errors related to circular dependencies and React hooks (useId).
  • Fixes transient authentication failures during backend cold starts due to insufficient retry attempts.

Additional Notes

  • The lazy loading implementation requires a <Suspense> boundary, which has been added with a simple LoadingFallback component.
  • The vendor chunk strategy in Vite is a safe default for this project structure to ensure stability over granular code splitting.

- Update Vite configuration to consolidate vendor chunks and dedupe React, resolving 'useId' and circular dependency errors
- Implement lazy loading for routes in App.js to improve initial load time
- Rename 'siteKey' in turnstileConfig.js to avoid variable name collision during minification
- Move playwright to devDependencies in package.json
- Fix Nginx logging by removing 'access_log on' directive in prod.conf
@kargig kargig force-pushed the fix_frontend_build_deps branch from c5b11d0 to 25d149d Compare January 1, 2026 21:00
- Fix logic bug in API retry mechanism where `_gatewayRetry` flag
  prevented multiple retries, restoring exponential backoff behavior
- Fix Temporal Dead Zone issue by hoisting `getFieldNameFromLoc` and
  `extractFieldErrors` helpers in `api.js`
- Refactor API interceptor error handling into `handle401Error` and
  `handleRetryableError` helpers for reduced complexity
- Remove unused React import and add missing PropTypes validation in
  `BackgroundLogo.js`
- Add `prop-types` dependency to frontend package.json
@kargig kargig changed the title Fix frontend build dependencies and Nginx logging Fix frontend build dependencies, API error handling, and Nginx logging Jan 2, 2026
@kargig kargig merged commit 451b6c6 into main Jan 2, 2026
1 check passed
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.

2 participants