Repository navigation
Vite runtime varables add default values for backward compatibility - #166
Conversation
VITE_runtime_var and mcp-protocol-version header
Avoid double slash Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Consider adding a loading indicator or fallback UI while fetchRuntimeConfig is in flight to avoid showing a blank screen before the app renders. Remove or conditionally suppress the console.log calls in fetchRuntimeConfig so debug output doesn’t clutter production logs. Instead of declaring window.RUNTIME_CONFIG as any, define and use a proper TypeScript interface for the runtime config to improve type safety.
Add default values for backward compatibility Remove build parameter from all in one dockerfile
Reviewer's GuideIntroduces a client-side runtime configuration system with defaults for backward compatibility, removes build-time VITE variables from Dockerfiles, and updates various components and services to consume the new runtime config while adding header support and static asset typings. Sequence diagram for frontend runtime config loading and app renderingsequenceDiagram
actor User
participant Browser
participant FrontendApp as React App
participant API as /api/runtime-config
User->>Browser: Load web page
Browser->>FrontendApp: Execute main.tsx
FrontendApp->>API: GET /api/runtime-config
API-->>FrontendApp: Return runtime config JSON
FrontendApp->>Browser: Merge config with defaults
FrontendApp->>Browser: Set window.RUNTIME_CONFIG
FrontendApp->>Browser: Render main React app
Browser->>User: Show application UI
Class diagram for new and updated runtime config typesclassDiagram
class RuntimeConfig {
+string apiBaseUrl
+boolean debugMode
+string version
+features: Features
+[key: string]: any
}
class Features {
+boolean enableExperimental
+[key: string]: boolean
}
class Window {
+RuntimeConfig RUNTIME_CONFIG
}
RuntimeConfig o-- Features
Window --> RuntimeConfig : RUNTIME_CONFIG
Class diagram for new LoadingScreen componentclassDiagram
class LoadingScreen {
<<React.FC>>
+render(): JSX.Element
}
Class diagram for static asset type declarationsclassDiagram
class PNGModule {
+string default
}
class JPGModule {
+string default
}
class JPEGModule {
+string default
}
class SVGModule {
+string default
}
class GIFModule {
+string default
}
Class diagram for updated ImportMetaEnv typeclassDiagram
class ImportMetaEnv {
+string MODE
+boolean DEV
+boolean PROD
+boolean SSR
+string VITE_MCP_GATEWAY_BASE_URL
+string VITE_API_BASE_URL
+string VITE_WS_BASE_URL
+[key: string]: string | boolean | undefined
}
class ImportMeta {
+ImportMetaEnv env
}
ImportMeta --> ImportMetaEnv : env
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @boston008 - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `web/src/main.tsx:47` </location>
<code_context>
- </HeroUIProvider>
- </React.StrictMode>,
-);
+// Show loading screen immediately
+const rootElement = document.getElementById("root");
+if (rootElement) {
+ ReactDOM.createRoot(rootElement).render(
+ <React.StrictMode>
+ <HeroUIProvider>
+ <LoadingScreen />
+ </HeroUIProvider>
+ </React.StrictMode>
+ );
+}
</code_context>
<issue_to_address>
Potential for double React root creation on the same DOM node.
Creating multiple React roots on the same DOM node can cause warnings or unexpected behavior. Use a single root and conditionally render the loading screen or main app to avoid this issue.
</issue_to_address>
### Comment 2
<location> `web/src/services/api.ts:14` </location>
<code_context>
// Create an axios instance with default config
const api = axios.create({
- baseURL: import.meta.env.VITE_API_URL || '/api',
+ baseURL: window.RUNTIME_CONFIG?.VITE_API_BASE_URL || '/api',
timeout: 10000,
headers: {
</code_context>
<issue_to_address>
Potential typo: VITE_API_URL should likely be VITE_API_BASE_URL for consistency.
The runtime config and Dockerfiles use VITE_API_BASE_URL, so using a different variable here may cause misconfiguration unless intentional.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
const api = axios.create({
baseURL: window.RUNTIME_CONFIG?.VITE_API_BASE_URL || '/api',
timeout: 10000,
headers: {
=======
const api = axios.create({
baseURL: window.RUNTIME_CONFIG?.VITE_API_BASE_URL || import.meta.env.VITE_API_BASE_URL || '/api',
timeout: 10000,
headers: {
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| // Show loading screen immediately | ||
| const rootElement = document.getElementById("root"); | ||
| if (rootElement) { | ||
| ReactDOM.createRoot(rootElement).render( | ||
| <React.StrictMode> | ||
| <HeroUIProvider> | ||
| <LoadingScreen /> | ||
| </HeroUIProvider> | ||
| </React.StrictMode> |
There was a problem hiding this comment.
issue (bug_risk): Potential for double React root creation on the same DOM node.
Creating multiple React roots on the same DOM node can cause warnings or unexpected behavior. Use a single root and conditionally render the loading screen or main app to avoid this issue.
|
@boston008 can you pls handle the conflicts? |
Done |
Vite runtime varables add default values for backward compatibility
Removed vite build time variable from allinone Dockerfile
Summary by Sourcery
Fetch runtime configuration at startup with default values for backward compatibility, replace build-time env variables with a dynamic
window.RUNTIME_CONFIG, and refactor gateway URL construction and CORS headers; also remove obsolete VITE_* declarations from DockerfilesNew Features:
/api/runtime-configendpoint with default values and deep merging for backward compatibilityEnhancements:
import.meta.envusages to usewindow.RUNTIME_CONFIGand add agetGatewayBaseUrl()helper for unified URL resolutionmcp-protocol-versionheader across YAML, Go converter, and React componentsImportMetaEnvtypings to include built-in Vite variables and allow arbitrary keysBuild:
Chores: