Skip to content

Conversation

@devksingh4
Copy link
Member

@devksingh4 devksingh4 commented Nov 5, 2025

Summary by CodeRabbit

  • New Features

    • Added a unified, user-friendly error page for displaying route errors and details.
  • Bug Fixes

    • Semester selector now validates and syncs with the URL, updating only when the selection actually changes.
    • Cleaner room requests view: redundant loading indicator removed and existing requests shown only when a semester is selected.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Refactors RoomRequestLanding state/URL semester sync (adds memoization, tightens setSemester updates, removes Loader), reworks Router to use a centralized ErrorPage via router errorElement (removes inline ErrorBoundary), and adds a new ErrorPage component that renders route errors in the app shell.

Changes

Cohort / File(s) Summary
Room Request Landing Page Refactor
src/ui/pages/roomRequest/RoomRequestLanding.page.tsx
Added useMemo for nextSemesters and semesterOptions; removed Mantine Loader and loading state; changed setSemester to update state and URL only when non-null and different; tightened URL-to-state sync on mount/update (validates URL semester, defaults to first nextSemester when absent/invalid); added semester and setSearchParams to effect deps; corrected typo semeseterFromUrlsemesterFromUrl; render now conditionally shows ExistingRoomRequests only when semester present.
Router restructuring (error handling & routes)
src/ui/Router.tsx
Replaced per-route inline ErrorBoundary usage with errorElement: <ErrorPage /> on routers; nested routes as children under these errorElement wrappers and consolidated authenticated routes; removed ErrorBoundary component and ErrorBoundaryProps interface; removed related state/effects/imports and swapped Error500Page usage for centralized ErrorPage.
New centralized Error page
src/ui/pages/Error.page.tsx
Added ErrorPage component exporting ErrorPage: React.FC that reads route error via useRouteError, renders inside AcmAppShell using Mantine components, and displays an accordion with expandable error details (stack/message) in a styled card.

Sequence Diagram(s)

sequenceDiagram
    participant Component as RoomRequestLanding
    participant URL as BrowserURL
    participant State as LocalState
    participant Select as SemesterSelect

    Note over Component,URL: Semester sync on mount/update
    Component->>URL: read semester param
    URL-->>Component: semester (or none)
    Component->>State: validate semester against nextSemesters
    alt valid
        Component->>State: set semester
    else invalid or missing
        Component->>State: set default semester (first nextSemester)
        Component->>URL: push default semester to URL
    end
    Component->>Select: render with selected semester

    Note over Select,Component: User changes selection
    Select->>Component: onChange(newSemester)
    Component->>Component: setSemester(newSemester)
    alt newSemester non-null && different
        Component->>State: update semester
        Component->>URL: update URL param
    else skip
    end
Loading
sequenceDiagram
    participant RouterOld as Router (old)
    participant RouterNew as Router (new)
    participant ErrorBoundary as ErrorBoundary
    participant ErrorPage as ErrorPage

    Note over RouterOld: Previous flow
    RouterOld->>ErrorBoundary: render per-route ErrorBoundary wrapping routes
    ErrorBoundary->>RouterOld: catch/render errors inline

    Note over RouterNew: New flow
    RouterNew->>ErrorPage: provide errorElement for routers
    RouterNew->>Children: render child routes under errorElement
    ErrorPage->>RouterNew: handle route errors via useRouteError
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect setSemester and URL sync in RoomRequestLanding.page.tsx for edge cases and potential state-effect loops.
  • Verify useMemo usage is correct and memo deps cover derived lists.
  • Confirm all routes remain reachable after moving to errorElement and that centralized ErrorPage presents expected data without exposing sensitive stacks.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix crash when clicking back on room requests' is specific and clearly describes the main issue being addressed, though the detailed changes extend beyond just the room request crash to include broader error handling refactoring.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between bffb9da and 55237aa.

