Skip to content

Refactor Labelary preview to support custom hosts#54

Merged
u8array merged 1 commit into
mainfrom
feat/add-labelary-premium-support
May 11, 2026
Merged

Refactor Labelary preview to support custom hosts#54
u8array merged 1 commit into
mainfrom
feat/add-labelary-premium-support

Conversation

@u8array
Copy link
Copy Markdown
Owner

@u8array u8array commented May 11, 2026

No description provided.

Update the Labelary preview functionality to allow for custom API hosts
and keys, supporting private Labelary instances. This includes changes
to the store, locale strings, and the addition of a
`isDefaultLabelaryHost` utility function. The privacy notice link has
also been updated to point to Labelary's service and pricing
information, rather than just privacy.
@u8array u8array merged commit 1bb9ac0 into main May 11, 2026
2 checks passed
@u8array u8array deleted the feat/add-labelary-premium-support branch May 11, 2026 05:56
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for custom Labelary API endpoints and API keys via environment variables, allowing the application to interface with private or metered Labelary instances. The UI has been updated to conditionally display privacy notices and attribution links only when the default public service is used. Feedback suggests optimizing performance by computing the API host and key at the module level rather than on every function call, which is particularly beneficial for frequently executed state selectors.

Comment thread src/lib/labelary.ts
Comment on lines +20 to +28
function host(): string {
const configured = trimmed(import.meta.env.VITE_LABELARY_API_URL);
if (!configured) return DEFAULT_HOST;
return configured.replace(/\/+$/, '');
}

function apiKey(): string | undefined {
return trimmed(import.meta.env.VITE_LABELARY_API_KEY);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The host() and apiKey() functions perform string operations and environment variable lookups on every call. Since these values are derived from build-time environment variables and are constant during the application's lifecycle, it is more efficient to compute them once at the module level. This is particularly relevant as host() is called via the selectLabelaryNoticeRequired Zustand selector, which may execute frequently during UI interactions (e.g., when dragging objects on the canvas).

Suggested change
function host(): string {
const configured = trimmed(import.meta.env.VITE_LABELARY_API_URL);
if (!configured) return DEFAULT_HOST;
return configured.replace(/\/+$/, '');
}
function apiKey(): string | undefined {
return trimmed(import.meta.env.VITE_LABELARY_API_KEY);
}
const API_HOST = trimmed(import.meta.env.VITE_LABELARY_API_URL)?.replace(/\/+$/, '') ?? DEFAULT_HOST;
const API_KEY = trimmed(import.meta.env.VITE_LABELARY_API_KEY);
function host(): string { return API_HOST; }
function apiKey(): string | undefined { return API_KEY; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant