Commit e9d43f6
fix(ui): use feature detection for crypto.randomUUID to support HTTP deployments (#1868)
**Summary**
- The UI uses `crypto.randomUUID()` which requires a [Secure
Context](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID)
(HTTPS or localhost). Deployments served over plain HTTP crash on
`/agents/new` with `Uncaught TypeError: crypto.randomUUID is not a
function`.
- Introduces a `generateId()` utility in `ui/src/lib/utils.ts` that
detects `crypto.randomUUID` availability at runtime and falls back to
the `uuid` package (already a dependency, v14) when unavailable.
- Replaces all 8 `crypto.randomUUID()` call sites across 4 source files.
**Changes**
| File | Change |
|------|--------|
| `ui/src/lib/utils.ts` | Add `generateId()` with runtime feature
detection |
| `ui/src/lib/promptSourceRow.ts` | `crypto.randomUUID()` →
`generateId()` |
| `ui/src/lib/openClawSandboxForm.ts` | `crypto.randomUUID()` →
`generateId()` |
| `ui/src/components/prompts/FragmentEntriesEditor.tsx` | 4×
`crypto.randomUUID()` → `generateId()` |
| `ui/src/app/agents/new/page.tsx` | 2× `crypto.randomUUID()` →
`generateId()` |
**Context**
`crypto.randomUUID()` is a Web Crypto API gated behind Secure Context.
Any deployment accessed via `http://` (common in internal/dev clusters
without TLS termination) crashes when rendering the agent creation form.
The `uuid` npm package (v14, already in `package.json`) uses
`crypto.getRandomValues()` which works in all contexts.
The fix uses runtime feature detection (`typeof crypto.randomUUID ===
"function"`) so it works with the pre-built Docker image regardless of
deployment configuration — no Helm or environment variable changes
needed.
`ui/public/mockServiceWorker.js` also calls `crypto.randomUUID()` but is
auto-generated by MSW and runs in a Service Worker context (always
secure), so it is not modified.
**Test plan**
- [ ] `cd ui && npm run build` passes
- [ ] `cd ui && npm run lint` passes
- [ ] Deploy over HTTP → `/agents/new` → "Skip wizard" → form loads
without crash
- [ ] Deploy over HTTPS → same flow works using native
`crypto.randomUUID()`
- [ ] `grep -r 'crypto.randomUUID' ui/src/` returns only `utils.ts`
feature-detection branch (and `mockServiceWorker.js`)
Signed-off-by: wsszh <wsszh@users.noreply.github.com>
Signed-off-by: sup <sup@supdeMacBook-Pro.local>
Co-authored-by: sup <sup@supdeMacBook-Pro.local>
Co-authored-by: Eitan Yarmush <eitan.yarmush@solo.io>1 parent 88a4bc7 commit e9d43f6
5 files changed
Lines changed: 21 additions & 8 deletions
File tree
- ui/src
- app/agents/new
- components/prompts
- lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
165 | | - | |
| 166 | + | |
166 | 167 | | |
167 | 168 | | |
168 | 169 | | |
| |||
207 | 208 | | |
208 | 209 | | |
209 | 210 | | |
210 | | - | |
| 211 | + | |
211 | 212 | | |
212 | 213 | | |
213 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | | - | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | | - | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
8 | | - | |
| 10 | + | |
9 | 11 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
39 | 47 | | |
40 | 48 | | |
41 | 49 | | |
| |||
0 commit comments