Skip to content

Commit 84350b8

Browse files
committed
fix(webapp): revalidate cached regions after setting a default
The org layout caches regions for useRegions(); the set-default action redirects to the same URL, so add a shouldRevalidate hook (mirroring the pause/resume pattern) to refresh the default shown in Test/Replay.
1 parent a77df3f commit 84350b8

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

  • apps/webapp/app/routes
    • _app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.regions
    • _app.orgs.$organizationSlug

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.regions/route.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ const FormSchema = z.object({
101101
regionId: z.string(),
102102
});
103103

104+
// Lets the parent layout route revalidate its cached regions after a new
105+
// default is set — the action redirects to the same URL, so a pathname check
106+
// alone wouldn't refresh the default shown by useRegions().
107+
export function isSetDefaultRegionFormSubmission(
108+
formMethod: string | undefined,
109+
formData: FormData | undefined
110+
) {
111+
if (!formMethod || !formData) {
112+
return false;
113+
}
114+
115+
return formMethod.toLowerCase() === "post" && formData.has("regionId");
116+
}
117+
104118
export const action = async ({ request, params }: ActionFunctionArgs) => {
105119
const user = await requireUser(request);
106120
const { organizationSlug, projectParam, envParam } = EnvironmentParamSchema.parse(params);

apps/webapp/app/routes/_app.orgs.$organizationSlug/route.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { requireUser } from "~/services/session.server";
1414
import { telemetry } from "~/services/telemetry.server";
1515
import { organizationPath } from "~/utils/pathBuilder";
1616
import { isEnvironmentPauseResumeFormSubmission } from "../_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.queues/route";
17+
import { isSetDefaultRegionFormSubmission } from "../_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.regions/route";
1718

1819
const ParamsSchema = z.object({
1920
organizationSlug: z.string(),
@@ -53,6 +54,11 @@ export const shouldRevalidate: ShouldRevalidateFunction = (params) => {
5354
return true;
5455
}
5556

57+
// Invalidate so useRegions() reflects a newly set default region
58+
if (isSetDefaultRegionFormSubmission(params.formMethod, params.formData)) {
59+
return true;
60+
}
61+
5662
// This prevents revalidation when there are search params changes
5763
// IMPORTANT: If the loader function depends on search params, this should be updated
5864
return params.currentUrl.pathname !== params.nextUrl.pathname;

0 commit comments

Comments
 (0)