Skip to content

Commit 0d50185

Browse files
authored
Small web platform cleanups (#3440)
These came out of a scan I did of the console with Chrome's [Modern Web Guidance](https://developer.chrome.com/docs/modern-web-guidance) skill, which gives an agent a set of guides on current web platform features to check a codebase against. Each change is its own commit. - **Set `color-scheme` from the chosen theme.** Our `<meta name="color-scheme" content="dark light">` tag tells the browser to pick a scheme from the OS preference, and the theme toggle only set `data-theme` on `<html>`. So browser-drawn UI (native scrollbars, date pickers, autofill) followed the OS and not the chosen theme. With a light OS and the default dark theme, the side modal's scrollbar was drawn for a light page: a white track with classic scrollbars, or a dark thumb on the dark background with macOS overlay scrollbars. Now `data-theme` also sets the `color-scheme` CSS property. - **Add `autoComplete="current-password"` to the login form's password field.** Password managers use it to tell a login form from a signup form. The username field already had `autoComplete="username"`. - **Drive table scroll shadows with a CSS scroll timeline.** The shadows on the sticky first column and the actions column were toggled by a `useIsOverflow` hook that listened to scroll and resize events, throttled with `lodash.throttle`. They are now an animation tied to the table's horizontal scroll position with `animation-timeline: scroll(nearest inline)`, so the hook and `lodash.throttle` are gone. The shadow fades in over the first 2rem of scroll instead of snapping on. Scroll timelines need Chrome 115 (July 2023), Safari 26 (September 2025) or Firefox 159 (October 2026), which is only two weeks old. The rules are inside `@supports`, so older Firefox and Safari lose the shadows and nothing else. I think that is fine: the scrollbar is still always visible. The shadows were also very hard to see, especially in the dark theme, so I made them stronger. - **Use a theme color for the table scrollbar thumb.** The SimpleBar thumb was hard-coded white at 28% opacity, which is nearly invisible in the light theme. It is now `--content-quaternary`, and `--content-tertiary` on hover. - **Drop the `uuid` package.** This one is not from the scan. The mock API now uses `crypto.randomUUID()`, which needs a secure context (HTTPS or localhost), as MSW's service worker already does. Toast IDs were the only use in the app itself, and I replaced those with a simple counter because the console is occasionally served over plain HTTP, e.g., from Nexus on a remote dev machine. `uuid.validate` in the mock API is replaced by a regex that matches any UUID version, [as Nexus does](https://github.com/oxidecomputer/omicron/blob/aa28c9c/common/src/api/external/mod.rs#L357-L367). I also tried replacing SimpleBar with native `scrollbar-color` and `scrollbar-width`, which one of the guides recommends, and dropped it. SimpleBar was added in #1310 to keep the table's horizontal scrollbar visible so it's clear the table overflows. Firefox on macOS can't do that natively: overlay scrollbars hide until you scroll. I checked the shadows and the scrollbar thumb in Chromium in both themes, and that Firefox 151, which has no scroll timelines, shows no shadows. ### `color-scheme`: light OS, dark theme Before, the overlay scrollbar thumb on the right is dark on a dark background. <img width="2144" height="1298" alt="color-scheme" src="https://github.com/user-attachments/assets/a7ca8062-c0e1-4f59-aed9-06d1ed7b9589" /> ### Scroll shadows <img width="1488" height="1336" alt="shadows" src="https://github.com/user-attachments/assets/addb6073-ae4e-412b-bc46-a0577238d79f" /> ### Table scrollbar thumb in light theme <img width="1488" height="804" alt="thumb" src="https://github.com/user-attachments/assets/44fb4cd2-6db9-4a3a-9628-6bcd0efe4047" />
1 parent f9f6fee commit 0d50185

16 files changed

Lines changed: 119 additions & 217 deletions

File tree

‎app/hooks/use-is-overflow.ts‎

Lines changed: 0 additions & 69 deletions
This file was deleted.

‎app/pages/LoginPage.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default function LoginPage() {
7272
name="password"
7373
type="password"
7474
placeholder="Password"
75+
autoComplete="current-password"
7576
required
7677
control={form.control}
7778
/>

‎app/stores/toast.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* Copyright Oxide Computer Company
77
*/
88
import { type ReactElement } from 'react'
9-
import { v4 as uuid } from 'uuid'
109
import { create } from 'zustand'
1110

1211
import type { ToastProps } from '~/ui/lib/Toast'
@@ -18,6 +17,10 @@ type Toast = {
1817

1918
export const useToastStore = create<{ toasts: Toast[] }>(() => ({ toasts: [] }))
2019

20+
// A counter and not crypto.randomUUID(), which only exists in secure contexts.
21+
// The console can be served over plain HTTP, e.g., from Nexus on a dev machine.
22+
let nextId = 0
23+
2124
/**
2225
* If argument is `ReactElement | string`, use it directly as `{ content }`.
2326
* Otherwise it's a config object.
@@ -27,7 +30,9 @@ export function addToast(optionsOrContent: Toast['options'] | ReactElement | str
2730
typeof optionsOrContent === 'object' && 'content' in optionsOrContent
2831
? optionsOrContent
2932
: { content: optionsOrContent }
30-
useToastStore.setState(({ toasts }) => ({ toasts: [...toasts, { id: uuid(), options }] }))
33+
useToastStore.setState(({ toasts }) => ({
34+
toasts: [...toasts, { id: String(nextId++), options }],
35+
}))
3136
}
3237

3338
export function removeToast(id: Toast['id']) {

‎app/ui/lib/Table.tsx‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,15 @@
66
* Copyright Oxide Computer Company
77
*/
88
import cn from 'classnames'
9-
import React, { useRef, type JSX, type ReactElement } from 'react'
9+
import React, { type JSX, type ReactElement } from 'react'
1010
import SimpleBar from 'simplebar-react'
1111

12-
import { useIsOverflow } from '~/hooks/use-is-overflow'
1312
import { classed } from '~/util/classed'
1413

1514
export type TableProps = JSX.IntrinsicElements['table']
1615
export function Table({ className, ...props }: TableProps) {
17-
const overflowRef = useRef<HTMLDivElement>(null)
18-
const { isOverflow, scrollStart, scrollEnd } = useIsOverflow(overflowRef, 'horizontal')
19-
2016
return (
21-
<SimpleBar
22-
scrollableNodeProps={{ ref: overflowRef }}
23-
className={cn(
24-
'overflow-x-auto rounded-md pb-4',
25-
!scrollStart && 'scrolled',
26-
isOverflow && !scrollEnd && 'overflowing'
27-
)}
28-
autoHide={false}
29-
>
17+
<SimpleBar className="overflow-x-auto rounded-md pb-4" autoHide={false}>
3018
<table
3119
className={cn(className, 'ox-table text-sans-md w-full border-separate')}
3220
{...props}

‎app/ui/styles/components/table.css‎

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -314,45 +314,54 @@ table.ox-table {
314314
}
315315

316316
/*
317-
Drop shadow appears if content is below a sticky
318-
cell and the table is overflowing
317+
Drop shadow on a sticky column when content is scrolled under it, driven by
318+
the table's horizontal scroll position. When the table fits, the timeline is
319+
inactive and neither shadow shows. The clip-path stops the shadow spilling
320+
above and below the cell; it's only on while there's a shadow so it doesn't
321+
clip the selected-row border.
319322
*/
320-
td:first-of-type,
321-
th:first-of-type,
322-
td:last-of-type.action-col,
323-
th:last-of-type.action-col {
324-
transition-property: box-shadow;
325-
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
326-
transition-duration: 250ms;
323+
.ox-table {
324+
--sticky-col-shadow: light-dark(oklch(0 0 0 / 0.075), oklch(0 0 0 / 0.6));
327325
}
328326

329-
.scrolled td:first-of-type,
330-
.scrolled th:first-of-type {
331-
box-shadow: 6px 0 8px -2px oklch(0 0 0 / 0.2);
332-
}
333-
.overflowing td:last-of-type.action-col,
334-
.overflowing th:last-of-type.action-col {
335-
box-shadow: -6px 0 8px -2px oklch(0 0 0 / 0.2);
336-
}
337-
[data-theme='light'] .scrolled td:first-of-type,
338-
[data-theme='light'] .scrolled th:first-of-type {
339-
box-shadow: 6px 0 8px -2px oklch(0 0 0 / 0.05);
340-
}
341-
[data-theme='light'] .overflowing td:last-of-type.action-col,
342-
[data-theme='light'] .overflowing th:last-of-type.action-col {
343-
box-shadow: -6px 0 8px -2px oklch(0 0 0 / 0.05);
327+
/* Without the guard, browsers lacking scroll timelines would run the animation
328+
with a 0s duration and hold the start shadow's end state on every table */
329+
@supports (animation-timeline: scroll()) {
330+
.ox-table :is(td, th):first-of-type {
331+
animation: sticky-start-shadow linear both;
332+
animation-timeline: scroll(nearest inline);
333+
animation-range: 0 2rem;
334+
}
335+
.ox-table :is(td, th):last-of-type.action-col {
336+
animation: sticky-end-shadow linear both;
337+
animation-timeline: scroll(nearest inline);
338+
animation-range: calc(100% - 2rem) 100%;
339+
}
344340
}
345341

346-
/*
347-
Stops shadow from overflowing below
348-
*/
349-
.scrolled td:first-of-type,
350-
.scrolled th:first-of-type {
351-
clip-path: inset(0px -40px 0px 0px);
342+
@keyframes sticky-start-shadow {
343+
from {
344+
clip-path: none;
345+
}
346+
1% {
347+
clip-path: inset(0 -40px 0 0);
348+
}
349+
to {
350+
clip-path: inset(0 -40px 0 0);
351+
box-shadow: 6px 0 8px -2px var(--sticky-col-shadow);
352+
}
352353
}
353-
.overflowing td:last-of-type.action-col,
354-
.overflowing th:last-of-type.action-col {
355-
clip-path: inset(0px 0px 0px -40px);
354+
@keyframes sticky-end-shadow {
355+
from {
356+
clip-path: inset(0 0 0 -40px);
357+
box-shadow: -6px 0 8px -2px var(--sticky-col-shadow);
358+
}
359+
99% {
360+
clip-path: inset(0 0 0 -40px);
361+
}
362+
to {
363+
clip-path: none;
364+
}
356365
}
357366

358367
.simplebar-scrollbar {
@@ -361,15 +370,15 @@ th:last-of-type.action-col {
361370
}
362371

363372
.simplebar-scrollbar:before {
364-
background-color: rgba(255, 255, 255, 0.28);
373+
background-color: var(--content-quaternary);
365374
left: 0 !important;
366375
top: 0 !important;
367376
right: 0 !important;
368377
border-radius: 8px !important;
369378
}
370379

371380
.simplebar-hover.simplebar-scrollbar:before {
372-
background-color: rgba(255, 255, 255, 0.4);
381+
background-color: var(--content-tertiary);
373382
}
374383

375384
.simplebar-track.simplebar-horizontal {

‎app/ui/styles/index.css‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@
6363
@source '../../../node_modules/@oxide/design-system/dist';
6464
@custom-variant light (&:where([data-theme=light], [data-theme=light] *));
6565

66+
/* The color-scheme meta tag follows the OS. These make browser-drawn UI
67+
(scrollbars, date pickers, autofill) follow the chosen theme instead. */
68+
[data-theme='dark'] {
69+
color-scheme: dark;
70+
}
71+
[data-theme='light'] {
72+
color-scheme: light;
73+
}
74+
6675
@theme {
6776
--animate-spin-slow: spin 5s linear infinite;
6877
--animate-pulse: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;

‎mock-api/audit-log.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* Copyright Oxide Computer Company
77
*/
88

9-
import { v4 as uuid } from 'uuid'
10-
119
import type { AuditLogEntry } from '@oxide/api'
1210

1311
import { Rando } from '~/util/rando'
@@ -78,7 +76,7 @@ const mockSourceIps = [
7876
'198.51.100.42',
7977
]
8078

81-
const mockRequestIds = Array.from({ length: 20 }, () => uuid())
79+
const mockRequestIds = Array.from({ length: 20 }, () => crypto.randomUUID())
8280

8381
// Use seeded random for consistent states across runs
8482
const rando = new Rando(0)
@@ -94,7 +92,7 @@ function generateAuditLogEntry(index: number): Json<AuditLogEntry> {
9492
completedTime.setMilliseconds(rando.next() * 300 + completedTime.getMilliseconds()) // deterministic random durations
9593

9694
return {
97-
id: uuid(),
95+
id: crypto.randomUUID(),
9896
auth_method: mockAuthMethod[index % mockAuthMethod.length],
9997
actor: {
10098
kind: 'silo_user',
@@ -121,7 +119,7 @@ function generateAuditLogEntry(index: number): Json<AuditLogEntry> {
121119
export const auditLog: Json<AuditLogEntry[]> = [
122120
// Recent successful operations
123121
{
124-
id: uuid(),
122+
id: crypto.randomUUID(),
125123
auth_method: 'session_cookie',
126124
actor: {
127125
kind: 'silo_user',
@@ -137,7 +135,7 @@ export const auditLog: Json<AuditLogEntry[]> = [
137135
source_ip: '192.168.1.100',
138136
},
139137
{
140-
id: uuid(),
138+
id: crypto.randomUUID(),
141139
auth_method: 'access_token',
142140
actor: {
143141
kind: 'silo_user',
@@ -155,7 +153,7 @@ export const auditLog: Json<AuditLogEntry[]> = [
155153
},
156154
// Failed operations
157155
{
158-
id: uuid(),
156+
id: crypto.randomUUID(),
159157
auth_method: 'session_cookie',
160158
actor: {
161159
kind: 'silo_user',
@@ -177,7 +175,7 @@ export const auditLog: Json<AuditLogEntry[]> = [
177175
source_ip: '172.16.0.25',
178176
},
179177
{
180-
id: uuid(),
178+
id: crypto.randomUUID(),
181179
auth_method: null,
182180
actor: { kind: 'unauthenticated' },
183181
result: {
@@ -195,7 +193,7 @@ export const auditLog: Json<AuditLogEntry[]> = [
195193
},
196194
// More historical entries
197195
{
198-
id: uuid(),
196+
id: crypto.randomUUID(),
199197
auth_method: 'session_cookie',
200198
actor: {
201199
kind: 'silo_user',

‎mock-api/msw/db.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
*
66
* Copyright Oxide Computer Company
77
*/
8-
// note that isUuid checks for any kind of UUID. strictly speaking, we should
9-
// only be checking for v4
108
import * as R from 'remeda'
11-
import { validate as isUuid } from 'uuid'
129

1310
import type { ApiTypes as Api, IpPoolType, IpVersion } from '@oxide/api'
1411
import * as mock from '@oxide/api-mocks'
@@ -20,6 +17,7 @@ import { commaSeries } from '~/util/str'
2017
import type { Json } from '../json-type'
2118
import { projects, type DbProject } from '../project'
2219
import { defaultSilo, siloSettings } from '../silo'
20+
import { isUuid } from '../util'
2321
import { internalError, invalidRequest } from './util'
2422

2523
export const notFoundErr = (msg: string) => {

0 commit comments

Comments
 (0)