File tree Expand file tree Collapse file tree
_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.regions
_app.orgs.$organizationSlug Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
104118export const action = async ( { request, params } : ActionFunctionArgs ) => {
105119 const user = await requireUser ( request ) ;
106120 const { organizationSlug, projectParam, envParam } = EnvironmentParamSchema . parse ( params ) ;
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { requireUser } from "~/services/session.server";
1414import { telemetry } from "~/services/telemetry.server" ;
1515import { organizationPath } from "~/utils/pathBuilder" ;
1616import { 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
1819const 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 ;
You can’t perform that action at this time.
0 commit comments