-
Notifications
You must be signed in to change notification settings - Fork 7
fix: kotlin sample frontend crashes on http://0.0.0.0 and quiets HPKE build warnings #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // crypto.randomUUID() requires a secure context (https or localhost). It throws | ||
| // on http://0.0.0.0:8080 in some browsers, which is the host Ktor binds to. | ||
| export function randomUUID(): string { | ||
| if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') { | ||
| return crypto.randomUUID() | ||
| } | ||
| return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { | ||
| const r = (Math.random() * 16) | 0 | ||
| const v = c === 'x' ? r : (r & 0x3) | 0x8 | ||
| return v.toString(16) | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,35 @@ | ||||||||||||||||||||||||||
| import { defineConfig } from 'vite' | ||||||||||||||||||||||||||
| import { createLogger, defineConfig } from 'vite' | ||||||||||||||||||||||||||
| import react from '@vitejs/plugin-react' | ||||||||||||||||||||||||||
| import tailwindcss from '@tailwindcss/vite' | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // @hpke/common has a Node <= v18 fallback that does `await import("crypto")`. | ||||||||||||||||||||||||||
| // It never executes in browsers (guarded by globalThis.crypto), but Vite logs an | ||||||||||||||||||||||||||
| // externalization warning at build time. The same package also ships misplaced | ||||||||||||||||||||||||||
| // /* @__PURE__ */ comments that Rollup can't attach. Both are noise; filter them. | ||||||||||||||||||||||||||
| const logger = createLogger() | ||||||||||||||||||||||||||
| const originalWarn = logger.warn | ||||||||||||||||||||||||||
| logger.warn = (msg, opts) => { | ||||||||||||||||||||||||||
| if (msg.includes('has been externalized for browser compatibility')) return | ||||||||||||||||||||||||||
| originalWarn(msg, opts) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+11
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: samples/frontend/vite.config.ts
Line: 11-14
Comment:
The logger filter matches any warning that contains `'has been externalized for browser compatibility'`, which suppresses the message from every dependency — not just `@hpke/common`. If a future (or existing) package is being externalized for a reason that would cause a real browser runtime error, the build would remain silent about it. The `rollupOptions.onwarn` handler correctly gates on `warning.id?.includes('@hpke/common')`; the same scoping should apply here.
```suggestion
logger.warn = (msg, opts) => {
if (
msg.includes('has been externalized for browser compatibility') &&
msg.includes('@hpke/common')
)
return
originalWarn(msg, opts)
}
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export default defineConfig({ | ||||||||||||||||||||||||||
| plugins: [react(), tailwindcss()], | ||||||||||||||||||||||||||
| customLogger: logger, | ||||||||||||||||||||||||||
| build: { | ||||||||||||||||||||||||||
| outDir: '../kotlin/src/main/resources/static', | ||||||||||||||||||||||||||
| emptyOutDir: true, | ||||||||||||||||||||||||||
| rollupOptions: { | ||||||||||||||||||||||||||
| onwarn(warning, warn) { | ||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||
| warning.code === 'INVALID_ANNOTATION' && | ||||||||||||||||||||||||||
| warning.id?.includes('@hpke/common') | ||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| warn(warning) | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| server: { | ||||||||||||||||||||||||||
| port: 5173, | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.random()is not cryptographically secure and produces low-entropy output. This only matters here in theIdempotency-Keyusage inExecuteSignedQuote.tsx: a collision, however unlikely, could cause the server to treat a fresh quote execution as a duplicate of a prior one. For a sample/dev-only path this is acceptable, but worth a comment at the call-site so future readers understand the trade-off.Prompt To Fix With AI