fix(ui): avoid crypto.randomUUID crash on LAN HTTP showcase (#332)#384
Conversation
Reviewer's GuideImplements a safe UUID generation utility for non-secure browser contexts, wires it into the showcase run history component to prevent LAN-HTTP crashes, adds targeted tests, and enforces a lint rule to prevent future direct uses of crypto.randomUUID, along with documenting the reliability work item in a PRP file. File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Closes #332 — Reliability E3 of umbrella #380.
crypto.randomUUID()is only defined in secure contexts (HTTPS or localhost). On a plain-HTTP LAN origin (http://<lan-ip>:5173/showcase) it isundefined, and the direct call atRunHistoryStrip.tsx:75threwTypeError: crypto.randomUUID is not a functionduring render atpipeline_complete— React unmounted the whole tree and the showcase white-screened while the backend pipeline finished fine.Changes
frontend/src/lib/uuid-utils.ts(new) —safeRandomUUID(): nativecrypto.randomUUID()when available → RFC-4122-v4 viacrypto.getRandomValues()(not secure-context-gated, crypto-strong) →Math.random()last resort when Web Crypto is absent entirely.frontend/src/lib/uuid-utils.test.ts(new) — 3 cases covering all three paths (v4 regex + uniqueness).RunHistoryStrip.tsx— one-line swap tosafeRandomUUID()(the render-phase append pattern is deliberate and untouched).RunHistoryStrip.test.tsx— regression case stubbing the LAN-HTTP crypto shape (getRandomValuesonly); proven to fail with the originalTypeErrorwhen the fix is reverted.eslint.config.js— repo-wideno-restricted-propertiesguard banning directcrypto.randomUUIDaccess (message points at the helper); the only sanctioned call site carries inline disables. Verified the rule bites: the unfixed call site failspnpm lintwith the new message.No new npm dependency (
uuid/nanoidrejected — ~25-line util for one call site, per product-vision dependency-light footprint). Zero backend changes.Validation
pnpm lint— clean (0 errors; 1 pre-existingreact-hooks/incompatible-librarywarning in untoucheddata-table.tsx)pnpm test --run— 323/323 across 58 files (+4 new cases)npx tsc -b— zero errors in touched fileshttp://10.0.0.226:5173/showcase:isSecureContext=false,typeof crypto.randomUUID === 'undefined'; fulldemo_minimalrun completed (16s, PASS); no white screen, zero page errors; "Recent runs" strip rendered; persisted id8706c012-2014-439e-806c-e235481e228amatches the v4 shape via the fallback path.Notes for reviewers
pnpm tsc --noEmitis vacuous (solution-style root tsconfig type-checks zero files), andnpx tsc -balready fails ondevwith pre-existingnoUncheckedIndexedAccesserrors in unrelated files (ai-models-panel.tsx,forecast-chart.tsx,job-picker.tsx,demand-utils.test.ts). Both deserve their own issue; out of scope here.Summary by Sourcery
Introduce a safe UUID generation utility for the frontend and use it to prevent showcase crashes in non-secure (plain-HTTP LAN) contexts.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: