Skip to content

Commit f881393

Browse files
geroplona-agent
andauthored
Improve minimal mode detection: drop ConfigCat, use isDedicatedInstallation (#21289)
- 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 f881393

File tree

3 files changed

+56
-51
lines changed

3 files changed

+56
-51
lines changed

components/dashboard/src/index.tsx

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,11 @@ 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";
35-
36-
/**
37-
* Check if we should use minimal gitpod.io mode.
38-
* Priority:
39-
* 1. localStorage override (for testing)
40-
* 2. ConfigCat feature flag
41-
*/
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-
}
63-
}
32+
const MINIMAL_MODE_OVERRIDE_KEY = "minimal_gitpod_io_mode";
6433

6534
/**
6635
* Check if the pathname is a known app route that should show the minimal login page
@@ -159,15 +128,29 @@ function handleMinimalGitpodIoMode(): void {
159128
window.location.href = `https://www.gitpod.io${pathname}${search}`;
160129
}
161130

131+
/**
132+
* Extract body content from a full HTML document string.
133+
* This allows keeping the complete HTML structure in the source file for easier editing.
134+
*/
135+
function extractBodyContent(html: string): string {
136+
const parser = new DOMParser();
137+
const doc = parser.parseFromString(html, "text/html");
138+
return doc.body.innerHTML;
139+
}
140+
162141
/**
163142
* Render a minimal static login page without React.
164-
* Loads the HTML from an external file for easier review and maintenance.
143+
* Uses innerHTML instead of document.write() to avoid deprecation issues.
165144
*/
166145
function renderMinimalLoginPage(): void {
167-
// Replace the entire document with the minimal login page
168-
document.open();
169-
document.write(minimalLoginHtml);
170-
document.close();
146+
const bodyContent = extractBodyContent(minimalLoginHtml);
147+
const root = document.getElementById("root");
148+
if (root) {
149+
root.innerHTML = bodyContent;
150+
} else {
151+
// Fallback if root doesn't exist
152+
document.body.innerHTML = bodyContent;
153+
}
171154
}
172155

173156
/**
@@ -221,23 +204,44 @@ function bootFullApp(): void {
221204
}
222205

223206
/**
224-
* Main boot function
207+
* Check if this is exactlly gitpod.io
225208
*/
226-
const bootApp = async () => {
227-
// Minimal gitpod.io mode - only on exact "gitpod.io" domain
228-
if (isGitpodIo()) {
229-
const minimalMode = await shouldUseMinimalMode();
209+
function isExactGitpodIo(): boolean {
210+
return window.location.hostname === "gitpod.io";
211+
}
230212

231-
if (minimalMode) {
232-
handleMinimalGitpodIoMode();
213+
/**
214+
* 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
219+
*/
220+
const bootApp = () => {
221+
let minimalMode = false;
222+
223+
// Handle website slugs on gitpod.io - redirect to www.gitpod.io
224+
if (isExactGitpodIo()) {
225+
const pathname = window.location.pathname;
226+
if (isWebsiteSlug(pathname)) {
227+
window.location.href = `https://www.gitpod.io${pathname}${window.location.search}`;
233228
return;
234229
}
230+
minimalMode = true;
231+
}
235232

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;
233+
// Check local storage override
234+
try {
235+
if (localStorage.getItem(MINIMAL_MODE_OVERRIDE_KEY) === "true") {
236+
minimalMode = true;
240237
}
238+
} catch {
239+
// localStorage might not be available
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)