Skip to content

Commit 91275ba

Browse files
committed
feat(EdgeSlowLoadHint): add component to inform users about slow loading on Microsoft Edge
1 parent b8d0446 commit 91275ba

4 files changed

Lines changed: 165 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ The latest release is deployed automatically to GitHub Pages. Open the link in a
1212

1313
> First load downloads Pyodide and installs Sigima via `micropip` (~30–60 s). Subsequent loads are cached by the browser.
1414
15+
> **Microsoft Edge users:** if the first load takes several minutes instead of ~30 s, Edge's _Enhance your security on the web_ setting is disabling the WebAssembly JIT compiler on this site. Microsoft [documents this behaviour and explicitly recommends the workaround](https://learn.microsoft.com/en-us/deployedge/microsoft-edge-security-browse-safer) — quoting the page:
16+
>
17+
> > Developers should be aware that the WebAssembly (WASM) interpreter running in enhanced security mode might not yield the expected level of performance. We recommend adding your site as an exception to opt-out of enhanced security mode for site users.
18+
>
19+
> To add the exception: open `edge://settings/privacy` → _Security_ → _Manage enhanced security for sites_ → under _Never use enhanced security for these sites_, click _Add a site_ and enter `https://datalab-platform.com` (or your deployment URL). Reload the page; load time drops back to ~30 s. Chrome, Firefox and Safari are not affected.
20+
1521
![DataLab Web — 2D sinc image with statistics and contrast tools](doc/images/screenshot-image-sinc2d.png)
1622

1723
## Features

‎src/App.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import {
7575
} from "./utils/consoleLog";
7676
import { DialogBridge } from "./components/DialogBridge";
7777
import { useConfirm, useMessage, usePrompt } from "./components/ConfirmDialog";
78+
import { EdgeSlowLoadHint } from "./components/EdgeSlowLoadHint";
7879
import { useProgress } from "./components/ProgressDialog";
7980
import {
8081
SeparateViewDialog,
@@ -3118,6 +3119,7 @@ export default function App() {
31183119
className="plot-loading-logo"
31193120
/>
31203121
<div className="plot-loading-message">{message}</div>
3122+
<EdgeSlowLoadHint />
31213123
</div>
31223124
)}
31233125
{centralView === "plot" &&
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Slow-load hint shown during Pyodide initialisation on Microsoft Edge.
3+
*
4+
* Edge's "Enhance your security on the web" feature (a.k.a. Enhanced
5+
* Security Mode) disables the WebAssembly JIT on unfamiliar sites,
6+
* which makes Pyodide start-up 20-40x slower than on Chrome / Firefox.
7+
* Microsoft documents this explicitly and recommends adding the site
8+
* as an exception (see ``microsoft-edge-security-browse-safer`` page,
9+
* "Important" admonition):
10+
*
11+
* > Developers should be aware that the WebAssembly (WASM) interpreter
12+
* > running in enhanced security mode might not yield the expected
13+
* > level of performance. We recommend adding your site as an
14+
* > exception to opt-out of enhanced security mode for site users.
15+
*
16+
* This component shows a discreet, English-only hint after a delay,
17+
* but only when the user agent looks like Microsoft Edge. The hint is
18+
* unmounted as soon as the runtime finishes loading.
19+
*
20+
* Note: Chromium blocks ``<a href="edge://...">`` navigation from web
21+
* pages for security reasons, so the settings URL is exposed as a
22+
* copy-to-clipboard button rather than a real link.
23+
*/
24+
25+
import { useEffect, useState } from "react";
26+
27+
/** Detect Microsoft Edge (Chromium). The UA token is ``Edg/`` — not
28+
* ``Edge/`` which was the legacy EdgeHTML browser. */
29+
function isMicrosoftEdge(): boolean {
30+
if (typeof navigator === "undefined") return false;
31+
return /\bEdg\//.test(navigator.userAgent);
32+
}
33+
34+
const HINT_DELAY_MS = 60_000;
35+
const EDGE_SETTINGS_URL = "edge://settings/privacy";
36+
const MS_DOC_URL =
37+
"https://learn.microsoft.com/en-us/deployedge/microsoft-edge-security-browse-safer";
38+
39+
export function EdgeSlowLoadHint() {
40+
const [show, setShow] = useState(false);
41+
const [copied, setCopied] = useState(false);
42+
43+
useEffect(() => {
44+
if (!isMicrosoftEdge()) return;
45+
const id = window.setTimeout(() => setShow(true), HINT_DELAY_MS);
46+
return () => window.clearTimeout(id);
47+
}, []);
48+
49+
if (!show) return null;
50+
51+
const copyUrl = async () => {
52+
try {
53+
await navigator.clipboard.writeText(EDGE_SETTINGS_URL);
54+
setCopied(true);
55+
window.setTimeout(() => setCopied(false), 2000);
56+
} catch {
57+
// Clipboard API unavailable (e.g. insecure context): silently ignore.
58+
}
59+
};
60+
61+
return (
62+
<div className="plot-loading-edge-hint">
63+
<div className="plot-loading-edge-hint-title">
64+
Loading is unusually slow on Microsoft Edge?
65+
</div>
66+
<div className="plot-loading-edge-hint-body">
67+
Edge&apos;s <strong>Enhance your security on the web</strong> setting
68+
disables the WebAssembly JIT compiler on unfamiliar sites, which can
69+
slow down Pyodide start-up by 20-40x.{" "}
70+
<a href={MS_DOC_URL} target="_blank" rel="noopener noreferrer">
71+
Microsoft recommends adding the site as an exception
72+
</a>{" "}
73+
as the official workaround for WebAssembly-heavy applications:
74+
<ol>
75+
<li>
76+
Open the Edge settings page (Chromium blocks direct links to{" "}
77+
<code>edge://</code> URLs from web pages, so use the button below to
78+
copy the URL, then paste it into the address bar):
79+
<div className="plot-loading-edge-hint-url">
80+
<code>{EDGE_SETTINGS_URL}</code>
81+
<button
82+
type="button"
83+
onClick={copyUrl}
84+
className="plot-loading-edge-hint-copy"
85+
>
86+
{copied ? "Copied!" : "Copy URL"}
87+
</button>
88+
</div>
89+
</li>
90+
<li>
91+
Under <em>Security</em>, make sure{" "}
92+
<em>Enhance your security on the web</em> is turned on, then click{" "}
93+
<em>Manage enhanced security for sites</em>.
94+
</li>
95+
<li>
96+
Under <em>Never use enhanced security for these sites</em>, click{" "}
97+
<em>Add a site</em> and enter the URL of this application (for
98+
example <code>https://datalab-platform.com</code>).
99+
</li>
100+
<li>Reload this page.</li>
101+
</ol>
102+
</div>
103+
</div>
104+
);
105+
}

‎src/styles.css‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,58 @@ input {
14401440
text-align: center;
14411441
}
14421442

1443+
.plot-loading-edge-hint {
1444+
max-width: 560px;
1445+
margin-top: 8px;
1446+
padding: 12px 16px;
1447+
border: 1px solid var(--border, #888);
1448+
border-radius: 6px;
1449+
background: var(--panel-bg, rgba(127, 127, 127, 0.08));
1450+
color: var(--text, inherit);
1451+
font-size: 12px;
1452+
line-height: 1.5;
1453+
text-align: left;
1454+
}
1455+
1456+
.plot-loading-edge-hint-title {
1457+
font-weight: 600;
1458+
margin-bottom: 6px;
1459+
}
1460+
1461+
.plot-loading-edge-hint-body ol {
1462+
margin: 6px 0 0 0;
1463+
padding-left: 20px;
1464+
}
1465+
1466+
.plot-loading-edge-hint-body code {
1467+
font-family: var(--font-mono, monospace);
1468+
font-size: 11px;
1469+
padding: 0 4px;
1470+
background: rgba(127, 127, 127, 0.15);
1471+
border-radius: 3px;
1472+
}
1473+
1474+
.plot-loading-edge-hint-url {
1475+
display: flex;
1476+
align-items: center;
1477+
gap: 8px;
1478+
margin: 4px 0 2px 0;
1479+
}
1480+
1481+
.plot-loading-edge-hint-copy {
1482+
font-size: 11px;
1483+
padding: 2px 8px;
1484+
border: 1px solid var(--border, #888);
1485+
border-radius: 3px;
1486+
background: var(--button-bg, transparent);
1487+
color: inherit;
1488+
cursor: pointer;
1489+
}
1490+
1491+
.plot-loading-edge-hint-copy:hover {
1492+
background: rgba(127, 127, 127, 0.15);
1493+
}
1494+
14431495
@keyframes plot-loading-pulse {
14441496
0%,
14451497
100% {

0 commit comments

Comments
 (0)