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
11 changes: 8 additions & 3 deletions src/lib/components/billing/alerts/realtimePricing.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
}
}
$: href = $currentPlan?.usagePerProject
? `${base}/organization-${$organization.$id}/billing`
: `${base}/organization-${$organization.$id}/usage`;
// Guard org id: this reactive runs even when the {#if} below is false, so optional
// chaining on $currentPlan alone is not enough — $organization can be undefined.
$: orgId = $organization?.$id;
$: href = orgId
? $currentPlan?.usagePerProject
? `${base}/organization-${orgId}/billing`
: `${base}/organization-${orgId}/usage`
: '';
Comment on lines +21 to +26
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Unnecessary intermediate reactive variable

The extra $: orgId = $organization?.$id reactive declaration adds a second reactive dependency chain where one is sufficient. Since orgId is used only inside the href expression, you can inline the guard directly:

Suggested change
$: orgId = $organization?.$id;
$: href = orgId
? $currentPlan?.usagePerProject
? `${base}/organization-${orgId}/billing`
: `${base}/organization-${orgId}/usage`
: '';
$: href = $organization?.$id
? $currentPlan?.usagePerProject
? `${base}/organization-${$organization.$id}/billing`
: `${base}/organization-${$organization.$id}/usage`
: '';

This achieves the same crash protection with one fewer reactive declaration, and keeps the intent clear: href is empty when the org is not loaded.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

</script>

{#if $organization?.$id && !dismissed}
Expand Down
Loading