Skip to content

fix(frontend): ns aware navigation#5024

Merged
jog1t merged 1 commit into
mainfrom
05-05-fix_frontend_ns_aware_navigation
May 15, 2026
Merged

fix(frontend): ns aware navigation#5024
jog1t merged 1 commit into
mainfrom
05-05-fix_frontend_ns_aware_navigation

Conversation

@jog1t
Copy link
Copy Markdown
Contributor

@jog1t jog1t commented May 11, 2026

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my 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
  • 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

@railway-app
Copy link
Copy Markdown

railway-app Bot commented May 11, 2026

🚅 Deployed to the rivet-pr-5024 environment in rivet-frontend

Service Status Web Updated (UTC)
kitchen-sink ❌ Build Failed (View Logs) Web May 15, 2026 at 7:40 pm
ladle 🕒 Building (View Logs) Web May 15, 2026 at 7:39 pm
frontend-cloud 🕒 Building (View Logs) Web May 15, 2026 at 7:39 pm
frontend-inspector 🕒 Building (View Logs) Web May 15, 2026 at 7:39 pm
website 😴 Sleeping (View Logs) Web May 11, 2026 at 6:54 pm
mcp-hub ✅ Success (View Logs) Web May 11, 2026 at 6:41 pm

@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5024 May 11, 2026 18:39 Destroyed
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 11, 2026

Code Review: fix(frontend): ns aware navigation (#5024)

Overview

This PR improves namespace/project switching in the frontend by preserving the user's current sub-route when switching namespaces. Instead of always resetting to the base namespace route (e.g. /ns/$namespace), the navigation now stays on the same leaf route (e.g. /ns/$namespace/actors) if the current path is already under the namespace base.


What's Good

  • The intent is sound: context-preserving navigation is a better UX than dropping the user to the namespace root on every switch.
  • The startsWith guard correctly falls back to the base route when the current path is outside the namespace subtree.

Issues and Suggestions

1. Unsafe type cast — potential mismatch between TypeScript type and runtime value

) as "/orgs/$organization/projects/$project/ns/$namespace";

The cast tells TypeScript the value is the base namespace route literal, but at runtime it may be a deeper path (e.g. /orgs/$organization/projects/$project/ns/$namespace/actors). TanStack Router uses these literals for compile-time params validation, so the cast silences errors that may be legitimate. A narrower cast to the union of all possible namespace sub-routes would be safer, or the navigate call should be typed more loosely (e.g. using any only at the call site, not on the computed value).

2. Detail-page navigation may 404 or show stale data

When a user is on a resource detail page (e.g. an actor, a specific build), the leaf fullPath will contain IDs for that resource. Switching namespaces will attempt to navigate to the same resource path in the new namespace, using the same IDs from the old namespace — those IDs almost certainly don't exist there. This will result in a 404-style error or empty state in the new namespace.

Suggested fix: only preserve the path up to the $namespace segment plus the first sub-route level (e.g. /actors, /builds), and drop any deeper dynamic segments.

3. Duplicated logic — should be extracted to a shared hook

The exact same pattern appears in both context-switcher.tsx and layout.tsx with only the namespaceBase string differing. Extracting this into a reusable hook would eliminate the duplication:

function useNamespaceAwarePath(base: string): string {
  return useMatches({
    select: (matches) => {
      const leaf = matches[matches.length - 1]?.fullPath;
      return typeof leaf === "string" && leaf.startsWith(base) ? leaf : base;
    },
  });
}

4. PR description and checklist are empty

None of the type-of-change checkboxes are filled in, no test description is provided, and the checklist is unchecked. The description also has no summary of the motivation. This makes it harder to review and audit later.


Minor Notes

  • The typeof leafFullPath === "string" guard is slightly redundant since useMatches with this selector can only return string | undefined. A direct ?? fallback (leafFullPath ?? namespaceBase) would be cleaner.
  • No tests are included. Given this is a navigation behavior change, a route-level integration test or at minimum a snapshot test covering the switcher render would help prevent regressions.

Summary

Category Assessment
Correctness Partial — detail-page navigation to a new namespace can 404
Type safety Weak — type cast hides potential mismatches
Code quality Good intent, but duplicated logic should be extracted
Tests None added
PR hygiene Description/checklist left blank

The core idea is the right fix, but the detail-page edge case and the duplicated implementation are worth addressing.

@jog1t jog1t force-pushed the 05-05-fix_frontend_ns_aware_navigation branch from f2d1963 to ded0afc Compare May 11, 2026 18:49
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5024 May 11, 2026 18:49 Destroyed
@jog1t jog1t force-pushed the 05-05-fix_frontend_navigate_only_by_using_actor_ids branch from 22e8455 to a29da76 Compare May 15, 2026 19:30
@jog1t jog1t force-pushed the 05-05-fix_frontend_ns_aware_navigation branch from ded0afc to aa332cf Compare May 15, 2026 19:30
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5024 May 15, 2026 19:30 Destroyed
@jog1t jog1t mentioned this pull request May 15, 2026
11 tasks
Copy link
Copy Markdown
Contributor Author

jog1t commented May 15, 2026

Merge activity

  • May 15, 7:36 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 15, 7:40 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 15, 7:40 PM UTC: @jog1t merged this pull request with Graphite.

@jog1t jog1t changed the base branch from 05-05-fix_frontend_navigate_only_by_using_actor_ids to graphite-base/5024 May 15, 2026 19:37
@jog1t jog1t changed the base branch from graphite-base/5024 to main May 15, 2026 19:38
@jog1t jog1t force-pushed the 05-05-fix_frontend_ns_aware_navigation branch from aa332cf to 9cf6ed3 Compare May 15, 2026 19:39
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5024 May 15, 2026 19:39 Destroyed
@jog1t jog1t merged commit 7cb8234 into main May 15, 2026
6 of 13 checks passed
@jog1t jog1t deleted the 05-05-fix_frontend_ns_aware_navigation branch May 15, 2026 19:40
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