fix(data): stop the field dialog crashing outside a secure context - #326
Open
lovepixel-git wants to merge 1 commit into
Open
fix(data): stop the field dialog crashing outside a secure context#326lovepixel-git wants to merge 1 commit into
lovepixel-git wants to merge 1 commit into
Conversation
`crypto.randomUUID()` is only defined when `window.isSecureContext` is true. An admin reached over plain HTTP on a LAN address or bare hostname has no such function, so opening the New Field dialog threw `TypeError: crypto.randomUUID is not a function` and crashed the page. `localhost` is treated as a secure context regardless of scheme, which is why this never reproduced in local development. `handleAdd()` in the framework scale panel had the same latent bug. Both call sites move to `nanoid`, already the id primitive everywhere else in the codebase, including `fieldDefaults.ts` and `scaleGroups.ts` in these same two feature areas. `SelectOptionSchema.id` is `Type.String()` with no format constraint, so ids already persisted in UUID shape stay valid and no migration is needed. Fixes CoreBunch#319
lovepixel-git
force-pushed
the
fix/data-field-option-id-secure-context
branch
from
August 2, 2026 02:50
8526513 to
a62ced2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #319.
Root cause
crypto.randomUUID()is only defined whenwindow.isSecureContextis true. An admin reached over plain HTTP on a LAN address or a bare hostname is not a secure context, so the function is simply absent andmakeOption()throwsTypeError: crypto.randomUUID is not a function, crashing the page.localhostand127.0.0.1are treated as secure contexts regardless of scheme, which is why this never shows up in local development and only surfaced on a Docker Compose install reached over the network.Probed one dev server across three origins:
isSecureContexttypeof crypto.randomUUIDhttp://localhost:3001functionhttp://127.0.0.1:3001functionhttp://192.168.7.112:3001undefinedChange
Two browser call sites reached
crypto.randomUUID()directly:makeOption()insrc/admin/pages/data/components/NewFieldDialog/newFieldDialogModel.ts, the crash in [Bug]: Can't add field for Custom Data Table #319, on the admin/data → add table → add field pathhandleAdd()insrc/admin/pages/site/panels/FrameworkScalePanel/ClassGeneratorList.tsx, the same bug, not yet reportedBoth move to
nanoid. That is not a new dependency or a new convention:nanoidis already the id primitive in 37 modules, includingsrc/admin/pages/data/utils/fieldDefaults.tsandsrc/core/framework/scaleGroups.ts, which sit in these same two feature areas. The twocrypto.randomUUID()calls were the anomaly.I fixed the second site in the same change because it is one root cause rather than two problems. Happy to split it out if you would rather keep the PR to the reported path.
Persistence
DraftOption.iddoes reach storage, viaDataSelectOptionon select and multiSelect fields, so the id format matters.SelectOptionSchema.idisType.String()with no format constraint, so nanoid ids validate, ids already persisted in UUID shape stay valid, and no migration is required.Tests
New:
src/__tests__/data/newFieldDialogModel.test.ts, four cases exercisingmakeOption()withcrypto.randomUUIDremoved to mirror an insecure context. Covers option creation, id uniqueness across 100 generations, and TypeBox validity of the resulting select options.Verified failing on
mainwith the exact error from the issue, passing on this branch.bun run lintcleanbun run buildcleanbun test6534 pass, 1 failUnrelated pre-existing failure
That one failure is
Bundle size budgets > ContentPage-*.js, at 90043 B against a 90000 B budget, 43 bytes over. It is not from this change. I stashed the fix, rebuilt cleanmain, and got the byte-identical 90043. It only appears afterbun run build, since the budget test readsdist/, so a test run on a fresh clone will not show it. Flagging it rather than folding it in, since it is a separate problem.