Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions static/app/views/preprod/redirects/legacyUrlRedirect.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {useEffect} from 'react';

import ConfigStore from 'sentry/stores/configStore';
import {useLocation} from 'sentry/utils/useLocation';
import {useNavigate} from 'sentry/utils/useNavigate';
import useOrganization from 'sentry/utils/useOrganization';
import {useParams} from 'sentry/utils/useParams';
import useProjectFromSlug from 'sentry/utils/useProjectFromSlug';

export default function LegacyPreprodRedirect() {
const params = useParams<{
Expand All @@ -15,31 +17,40 @@ export default function LegacyPreprodRedirect() {
const navigate = useNavigate();
const organization = useOrganization();
const location = useLocation();
const project = useProjectFromSlug({organization, projectSlug: params.projectId});

useEffect(() => {
const {projectId, artifactId, headArtifactId, baseArtifactId} = params;
if (!project) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Invalid project slugs cause blank page forever

Medium Severity

The early return when !project blocks redirects for invalid or inaccessible project slugs. Previously, the redirect always executed, letting the destination page handle errors. Now, if useProjectFromSlug returns undefined permanently (invalid slug, deleted project, or no access), no redirect occurs and the component renders null, leaving users stuck on a blank page with no feedback.

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine. We're going to kill this redirect shortly anyway.


const {artifactId, headArtifactId, baseArtifactId} = params;
const numericProjectId = project.id;
const isInstall = location.pathname.includes('/install/');
const isCompare = location.pathname.includes('/compare/');

const {customerDomain} = ConfigStore.getState();
const orgPrefix = customerDomain ? '' : `/organizations/${organization.slug}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok this should work but I'm not sure how to test this customerDomain logic locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

Which side of the logic are you not able to test?


let newPath = '';

if (isCompare && headArtifactId) {
const compareType = 'size';
if (baseArtifactId) {
newPath = `/organizations/${organization.slug}/preprod/${compareType}/compare/${headArtifactId}/${baseArtifactId}/?project=${projectId}`;
newPath = `${orgPrefix}/preprod/${compareType}/compare/${headArtifactId}/${baseArtifactId}/?project=${numericProjectId}`;
} else {
newPath = `/organizations/${organization.slug}/preprod/${compareType}/compare/${headArtifactId}/?project=${projectId}`;
newPath = `${orgPrefix}/preprod/${compareType}/compare/${headArtifactId}/?project=${numericProjectId}`;
}
} else if (isInstall && artifactId) {
newPath = `/organizations/${organization.slug}/preprod/install/${artifactId}/?project=${projectId}`;
newPath = `${orgPrefix}/preprod/install/${artifactId}/?project=${numericProjectId}`;
} else if (artifactId) {
newPath = `/organizations/${organization.slug}/preprod/size/${artifactId}/?project=${projectId}`;
newPath = `${orgPrefix}/preprod/size/${artifactId}/?project=${numericProjectId}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Query parameter changed from slug to numeric ID

Medium Severity

The project query parameter in redirect URLs now uses numericProjectId (from project.id) instead of the original slug from params.projectId. This contradicts the PR description which shows the query parameter should remain as the slug (e.g., ?project=launchpad-test-ios). The code should continue using params.projectId for the query parameter to maintain consistency with the stated behavior and existing patterns in the codebase.

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

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

(I updated)

}

if (newPath) {
navigate(newPath, {replace: true});
}
}, [params, navigate, organization, location]);
}, [params, navigate, organization, location, project]);

return null;
}
Loading