Skip to content

fix(frontend): CSR builds were missing env vars due to import.meta.env not being used - #657

Merged
daveearley merged 3 commits into
HiEventsDev:developfrom
carlosalaniz:fix/config-type-definition
Jul 23, 2025
Merged

fix(frontend): CSR builds were missing env vars due to import.meta.env not being used#657
daveearley merged 3 commits into
HiEventsDev:developfrom
carlosalaniz:fix/config-type-definition

Conversation

@carlosalaniz

Copy link
Copy Markdown
Contributor

refactor(frontend): Replace string-based ConfigKeys with a strict union type and update usages
fix(frontend): Ensure Vite CSR builds correctly receive env variables via import.meta.env

  • Defined ConfigKeys as a strict union type (no more string fallback).

  • Added clientBuildEnv with all keys from ConfigKeys, populated via import.meta.env.

  • Updated getConfig() to resolve environment variables in the following order:

    • process.env during SSR
    • window.hievents when injected
    • clientBuildEnv during CSR
    • a provided fallback

Prior to this change, the app relied on window.hievents to access environment variables at runtime. That worked fine for SSR deployments (which most of ours are), since the server injects window.hievents into the rendered HTML.

However, in CSR builds, environment variables like import.meta.env.VITE_* are injected at build time and are not preserved in the runtime global scope (i.e., not available on window). This caused CSR builds to silently break — wrong base URLs, missing logos, broken colors, and failing third-party integrations.

This update ensures that both SSR and CSR builds correctly load the expected environment config, restoring reliability and consistency across deployment types.

…on type and update usages

- Defined `ConfigKeys` as a union type for better type safety and clarity.
- Updated `clientBuildEnv` to include all keys from `ConfigKeys`.
- Enhanced `getConfig` to utilize `clientBuildEnv` for client-side environment variable access.

@daveearley daveearley left a comment

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.

Thank you, @carlosalaniz!

I can test this later today

Comment thread frontend/src/utilites/config.ts Outdated
Co-authored-by: Dave Earley <dave.m.earley@gmail.com>
@carlosalaniz
carlosalaniz requested a review from daveearley June 30, 2025 02:55

@daveearley daveearley left a comment

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.

Thank you!

@daveearley
daveearley merged commit 0114795 into HiEventsDev:develop Jul 23, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants