Skip to content

Conversation

@Ontiomacer
Copy link

@Ontiomacer Ontiomacer commented Dec 30, 2025

Proposed change

Resolves l3montree-dev/devguard #1472
l3montree-dev/devguard#1472

This PR fixes a frontend redirect issue where clicking a repository assumed a
main branch exists and redirected to /refs/main, causing a 500 error when
no default branch or refs are present.

Summary of changes

  • Removed hardcoded main branch fallback
  • Redirects now resolve in the following order:
    • repository.defaultBranch (if available)
    • first available branch
    • first available tag
  • If no refs exist, redirect is skipped entirely
  • Prevents invalid /refs/main URLs from being constructed

Testing

  • Reproduced the issue locally
  • Verified redirect logic no longer assumes a default branch
  • Full end-to-end auth testing is limited locally due to Kratos requirements

@Ontiomacer
Copy link
Author

Hi @Hubtrick-Git ,

I’ve opened a pull request in the devguard-web repository implementing the discussed fix.
The redirect logic now resolves refs in a safe order and skips redirecting entirely if none are available, preventing the 500 error.

Please let me know if any adjustments are needed.

@refoo0
Copy link
Collaborator

refoo0 commented Jan 7, 2026

Hello Ontiomacer,

Thank you very much for your pull request! 😊

I looked into the changes, and it seems that the function maybeGetRedirectDestination in server.ts is actually deprecated and no longer used. Unfortunately, the bug still exists. You can reproduce it like this:

  1. Select an asset version with a URL like:
    http://localhost:3000/org/projects/pro/assets/repo/refs/main
  2. Delete the asset version main here:
    http://localhost:3000/org/projects/pro/assets/repo/refs
  3. Click on the repository name → you will get a 500 error

As I mentioned, the function you updated is not being used anymore. The fix should happen in AssetTitle, because the assetVersionSlug is stored in the session there. The problem occurs when an asset version is deleted, but the session value is not updated.

A possible solution would be:

  • In the handleDeleteRef function, check if the deleted assetVersionSlug matches the one stored in the session. If it does, remove it from the session.
  • Also, in AssetTitle, check if the assetVersionSlug is undefined. If so, update the link to:
    / ${activeOrg?.slug}/projects/${project?.slug}/assets/${asset?.slug}

Additionally, the changes in fetchOrg are not necessary for this bug. If you were aiming for something else with those, please let me know.

Please feel free to reach out if you have any questions or want to discuss this further!

@Ontiomacer
Copy link
Author

Ontiomacer commented Jan 9, 2026

Thanks @refoo0 for the detailed review and for pointing this out

You’re right: maybeGetRedirectDestination is deprecated and no longer part of the active redirect flow, so the changes I made there don’t address the actual failure path. Thanks for clarifying the correct reproduction steps as well.

I understand now that the root cause is the stale assetVersionSlug stored in the session when a ref is deleted, and that the fix needs to happen in:

  • handleDeleteRef, to clear the session value if the deleted ref matches it, and
  • AssetTitle, to handle an undefined assetVersionSlug by linking to the asset root instead of /refs/.

Given this, I propose to:

  • Drop the current redirect-related changes (including fetchOrg, which I agree is unrelated), and
  • Update this PR with a focused fix in handleDeleteRef and AssetTitle as described — unless you’d prefer that I close this PR and open a new, cleaner one targeting only that logic.

Please let me know which you’d prefer. Happy to adjust accordingly.

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