Skip to content

Commit 7e76d15

Browse files
geroplona-agent
andcommitted
Improve minimal mode detection: drop ConfigCat, use isDedicatedInstallation
- Remove ConfigCat feature flag dependency for minimal mode detection - gitpod.io: always use minimal mode (synchronous, no network call) - Preview environments: use isDedicatedInstallation with localStorage caching - Dedicated/self-hosted: never use minimal mode - Replace document.write() with innerHTML to avoid deprecation issues - Change GITPOD_WITH_DEDICATED_EMU default to true in preview deployments The localStorage override (minimal_gitpod_io_mode=true/false) still works for testing. Co-authored-by: Ona <no-reply@ona.com>
1 parent dc87226 commit 7e76d15

File tree

3 files changed

+54
-49
lines changed

3 files changed

+54
-49
lines changed

components/dashboard/src/index.tsx

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,17 @@ import "./index.css";
2525
import { PaymentContextProvider } from "./payment-context";
2626
import { ThemeContextProvider } from "./theme-context";
2727
import { UserContextProvider } from "./user-context";
28-
import { getURLHash, isGitpodIo, isWebsiteSlug } from "./utils";
29-
import { getExperimentsClient } from "./experiments/client";
28+
import { getURLHash, isWebsiteSlug } from "./utils";
3029
// Import the minimal login HTML template at build time
3130
import minimalLoginHtml from "./minimal-login.html";
3231

33-
const MINIMAL_MODE_STORAGE_KEY = "minimal_gitpod_io_mode";
34-
const MINIMAL_MODE_FLAG_NAME = "minimal_gitpod_io_mode";
32+
const MINIMAL_MODE_OVERRIDE_KEY = "minimal_gitpod_io_mode";
3533

3634
/**
37-
* Check if we should use minimal gitpod.io mode.
38-
* Priority:
39-
* 1. localStorage override (for testing)
40-
* 2. ConfigCat feature flag
35+
* Check if this is production gitpod.io (exact match)
4136
*/
42-
async function shouldUseMinimalMode(): Promise<boolean> {
43-
// Check localStorage override first (sync, for testing)
44-
try {
45-
const localOverride = localStorage.getItem(MINIMAL_MODE_STORAGE_KEY);
46-
if (localOverride === "true") return true;
47-
if (localOverride === "false") return false;
48-
} catch {
49-
// localStorage might not be available
50-
}
51-
52-
// Check ConfigCat feature flag
53-
try {
54-
const client = getExperimentsClient();
55-
const value = await client.getValueAsync(MINIMAL_MODE_FLAG_NAME, false, {
56-
gitpodHost: window.location.host,
57-
});
58-
return value === true;
59-
} catch (error) {
60-
console.error("Failed to check minimal mode flag:", error);
61-
return false; // Fail safe: use full app
62-
}
37+
function isProductionGitpodIo(): boolean {
38+
return window.location.hostname === "gitpod.io";
6339
}
6440

6541
/**
@@ -159,15 +135,29 @@ function handleMinimalGitpodIoMode(): void {
159135
window.location.href = `https://www.gitpod.io${pathname}${search}`;
160136
}
161137

138+
/**
139+
* Extract body content from a full HTML document string.
140+
* This allows keeping the complete HTML structure in the source file for easier editing.
141+
*/
142+
function extractBodyContent(html: string): string {
143+
const parser = new DOMParser();
144+
const doc = parser.parseFromString(html, "text/html");
145+
return doc.body.innerHTML;
146+
}
147+
162148
/**
163149
* Render a minimal static login page without React.
164-
* Loads the HTML from an external file for easier review and maintenance.
150+
* Uses innerHTML instead of document.write() to avoid deprecation issues.
165151
*/
166152
function renderMinimalLoginPage(): void {
167-
// Replace the entire document with the minimal login page
168-
document.open();
169-
document.write(minimalLoginHtml);
170-
document.close();
153+
const bodyContent = extractBodyContent(minimalLoginHtml);
154+
const root = document.getElementById("root");
155+
if (root) {
156+
root.innerHTML = bodyContent;
157+
} else {
158+
// Fallback if root doesn't exist
159+
document.body.innerHTML = bodyContent;
160+
}
171161
}
172162

173163
/**
@@ -222,22 +212,36 @@ function bootFullApp(): void {
222212

223213
/**
224214
* Main boot function
215+
*
216+
* Minimal mode is enabled when:
217+
* - localStorage override is "true" (for testing in preview environments)
218+
* - Host is exactly "gitpod.io" AND path is not a website slug
225219
*/
226-
const bootApp = async () => {
227-
// Minimal gitpod.io mode - only on exact "gitpod.io" domain
228-
if (isGitpodIo()) {
229-
const minimalMode = await shouldUseMinimalMode();
230-
231-
if (minimalMode) {
232-
handleMinimalGitpodIoMode();
233-
return;
234-
}
220+
const bootApp = () => {
221+
const pathname = window.location.pathname;
222+
223+
// Handle website slugs on gitpod.io - redirect to www.gitpod.io
224+
if (isProductionGitpodIo() && isWebsiteSlug(pathname)) {
225+
window.location.href = `https://www.gitpod.io${pathname}${window.location.search}`;
226+
return;
227+
}
235228

236-
// Not in minimal mode, but still handle website slugs
237-
if (isWebsiteSlug(window.location.pathname)) {
238-
window.location.host = "www.gitpod.io";
239-
return;
229+
// Check if minimal mode should be used
230+
let minimalMode = false;
231+
try {
232+
if (localStorage.getItem(MINIMAL_MODE_OVERRIDE_KEY) === "true") {
233+
minimalMode = true;
240234
}
235+
} catch {
236+
// localStorage might not be available
237+
}
238+
if (!minimalMode && isProductionGitpodIo()) {
239+
minimalMode = true;
240+
}
241+
242+
if (minimalMode) {
243+
handleMinimalGitpodIoMode();
244+
return;
241245
}
242246

243247
// Boot full React app

components/dashboard/src/minimal-login.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
See License.AGPL.txt in the project root for license information.
66
77
Minimal login page for gitpod.io when minimal mode is enabled.
8-
This page is loaded by index.tsx when the minimal_gitpod_io_mode flag is active.
8+
This is a complete HTML document for easier editing and preview.
9+
index.tsx extracts only the body content using DOMParser.
910
-->
1011
<html lang="en">
1112
<head>

dev/preview/workflow/preview/deploy-gitpod.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ GITPOD_IMAGE_PULL_SECRET_NAME="image-pull-secret";
2424
GITPOD_PROXY_SECRET_NAME="proxy-config-certificates";
2525
GITPOD_ANALYTICS="${GITPOD_ANALYTICS:-}"
2626
GITPOD_WORKSPACE_FEATURE_FLAGS="${GITPOD_WORKSPACE_FEATURE_FLAGS:-}"
27-
GITPOD_WITH_DEDICATED_EMU="${GITPOD_WITH_DEDICATED_EMU:-false}"
27+
GITPOD_WITH_DEDICATED_EMU="${GITPOD_WITH_DEDICATED_EMU:-true}"
2828
PREVIEW_GCP_PROJECT="gitpod-dev-preview"
2929

3030

0 commit comments

Comments
 (0)