From 333b812c8274cb9d577f1ddcdee9a6ceaaf3f6e2 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Tue, 27 May 2025 17:12:46 -0700 Subject: [PATCH 1/2] fix: initialize regions store as empty ConsoleRegionList Using undefined as the initial value can lead to issues when trying to access the store such as: TypeError: Cannot read properties of undefined (reading 'regions') --- src/lib/stores/organization.ts | 2 +- src/routes/(console)/regions.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/stores/organization.ts b/src/lib/stores/organization.ts index 6f22cbc96a..9ae54ea27f 100644 --- a/src/lib/stores/organization.ts +++ b/src/lib/stores/organization.ts @@ -61,4 +61,4 @@ export const organization = derived(page, ($page) => $page.data?.organization as export const currentPlan = derived(page, ($page) => $page.data?.currentPlan as Plan); export const members = derived(page, ($page) => $page.data.members as Models.MembershipList); -export const regions = writable(undefined); +export const regions = writable({ total: 0, regions: [] }); diff --git a/src/routes/(console)/regions.ts b/src/routes/(console)/regions.ts index 0ac4d4304c..b9e8633672 100644 --- a/src/routes/(console)/regions.ts +++ b/src/routes/(console)/regions.ts @@ -16,7 +16,7 @@ export async function loadAvailableRegions(orgId: string): Promise { try { const storedRegions = get(regions); - if (storedRegions?.regions && lastLoadedOrganization === orgId) { + if (storedRegions.regions && lastLoadedOrganization === orgId) { // already loaded for this organization, fast path return. return; } From e4c66b13f81283c8ec674f554c291c6b77011339 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Tue, 27 May 2025 17:15:21 -0700 Subject: [PATCH 2/2] chore: remove unnecessary regions fetch The regions store is populated elsewhere already so no need to do it again here. Also, $organization may not be defined on mount which would lead to: TypeError: Cannot read properties of undefined (reading '$id') --- .../(console)/organization-[organization]/+page.svelte | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/routes/(console)/organization-[organization]/+page.svelte b/src/routes/(console)/organization-[organization]/+page.svelte index 089351e324..19090c22a4 100644 --- a/src/routes/(console)/organization-[organization]/+page.svelte +++ b/src/routes/(console)/organization-[organization]/+page.svelte @@ -38,7 +38,7 @@ } from '@appwrite.io/pink-icons-svelte'; import { getPlatformInfo } from '$lib/helpers/platform'; import CreateProjectCloud from './createProjectCloud.svelte'; - import { organization, regions as regionsStore } from '$lib/stores/organization'; + import { regions as regionsStore } from '$lib/stores/organization'; export let data; @@ -112,15 +112,11 @@ } }; onMount(async () => { - if (isCloud && $organization.$id) { - const regions = await sdk.forConsole.billing.listRegions($organization.$id); - regionsStore.set(regions); - checkPricingRefAndRedirect(page.url.searchParams); - } + checkPricingRefAndRedirect(page.url.searchParams); }); function findRegion(project: Models.Project) { - return $regionsStore?.regions?.find((region) => region.$id === project.region); + return $regionsStore.regions.find((region) => region.$id === project.region); }