From be126f9f9367ae39dc4ea0dc9934384b4c534bd6 Mon Sep 17 00:00:00 2001 From: myftija Date: Wed, 24 Sep 2025 14:50:37 +0200 Subject: [PATCH 1/2] fix(webapp): toast message issue after gh app installation Fixes an issue with displaying toasts messages in the project settings page. The github callback cookie was interfering with the flash cookie used for toast messages. --- .../app/routes/_app.github.callback/route.tsx | 34 ++--------- .../route.tsx | 58 ++++++++----------- 2 files changed, 29 insertions(+), 63 deletions(-) diff --git a/apps/webapp/app/routes/_app.github.callback/route.tsx b/apps/webapp/app/routes/_app.github.callback/route.tsx index 44d9d96b68..44c7f37c13 100644 --- a/apps/webapp/app/routes/_app.github.callback/route.tsx +++ b/apps/webapp/app/routes/_app.github.callback/route.tsx @@ -1,13 +1,9 @@ -import { type LoaderFunctionArgs, redirect } from "@remix-run/node"; +import { type LoaderFunctionArgs } from "@remix-run/node"; import { z } from "zod"; import { validateGitHubAppInstallSession } from "~/services/gitHubSession.server"; import { linkGitHubAppInstallation, updateGitHubAppInstallation } from "~/services/gitHub.server"; import { logger } from "~/services/logger.server"; -import { - redirectWithErrorMessage, - setRequestSuccessMessage, - commitSession, -} from "~/models/message.server"; +import { redirectWithErrorMessage, redirectWithSuccessMessage } from "~/models/message.server"; import { tryCatch } from "@trigger.dev/core"; import { $replica } from "~/db.server"; import { requireUser } from "~/services/session.server"; @@ -92,14 +88,7 @@ export async function loader({ request }: LoaderFunctionArgs) { return redirectWithErrorMessage(redirectTo, request, "Failed to install GitHub App"); } - const session = await setRequestSuccessMessage(request, "GitHub App installed successfully"); - session.flash("gitHubAppInstalled", true); - - return redirect(redirectTo, { - headers: { - "Set-Cookie": await commitSession(session), - }, - }); + return redirectWithSuccessMessage(redirectTo, request, "GitHub App installed successfully"); } case "update": { @@ -112,14 +101,7 @@ export async function loader({ request }: LoaderFunctionArgs) { return redirectWithErrorMessage(redirectTo, request, "Failed to update GitHub App"); } - const session = await setRequestSuccessMessage(request, "GitHub App updated successfully"); - session.flash("gitHubAppInstalled", true); - - return redirect(redirectTo, { - headers: { - "Set-Cookie": await commitSession(session), - }, - }); + return redirectWithSuccessMessage(redirectTo, request, "GitHub App updated successfully"); } case "request": { @@ -129,13 +111,7 @@ export async function loader({ request }: LoaderFunctionArgs) { callbackData, }); - const session = await setRequestSuccessMessage(request, "GitHub App installation requested"); - - return redirect(redirectTo, { - headers: { - "Set-Cookie": await commitSession(session), - }, - }); + return redirectWithSuccessMessage(redirectTo, request, "GitHub App installation requested"); } default: diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.settings/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.settings/route.tsx index d826c986d9..1ba5f26407 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.settings/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.settings/route.tsx @@ -14,6 +14,7 @@ import { useActionData, useNavigation, useNavigate, + useSearchParams, } from "@remix-run/react"; import { type ActionFunction, type LoaderFunctionArgs, json } from "@remix-run/server-runtime"; import { typedjson, useTypedLoaderData } from "remix-typedjson"; @@ -49,8 +50,6 @@ import { redirectBackWithSuccessMessage, redirectWithErrorMessage, redirectWithSuccessMessage, - getSession, - commitSession, } from "~/models/message.server"; import { ProjectSettingsService } from "~/services/projectSettings.server"; import { logger } from "~/services/logger.server"; @@ -123,22 +122,12 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => { const { gitHubApp, buildSettings } = resultOrFail.value; - const session = await getSession(request.headers.get("Cookie")); - const openGitHubRepoConnectionModal = session.get("gitHubAppInstalled") === true; - const headers = new Headers({ - "Set-Cookie": await commitSession(session), + return typedjson({ + githubAppEnabled: gitHubApp.enabled, + githubAppInstallations: gitHubApp.installations, + connectedGithubRepository: gitHubApp.connectedRepository, + buildSettings, }); - - return typedjson( - { - githubAppEnabled: gitHubApp.enabled, - githubAppInstallations: gitHubApp.installations, - connectedGithubRepository: gitHubApp.connectedRepository, - openGitHubRepoConnectionModal, - buildSettings, - }, - { headers } - ); }; const ConnectGitHubRepoFormSchema = z.object({ @@ -444,13 +433,8 @@ export const action: ActionFunction = async ({ request, params }) => { }; export default function Page() { - const { - githubAppInstallations, - connectedGithubRepository, - githubAppEnabled, - openGitHubRepoConnectionModal, - buildSettings, - } = useTypedLoaderData(); + const { githubAppInstallations, connectedGithubRepository, githubAppEnabled, buildSettings } = + useTypedLoaderData(); const project = useProject(); const organization = useOrganization(); const environment = useEnvironment(); @@ -584,7 +568,6 @@ export default function Page() { organizationSlug={organization.slug} projectSlug={project.slug} environmentSlug={environment.slug} - openGitHubRepoConnectionModal={openGitHubRepoConnectionModal} /> )} @@ -667,7 +650,6 @@ function ConnectGitHubRepoModal({ organizationSlug, projectSlug, environmentSlug, - open = false, }: { gitHubAppInstallations: GitHubAppInstallation[]; organizationSlug: string; @@ -675,7 +657,7 @@ function ConnectGitHubRepoModal({ environmentSlug: string; open?: boolean; }) { - const [isModalOpen, setIsModalOpen] = useState(open); + const [isModalOpen, setIsModalOpen] = useState(false); const lastSubmission = useActionData() as any; const navigate = useNavigate(); @@ -703,6 +685,17 @@ function ConnectGitHubRepoModal({ }, }); + const [searchParams, setSearchParams] = useSearchParams(); + useEffect(() => { + const params = new URLSearchParams(searchParams); + + if (params.get("openGithubRepoModal") === "1") { + setIsModalOpen(true); + params.delete("openGithubRepoModal"); + setSearchParams(params); + } + }, [searchParams, setSearchParams]); + useEffect(() => { if (lastSubmission && "success" in lastSubmission && lastSubmission.success === true) { setIsModalOpen(false); @@ -759,11 +752,11 @@ function ConnectGitHubRepoModal({ navigate( githubAppInstallPath( organizationSlug, - v3ProjectSettingsPath( + `${v3ProjectSettingsPath( { slug: organizationSlug }, { slug: projectSlug }, { slug: environmentSlug } - ) + )}?openGithubRepoModal=1` ) ); }} @@ -856,13 +849,11 @@ function GitHubConnectionPrompt({ organizationSlug, projectSlug, environmentSlug, - openGitHubRepoConnectionModal = false, }: { gitHubAppInstallations: GitHubAppInstallation[]; organizationSlug: string; projectSlug: string; environmentSlug: string; - openGitHubRepoConnectionModal?: boolean; }) { return (
@@ -871,11 +862,11 @@ function GitHubConnectionPrompt({ GitHub app is installed From 0f1c7b7062e3efd1652b1a7fbee1936e6d210317 Mon Sep 17 00:00:00 2001 From: myftija Date: Wed, 24 Sep 2025 14:53:07 +0200 Subject: [PATCH 2/2] Do not set a tracking branch in the staging env by default --- apps/webapp/app/services/projectSettings.server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/webapp/app/services/projectSettings.server.ts b/apps/webapp/app/services/projectSettings.server.ts index 8f5195e985..93d05c1f89 100644 --- a/apps/webapp/app/services/projectSettings.server.ts +++ b/apps/webapp/app/services/projectSettings.server.ts @@ -90,7 +90,7 @@ export class ProjectSettingsService { repositoryId: repositoryId, branchTracking: { prod: { branch: defaultBranch }, - staging: { branch: defaultBranch }, + staging: {}, } satisfies BranchTrackingConfig, previewDeploymentsEnabled: true, },