📒 Files selected for processing (1)
  • src/ui/pages/roomRequest/RoomRequestLanding.page.tsx (4 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

💰 Infracost report

Monthly estimate generated

This comment will be updated when code changes.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 09edf61 and 3f8ef8f.

📒 Files selected for processing (1)
  • src/ui/pages/roomRequest/RoomRequestLanding.page.tsx (4 hunks)
🧰 Additional context used
🪛 GitHub Actions: Required Reviews
src/ui/pages/roomRequest/RoomRequestLanding.page.tsx

[error] 1-1: Requirement 'Base Requirement' is not satisfied by the existing reviews.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Run Unit Tests
  • GitHub Check: Build Application
🔇 Additional comments (3)
src/ui/pages/roomRequest/RoomRequestLanding.page.tsx (3)

2-2: LGTM - Import cleanup consistent with loading state removal.

The removal of Loader from imports is consistent with the simplified conditional rendering logic.


26-31: Verify null handling behavior.

The function silently ignores null values. If the Select component allows users to clear their selection (returning null), this will prevent deselection. Confirm this is the intended behavior.


93-110: LGTM - Cleaner conditional rendering.

The simplified rendering logic is an improvement. The Select directly uses setSemester as its onChange handler, and ExistingRoomRequests only renders when a valid semester is selected. This eliminates the need for loading states and extra conditional nesting.

@devksingh4 devksingh4 merged commit 1a9f8ef into main Nov 5, 2025
8 of 9 checks passed
@devksingh4 devksingh4 deleted the dsingh14/fix-rr-crash branch November 5, 2025 16:23
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 3f8ef8f and bffb9da.

📒 Files selected for processing (2)
  • src/ui/Router.tsx (3 hunks)
  • src/ui/pages/Error.page.tsx (1 hunks)
🧰 Additional context used
🪛 ESLint
src/ui/pages/Error.page.tsx

[error] 1-1: Resolve error: EACCES: permission denied, open '/LKvPAfUvBj'
at Object.writeFileSync (node:fs:2409:20)
at l (/home/jailuser/git/node_modules/get-tsconfig/dist/index.cjs:7:13685)
at createFilesMatcher (/home/jailuser/git/node_modules/get-tsconfig/dist/index.cjs:7:14437)
at Object.resolve (/home/jailuser/git/node_modules/eslint-import-resolver-typescript/lib/index.cjs:298:107)
at withResolver (/home/jailuser/git/node_modules/eslint-module-utils/resolve.js:180:23)
at fullResolve (/home/jailuser/git/node_modules/eslint-module-utils/resolve.js:201:22)
at relative (/home/jailuser/git/node_modules/eslint-module-utils/resolve.js:217:10)
at resolve (/home/jailuser/git/node_modules/eslint-module-utils/resolve.js:233:12)
at checkFileExtension (/home/jailuser/git/node_modules/eslint-plugin-import/lib/rules/extensions.js:205:53)
at checkSourceValue (/home/jailuser/git/node_modules/eslint-module-utils/moduleVisitor.js:32:5)

(import/extensions)

src/ui/Router.tsx

[error] 1-1: Resolve error: EACCES: permission denied, open '/TIJlfcsNoU'
at Object.writeFileSync (node:fs:2409:20)
at l (/home/jailuser/git/node_modules/get-tsconfig/dist/index.cjs:7:13685)
at createFilesMatcher (/home/jailuser/git/node_modules/get-tsconfig/dist/index.cjs:7:14437)
at Object.resolve (/home/jailuser/git/node_modules/eslint-import-resolver-typescript/lib/index.cjs:298:107)
at withResolver (/home/jailuser/git/node_modules/eslint-module-utils/resolve.js:180:23)
at fullResolve (/home/jailuser/git/node_modules/eslint-module-utils/resolve.js:201:22)
at relative (/home/jailuser/git/node_modules/eslint-module-utils/resolve.js:217:10)
at resolve (/home/jailuser/git/node_modules/eslint-module-utils/resolve.js:233:12)
at checkFileExtension (/home/jailuser/git/node_modules/eslint-plugin-import/lib/rules/extensions.js:205:53)
at checkSourceValue (/home/jailuser/git/node_modules/eslint-module-utils/moduleVisitor.js:32:5)

(import/extensions)


[error] 8-8: Missing file extension for "./components/AuthContext"

(import/extensions)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build Application
  • GitHub Check: Run Unit Tests
🔇 Additional comments (4)
src/ui/Router.tsx (4)

97-113: LGTM!

The profileRouter correctly uses the centralized ErrorPage via errorElement and properly structures routes as nested children.


115-135: LGTM!

The unauthenticatedRouter correctly uses the centralized ErrorPage and properly handles unauthenticated user routing.


155-236: LGTM!

The authenticated routes are well-organized and comprehensive, with proper 404 handling via the catch-all route.


240-249: LGTM!

The main Router component correctly selects the appropriate router based on authentication state and cleanly renders the RouterProvider.

Comment on lines +6 to +7
export const ErrorPage: React.FC = () => {
const error = useRouteError() as Error;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Unsafe type assertion can cause runtime errors.

useRouteError() returns unknown and can be an Error, Response, or any thrown value. The as Error assertion is unsafe and will fail at line 25 when accessing .stack or .message if the error is a Response (e.g., from a loader/action) or another type.

Apply this diff to handle different error types safely:

-export const ErrorPage: React.FC = () => {
-  const error = useRouteError() as Error;
+export const ErrorPage: React.FC = () => {
+  const routeError = useRouteError();
+  
+  let errorMessage: string;
+  let errorStack: string | undefined;
+  
+  if (routeError instanceof Error) {
+    errorMessage = routeError.message;
+    errorStack = routeError.stack;
+  } else if (typeof routeError === 'string') {
+    errorMessage = routeError;
+  } else if (routeError && typeof routeError === 'object' && 'statusText' in routeError) {
+    // Handle Response objects
+    errorMessage = (routeError as { statusText?: string; status?: number }).statusText || 'Unknown error';
+  } else {
+    errorMessage = 'An unknown error occurred';
+  }

Then update line 25 to use the safe variables:

-                    <pre>{error.stack || error.message}</pre>
+                    <pre>{errorStack || errorMessage}</pre>

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/ui/pages/Error.page.tsx around lines 6-7, the code unsafely asserts
useRouteError() as Error which can be Response, string, or other thrown values
and will crash when accessing .message or .stack; change to narrow the unknown
safely by detecting types: if error is an instance of Response handle
status/text, if it's an instance of Error extract message and stack, if it's a
string use it as the message, otherwise provide a generic message; assign safe
variables (e.g., const message = ...; const stack = ...;) and use those
variables at line 25 instead of directly using error.message/error.stack.

Comment on lines +142 to +154
...commonRoutes,
{
path: "/",
element: <Navigate to="/home" replace />,
},
{
path: "/login",
element: <LoginPage />,
},
{
path: "/logout",
element: <LogoutPage />,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove duplicate /logout route.

The /logout route is already included in commonRoutes (lines 84-86) which are spread at line 142. The explicit definition at lines 152-154 is redundant.

Apply this diff to remove the duplicate:

       ...commonRoutes,
       {
         path: "/",
         element: <Navigate to="/home" replace />,
       },
       {
         path: "/login",
         element: <LoginPage />,
       },
-      {
-        path: "/logout",
-        element: <LogoutPage />,
-      },
       {
         path: "/profile",
         element: <ManageProfilePage />,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
...commonRoutes,
{
path: "/",
element: <Navigate to="/home" replace />,
},
{
path: "/login",
element: <LoginPage />,
},
{
path: "/logout",
element: <LogoutPage />,
},
...commonRoutes,
{
path: "/",
element: <Navigate to="/home" replace />,
},
{
path: "/login",
element: <LoginPage />,
},
🤖 Prompt for AI Agents
In src/ui/Router.tsx around lines 142 to 154, there is a duplicate /logout
route: commonRoutes (spread at ~line 142) already includes /logout (lines
84-86), and an explicit /logout route is again defined at lines 152-154; remove
the explicit route block for path "/logout" (the object with path "/logout" and
element <LogoutPage />) so the router only relies on the entry provided by
commonRoutes, keeping all other route entries ("/", "/login", etc.) unchanged.

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